Class: OEHClient::Realtime::Interaction

Inherits:
Object
  • Object
show all
Defined in:
lib/oehclient/realtime/interaction.rb

Constant Summary collapse

API_REALTIME =

constants used to construct the restful API Request URL

"/interaction"
API_OFFLINE =
"/offline"
ONE_PARAM_URI =

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

"uri"
ONE_PARAM_CK =
"customerKey"
ONE_PARAM_TID =
"tid"
ONE_PARAM_SESSION =
"session"
ONE_PARAM_SK =
"sk"
ONE_PARAM_TS =
"timestamp"
ONE_PARAM_PROPERTIES =
"properties"
ONE_PROPERTIES_NAME =

Property Hash Keys

"name"
ONE_PROPERTIES_VALUE =
"value"
ONE_RESPONSE_OPTIMIZATIONS =

Collection objects returned in the response

"optimizations"
ONE_RESPONSE_OPTIMIZATION_DATA =
"data"
ONE_RESPONSE_ACTIONS =
"actions"
ONE_RESPONSE_TRACKERS =
"trackers"
ONE_RESPONSE_CAPTURES =
"captures"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = nil) ⇒ Interaction

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

[View source]

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/oehclient/realtime/interaction.rb', line 122

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))
		@keyname 		= attributes[:keyname]														if (attributes.has_key?(:keyname))
		@customer_key 	= attributes[:ck] 															if (attributes.has_key?(:ck))
		@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))

	end

end

Instance Attribute Details

#capturesObject

——-[ CLASS ATTRIBUTES ]


35
36
37
# File 'lib/oehclient/realtime/interaction.rb', line 35

def captures
  @captures
end

#cookiesObject

——-[ CLASS ATTRIBUTES ]


35
36
37
# File 'lib/oehclient/realtime/interaction.rb', line 35

def cookies
  @cookies
end

#customer_keyObject

——-[ CLASS ATTRIBUTES ]


35
36
37
# File 'lib/oehclient/realtime/interaction.rb', line 35

def customer_key
  @customer_key
end

#keynameObject

——-[ CLASS ATTRIBUTES ]


35
36
37
# File 'lib/oehclient/realtime/interaction.rb', line 35

def keyname
  @keyname
end

#optimizationsObject

——-[ CLASS ATTRIBUTES ]


35
36
37
# File 'lib/oehclient/realtime/interaction.rb', line 35

def optimizations
  @optimizations
end

#sessionObject

——-[ CLASS ATTRIBUTES ]


35
36
37
# File 'lib/oehclient/realtime/interaction.rb', line 35

def session
  @session
end

#spaceObject

——-[ CLASS ATTRIBUTES ]


35
36
37
# File 'lib/oehclient/realtime/interaction.rb', line 35

def space
  @space
end

#tidObject

——-[ CLASS ATTRIBUTES ]


35
36
37
# File 'lib/oehclient/realtime/interaction.rb', line 35

def tid
  @tid
end

#timestampObject

——-[ CLASS ATTRIBUTES ]


35
36
37
# File 'lib/oehclient/realtime/interaction.rb', line 35

def timestamp
  @timestamp
end

#trackersObject

——-[ CLASS ATTRIBUTES ]


35
36
37
# File 'lib/oehclient/realtime/interaction.rb', line 35

def trackers
  @trackers
end

#uriObject

——-[ CLASS ATTRIBUTES ]


35
36
37
# File 'lib/oehclient/realtime/interaction.rb', line 35

def uri
  @uri
end

Class Method Details

.post(site_key, uri, timestamp = nil, tid = nil, customer_key = nil, properties = {}) ⇒ Object

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

[View source]

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/oehclient/realtime/interaction.rb', line 58

def post(site_key, uri, timestamp=nil, tid=nil, customer_key=nil, 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
				 }

	# 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?)

	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
		attributes.merge!(:ck => customer_key)														unless(customer_key.blank?)
	end



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

end

.update(site_key, uri, properties = {}, tid = nil, customer_key = nil) ⇒ Object

class-level wrapper to create a new instance of the OEHClient::Realtime::Interaction class, call the

send_update method, and return the resulting instance of the same class
[View source]

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/oehclient/realtime/interaction.rb', line 89

def update(site_key, uri, properties={}, tid=nil, customer_key=nil)

	# 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
				 }

	# conditionally merge the rest of the attributes if they are passed
	attributes.merge!(:tid => tid)					if (!tid.nil? && !tid.empty?)

	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
		attributes.merge!(:ck => customer_key)														unless(customer_key.blank?)
	end

	# create a new interaction using all parameters pass
	new_interaction = OEHClient::Realtime::Interaction.new(attributes)
	# send the update and return the current object
	new_interaction.send_update(properties)

end

Instance Method Details

#send(parameters = {}) ⇒ Object

send() will post a new interaction using either the realtime (current timestamp) or the offline (historic)

API interface based on the existence of a timestamp value
[View source]

142
143
144
145
146
147
148
149
150
151
# File 'lib/oehclient/realtime/interaction.rb', line 142

def send(parameters={})
	# raise the MissingParameterException when one (or more) of the miminal parameters are missing
	raise OEHClient::Exception::MissingParameterException.new(missing_minimal_parameters) 	unless (minimal_parameters?)

	# call the appropriate method based on the existance of the timestamp value
	#((!@timestamp.nil?) ? send_offline(parameters) : send_realtime(parameters))
	send_realtime(parameters)
	# return the current instance interacton
	self
end

#send_new(uri, timestamp = nil, parameters = {}) ⇒ Object

send_new posts a new interaction using the existing instance data, but for a different touchpoint

URI.  The method returns a new instance of the OEHClient::Realtime::Interaction class
[View source]

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/oehclient/realtime/interaction.rb', line 155

def send_new(uri, timestamp=nil, parameters={})
	# raise the MissingParameterException when one (or more) of the miminal parameters are missing
	raise OEHClient::Exception::MissingParameterException.new(missing_minimal_parameters) 	unless (minimal_parameters?)

	# protect against NIL by creating a new Hash object if the parameters, for any reason is 
	#  NIL
	parameters ||= Hash.new

	# create a new interaction using all parameters from the existing other than the new touchpoint
	#  URI and timestamp of the current Interaction instance.  The method can be used to submit new
	#  requests for the same customer, tid, & session
	new_interaction = OEHClient::Realtime::Interaction.new({
													:uri => uri,
													:ck => @customer_key,
													:tid => @tid,
													:session => @session,
													:sk => @space.site_key,
													:timestamp => OEHClient::Helper::Timestamp.to_one_timestamp(timestamp)
												})

	# Send the interaction for processing and return the current instance
	new_interaction.send(parameters)
end

#send_update(properties = {}) ⇒ Object

send_update allows the system to update the capture and tracking properties that are defined as

part of the existing interaction
[View source]

181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/oehclient/realtime/interaction.rb', line 181

def send_update(properties={}) 
	# raise the MissingParameterException when one (or more) of the miminal parameters are missing
	raise OEHClient::Exception::MissingParameterException.new(missing_minimal_parameters) 	unless (minimal_parameters?)

	# force the properties object to be an empty Hash if, for any reason, it is NIL
	properties ||= Hash.new

	# Call the PUT method to update the 
	send_request(OEHClient::Helper::Request::PUT_METHOD, realtime_url, properties) unless properties.empty?

	# return the current object
	self
end