class OEHClient::Realtime::Event

Constants

ONE_PARAM_PROPERTIES
ONE_PARAM_TID
ONE_PARAM_URI

ONE attributes that are either in the request and/or returned in the response

ONE_PROPERTIES_NAME

Property Hash Keys

ONE_PROPERTIES_VALUE
URI_EVENTS
URI_RT_TRACK_PART

Attributes

space[RW]

——-[ CLASS ATTRIBUTES ]

tid[RW]

——-[ CLASS ATTRIBUTES ]

uri[RW]

——-[ CLASS ATTRIBUTES ]

Public Class Methods

new(attributes=nil) click to toggle source

constructor that allows the passed Ruby Hash to be mapped to the

# File lib/oehclient/realtime/event.rb, line 44
def initialize(attributes=nil)

        # set the instance attributes is the parameter hash is created
        if (!attributes.nil? && attributes.kind_of?(Hash))

                @uri                         = attributes[:uri]                                                                                                                   if (attributes.has_key?(:uri))
                @tid                         = attributes[:tid]                                                                                                                   if (attributes.has_key?(:tid))

                @space                       = OEHClient::Config::SpaceManager.instance.get(attributes[:sk])                            if (attributes.has_key?(:sk))

        end

end
post(site_key, uri, properties={}) click to toggle source

class-level wrapper to post a new interaction to the OEH server using either the realtime or offline API for an anonymous or known prospects/customer

# File lib/oehclient/realtime/event.rb, line 26
def self.post(site_key, uri, properties={})

        # setup the baseline attributes hash with the site_key and interaction URI, which are the
        #  minimal values needed for an interaction
        attributes = {:sk => site_key,:uri => uri}

        # create a new interaction using all attributes pass
        new_event = OEHClient::Realtime::Event.new(attributes)
        # Send the interaction for processing and return the instance of the interaction class
        new_event.send(properties)

end

Public Instance Methods

send(properties={}) click to toggle source
# File lib/oehclient/realtime/event.rb, line 58
def send(properties={})

        send_args                     = {:payload => ActiveSupport::JSON.encode(request_data(properties))}
        send_args[:header]    = properties[:header]  if (!properties.nil? && properties.has_key?(:header))

        # send the POST or PUT methond along with the arguments to the OEHClient class
        map_response(OEHClient.send(OEHClient::Helper::Request::POST_METHOD.to_sym, 
                                        request_url,
                                        nil,
                                        send_args))

        self          
end

Private Instance Methods

map_response(response) click to toggle source

map_response takes the attributes returned in an interaction response and maps it to exiting

attributes in the current instance of the interaction object
# File lib/oehclient/realtime/event.rb, line 106
def map_response(response)

        body                  = response[:body]

        # Save the tid and session data if they where not previously used in the request
        @tid                  = body[ONE_PARAM_TID]                 if (@tid.nil? || (!@tid.blank? && @tid != body[ONE_PARAM_TID]))

end
request_data(passed_properties={}) click to toggle source

request_data creates a properly formatted Hash object that represents the body of the request needed

for POST and PUT operations
# File lib/oehclient/realtime/event.rb, line 80
def request_data(passed_properties={})

        # Initialize the parameters hash
        parameters ||= Hash.new

        # merge in the different parts of the request data if the values currently exist within
        #  the instance of the class
        parameters.merge!({ONE_PARAM_URI => @uri})                            if (!@uri.nil? && @uri.length > 0)

        # for each of the properties hash entry, build a name/value pair in the properties collection
        properties = Array.new
        # merge in the different parts of the request data if the values currently exist within
        #  the instance of the class
        passed_properties.each do | key, value |
                properties << {ONE_PROPERTIES_NAME => key.to_s, ONE_PROPERTIES_VALUE => value} unless (key == :header)
        end
        # merge the properties (name / value) connections if there are additonal values to pass
        parameters.merge!({ONE_PARAM_PROPERTIES => properties})               if (properties.length > 0)

        # return the full parameter hash
        return(parameters)

end
request_url() click to toggle source
# File lib/oehclient/realtime/event.rb, line 74
def request_url
        "#{OEHClient::Helper::Request::ONE_PROTOCOL}#{@space.host}/#{OEHClient::Realtime::Event::URI_RT_TRACK_PART}/#{@space.site_key}/#{OEHClient::Realtime::Event::URI_EVENTS}"
end