lib/oehclient/realtime/interaction.rb in oeh-client-2.2.8 vs lib/oehclient/realtime/interaction.rb in oeh-client-2.2.9

- old
+ new

@@ -9,10 +9,11 @@ # constants used to construct the restful API Request URL API_REALTIME = "/interaction" API_OFFLINE = "/offline" # ONE attributes that are either in the request and/or returned in the response ONE_PARAM_URI = "uri" + ONE_PARAM_DEVICE = "device" ONE_PARAM_CK = "customerKey" ONE_PARAM_TID = "tid" ONE_PARAM_SESSION = "session" ONE_PARAM_SK = "sk" ONE_PARAM_TS = "timestamp" @@ -32,10 +33,11 @@ # -------[ CLASS ATTRIBUTES ] # attr_accessor :uri, # The full touchpoint/interaction URI used to post the interaction :space, # The configured OEHClient::Config::Space object that represents the OEH workspace + :device, # The device information :timestamp, # A millisecond value representing a Time value of the interaction :keyname, # The customer keyname to use based on multi-key configuration. Default is customerKey :customer_key, # The customer to which this interaction is related :tid, # The Thunderhead ID (TID) to which this interaction is related @@ -53,11 +55,11 @@ class << self # 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 - def post(site_key, uri, timestamp=nil, tid=nil, customer_key=nil, properties={}) + def post(site_key, uri, timestamp=nil, tid=nil, customer_key=nil, properties={}, device={}) # 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, @@ -65,10 +67,11 @@ } # conditionally merge the rest of the attributes if they are passed attributes.merge!(:timestamp => OEHClient::Helper::Timestamp.to_one_timestamp(timestamp)) unless(timestamp.blank?) attributes.merge!(:tid => tid) unless(timestamp.blank?) + attributes.merge!(:device => device) if (customer_key.is_a?(Hash)) attributes.merge!(:ck => customer_key[:value]) if (customer_key.has_key?(:value)) attributes.merge!(:keyname => customer_key[:keyname]) if (customer_key.has_key?(:keyname)) else @@ -130,10 +133,11 @@ @tid = attributes[:tid] if (attributes.has_key?(:tid)) @session = attributes[:session] if (attributes.has_key?(:session)) @timestamp = OEHClient::Helper::Timestamp.to_one_timestamp(attributes[:timestamp]) if (attributes.has_key?(:timestamp)) @space = OEHClient::Config::SpaceManager.instance.get(attributes[:sk]) if (attributes.has_key?(:sk)) + @device = attributes[:device] if (attributes.has_key?(:device)) end end @@ -326,16 +330,17 @@ 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) + parameters.merge!({ONE_PARAM_DEVICE => @device}) if (!@device.nil? && !@device.empty?) - parameters.merge!({"customerKeyName" => @keyname}) if (!@keyname.nil? && @keyname.length > 0) - parameters.merge!({"customerKey" => @customer_key}) if (!@customer_key.nil? && @customer_key.length > 0) + parameters.merge!({"customerKeyName" => @keyname}) if (!@keyname.nil? && @keyname.length > 0) + parameters.merge!({"customerKey" => @customer_key}) if (!@customer_key.nil? && @customer_key.length > 0) - parameters.merge!({ONE_PARAM_SESSION => @session}) if (!@session.nil? && @session.length > 0) - #parameters.merge!({ONE_PARAM_TS => @timestamp}) if (!@timestamp.nil?) + parameters.merge!({ONE_PARAM_SESSION => @session}) if (!@session.nil? && @session.length > 0) + parameters.merge!({ONE_PARAM_TS => @timestamp}) if (!@timestamp.nil?) # for each of the properties hash entry, build a name/value pair in the properties collection properties = Array.new passed_properties.each do | key, value | properties << {ONE_PROPERTIES_NAME => key.to_s, ONE_PROPERTIES_VALUE => value} unless (key == :header) \ No newline at end of file