oeh-client 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- metadata +1 -30
- data/.gitignore +0 -11
- data/.rspec +0 -2
- data/.travis.yml +0 -4
- data/CODE_OF_CONDUCT.md +0 -13
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -21
- data/README.md +0 -73
- data/Rakefile +0 -9
- data/lib/oehclient/config/space.rb +0 -114
- data/lib/oehclient/config/space_manager.rb +0 -55
- data/lib/oehclient/config.rb +0 -11
- data/lib/oehclient/data/node.rb +0 -66
- data/lib/oehclient/data/structure.rb +0 -82
- data/lib/oehclient/data.rb +0 -10
- data/lib/oehclient/exception.rb +0 -64
- data/lib/oehclient/helper.rb +0 -97
- data/lib/oehclient/meta/entity.rb +0 -97
- data/lib/oehclient/meta/interaction.rb +0 -14
- data/lib/oehclient/meta/session.rb +0 -36
- data/lib/oehclient/meta/touchpoint.rb +0 -36
- data/lib/oehclient/meta/workspace.rb +0 -58
- data/lib/oehclient/meta/workspace_entity.rb +0 -13
- data/lib/oehclient/meta.rb +0 -14
- data/lib/oehclient/realtime/interaction.rb +0 -355
- data/lib/oehclient/realtime/optimization.rb +0 -55
- data/lib/oehclient/realtime/response.rb +0 -74
- data/lib/oehclient/realtime.rb +0 -11
- data/lib/oehclient/version.rb +0 -3
- data/oeh-client.gemspec +0 -41
@@ -1,355 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
|
3
|
-
class OEHClient::Realtime::Interaction
|
4
|
-
|
5
|
-
#
|
6
|
-
# -------[ CONSTANTS ]
|
7
|
-
#
|
8
|
-
|
9
|
-
# constants used to construct the restful API Request URL
|
10
|
-
API_REALTIME = "/interaction"
|
11
|
-
API_OFFLINE = "/offline"
|
12
|
-
# ONE attributes that are either in the request and/or returned in the response
|
13
|
-
ONE_PARAM_URI = "uri"
|
14
|
-
ONE_PARAM_CK = "customerKey"
|
15
|
-
ONE_PARAM_TID = "tid"
|
16
|
-
ONE_PARAM_SESSION = "session"
|
17
|
-
ONE_PARAM_SK = "sk"
|
18
|
-
ONE_PARAM_TS = "timestamp"
|
19
|
-
ONE_PARAM_PROPERTIES = "properties"
|
20
|
-
# Property Hash Keys
|
21
|
-
ONE_PROPERTIES_NAME = "name"
|
22
|
-
ONE_PROPERTIES_VALUE = "value"
|
23
|
-
# Collection objects returned in the response
|
24
|
-
ONE_RESPONSE_OPTIMIZATIONS = "optimizations"
|
25
|
-
ONE_RESPONSE_OPTIMIZATION_DATA = "data"
|
26
|
-
ONE_RESPONSE_ACTIONS = "actions"
|
27
|
-
ONE_RESPONSE_TRACKERS = "trackers"
|
28
|
-
ONE_RESPONSE_CAPTURES = "captures"
|
29
|
-
|
30
|
-
|
31
|
-
#
|
32
|
-
# -------[ CLASS ATTRIBUTES ]
|
33
|
-
#
|
34
|
-
|
35
|
-
attr_accessor :uri, # The full touchpoint/interaction URI used to post the interaction
|
36
|
-
:space, # The configured OEHClient::Config::Space object that represents the OEH workspace
|
37
|
-
|
38
|
-
:timestamp, # A millisecond value representing a Time value of the interaction
|
39
|
-
:keyname, # The customer keyname to use based on multi-key configuration. Default is customerKey
|
40
|
-
:customer_key, # The customer to which this interaction is related
|
41
|
-
:tid, # The Thunderhead ID (TID) to which this interaction is related
|
42
|
-
:session, # The session id to which this interaction is related
|
43
|
-
|
44
|
-
:optimizations, # The collection of optimizations that are relevent for the interaction
|
45
|
-
:trackers, # The collection of tracking point data that are relevant for the interaction
|
46
|
-
:captures, # The collection of capture point data that are relevant for the interactions
|
47
|
-
|
48
|
-
:cookies # The JSON object of cookies returned within a ONE Request
|
49
|
-
|
50
|
-
#
|
51
|
-
# -------[ CLASS METHODS ]
|
52
|
-
#
|
53
|
-
|
54
|
-
class << self
|
55
|
-
|
56
|
-
# class-level wrapper to post a new interaction to the OEH server using either the realtime or offline
|
57
|
-
# API for an anonymous or known prospects/customer
|
58
|
-
def post(site_key, uri, timestamp=nil, tid=nil, customer_key=nil, properties={})
|
59
|
-
|
60
|
-
# setup the baseline attributes hash with the site_key and interaction URI, which are the
|
61
|
-
# minimal values needed for an interaction
|
62
|
-
attributes = {
|
63
|
-
:sk => site_key,
|
64
|
-
:uri => uri
|
65
|
-
}
|
66
|
-
|
67
|
-
# conditionally merge the rest of the attributes if they are passed
|
68
|
-
attributes.merge!(:timestamp => OEHClient::Helper::Timestamp.to_one_timestamp(timestamp)) unless(timestamp.blank?)
|
69
|
-
attributes.merge!(:tid => tid) unless(timestamp.blank?)
|
70
|
-
|
71
|
-
if (customer_key.is_a?(Hash))
|
72
|
-
attributes.merge!(:ck => customer_key[:value]) if (customer_key.has_key?(:value))
|
73
|
-
attributes.merge!(:keyname => customer_key[:keyname]) if (customer_key.has_key?(:keyname))
|
74
|
-
else
|
75
|
-
attributes.merge!(:ck => customer_key) unless(customer_key.blank?)
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
# create a new interaction using all attributes pass
|
81
|
-
new_interaction = OEHClient::Realtime::Interaction.new(attributes)
|
82
|
-
# Send the interaction for processing and return the instance of the interaction class
|
83
|
-
new_interaction.send(properties)
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
# class-level wrapper to create a new instance of the OEHClient::Realtime::Interaction class, call the
|
88
|
-
# send_update method, and return the resulting instance of the same class
|
89
|
-
def update(site_key, uri, properties={}, tid=nil, customer_key=nil)
|
90
|
-
|
91
|
-
# setup the baseline attributes hash with the site_key and interaction URI, which are the
|
92
|
-
# minimal values needed for an interaction
|
93
|
-
attributes = {
|
94
|
-
:sk => site_key,
|
95
|
-
:uri => uri
|
96
|
-
}
|
97
|
-
|
98
|
-
# conditionally merge the rest of the attributes if they are passed
|
99
|
-
attributes.merge!(:tid => tid) if (!tid.nil? && !tid.empty?)
|
100
|
-
|
101
|
-
if (customer_key.is_a?(Hash))
|
102
|
-
attributes.merge!(:ck => customer_key[:value]) if (customer_key.has_key?(:value))
|
103
|
-
attributes.merge!(:keyname => customer_key[:keyname]) if (customer_key.has_key?(:keyname))
|
104
|
-
else
|
105
|
-
attributes.merge!(:ck => customer_key) unless(customer_key.blank?)
|
106
|
-
end
|
107
|
-
|
108
|
-
# create a new interaction using all parameters pass
|
109
|
-
new_interaction = OEHClient::Realtime::Interaction.new(attributes)
|
110
|
-
# send the update and return the current object
|
111
|
-
new_interaction.send_update(properties)
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
#
|
118
|
-
# -------[ INSTANCE METHODS ]
|
119
|
-
#
|
120
|
-
|
121
|
-
# constructor that allows the passed Ruby Hash to be mapped to the
|
122
|
-
def initialize(attributes=nil)
|
123
|
-
|
124
|
-
# set the instance attributes is the parameter hash is created
|
125
|
-
if (!attributes.nil? && attributes.kind_of?(Hash))
|
126
|
-
|
127
|
-
@uri = attributes[:uri] if (attributes.has_key?(:uri))
|
128
|
-
@keyname = attributes[:keyname] if (attributes.has_key?(:keyname))
|
129
|
-
@customer_key = attributes[:ck] if (attributes.has_key?(:ck))
|
130
|
-
@tid = attributes[:tid] if (attributes.has_key?(:tid))
|
131
|
-
@session = attributes[:session] if (attributes.has_key?(:session))
|
132
|
-
@timestamp = OEHClient::Helper::Timestamp.to_one_timestamp(attributes[:timestamp]) if (attributes.has_key?(:timestamp))
|
133
|
-
|
134
|
-
@space = OEHClient::Config::SpaceManager.instance.get(attributes[:sk]) if (attributes.has_key?(:sk))
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
# send() will post a new interaction using either the realtime (current timestamp) or the offline (historic)
|
141
|
-
# API interface based on the existence of a timestamp value
|
142
|
-
def send(parameters={})
|
143
|
-
# raise the MissingParameterException when one (or more) of the miminal parameters are missing
|
144
|
-
raise OEHClient::Exception::MissingParameterException.new(missing_minimal_parameters) unless (minimal_parameters?)
|
145
|
-
|
146
|
-
# call the appropriate method based on the existance of the timestamp value
|
147
|
-
#((!@timestamp.nil?) ? send_offline(parameters) : send_realtime(parameters))
|
148
|
-
send_realtime(parameters)
|
149
|
-
# return the current instance interacton
|
150
|
-
self
|
151
|
-
end
|
152
|
-
|
153
|
-
# send_new posts a new interaction using the existing instance data, but for a different touchpoint
|
154
|
-
# URI. The method returns a new instance of the OEHClient::Realtime::Interaction class
|
155
|
-
def send_new(uri, timestamp=nil, parameters={})
|
156
|
-
# raise the MissingParameterException when one (or more) of the miminal parameters are missing
|
157
|
-
raise OEHClient::Exception::MissingParameterException.new(missing_minimal_parameters) unless (minimal_parameters?)
|
158
|
-
|
159
|
-
# protect against NIL by creating a new Hash object if the parameters, for any reason is
|
160
|
-
# NIL
|
161
|
-
parameters ||= Hash.new
|
162
|
-
|
163
|
-
# create a new interaction using all parameters from the existing other than the new touchpoint
|
164
|
-
# URI and timestamp of the current Interaction instance. The method can be used to submit new
|
165
|
-
# requests for the same customer, tid, & session
|
166
|
-
new_interaction = OEHClient::Realtime::Interaction.new({
|
167
|
-
:uri => uri,
|
168
|
-
:ck => @customer_key,
|
169
|
-
:tid => @tid,
|
170
|
-
:session => @session,
|
171
|
-
:sk => @space.site_key,
|
172
|
-
:timestamp => OEHClient::Helper::Timestamp.to_one_timestamp(timestamp)
|
173
|
-
})
|
174
|
-
|
175
|
-
# Send the interaction for processing and return the current instance
|
176
|
-
new_interaction.send(parameters)
|
177
|
-
end
|
178
|
-
|
179
|
-
# send_update allows the system to update the capture and tracking properties that are defined as
|
180
|
-
# part of the existing interaction
|
181
|
-
def send_update(properties={})
|
182
|
-
# raise the MissingParameterException when one (or more) of the miminal parameters are missing
|
183
|
-
raise OEHClient::Exception::MissingParameterException.new(missing_minimal_parameters) unless (minimal_parameters?)
|
184
|
-
|
185
|
-
# force the properties object to be an empty Hash if, for any reason, it is NIL
|
186
|
-
properties ||= Hash.new
|
187
|
-
|
188
|
-
# Call the PUT method to update the
|
189
|
-
send_request(OEHClient::Helper::Request::PUT_METHOD, realtime_url, properties) unless properties.empty?
|
190
|
-
|
191
|
-
# return the current object
|
192
|
-
self
|
193
|
-
end
|
194
|
-
|
195
|
-
|
196
|
-
#
|
197
|
-
# -------[ PRIVATE METHODS ]
|
198
|
-
#
|
199
|
-
|
200
|
-
private
|
201
|
-
|
202
|
-
|
203
|
-
# send_realtime posts a new interaction occuring at the moment (in realtime). The response attributes
|
204
|
-
# are mapped to the current instance attributes for all valid requests
|
205
|
-
def send_realtime(properties={})
|
206
|
-
# Put timestamp in the header if it has been provides
|
207
|
-
properties[:header] = {'X-ONE-Timestamp' => @timestamp}.merge!(OEHClient::Helper::Request.default_JSON_header()) unless (@timestamp.nil?)
|
208
|
-
# POST the realtime interaction method
|
209
|
-
response = send_request(OEHClient::Helper::Request::POST_METHOD, realtime_url, properties)
|
210
|
-
# map the response message to the current instance attributes
|
211
|
-
map_response(response)
|
212
|
-
end
|
213
|
-
|
214
|
-
# send_offline posts a historic interaction, using a specified timestamp
|
215
|
-
def send_offline(properties={})
|
216
|
-
# PUT the offline interaction method
|
217
|
-
response = send_request(OEHClient::Helper::Request::PUT_METHOD, offline_url, properties)
|
218
|
-
# map the response message to the current instance attributes
|
219
|
-
map_response(response)
|
220
|
-
end
|
221
|
-
|
222
|
-
# send_request acts as the wrapper to send all client requests to the ONE server in a unified manner
|
223
|
-
def send_request(method, url, properties={})
|
224
|
-
# set the URL parameters for the site_key and the tid, of the value exists
|
225
|
-
url_parameters = {:sk => @space.site_key}
|
226
|
-
url_parameters.merge!({:tid => @tid}) unless (@tid.blank?)
|
227
|
-
#url_parameters.merge!({:timestamp => @timestamp}) unless (@timestamp.nil?)
|
228
|
-
|
229
|
-
send_args = {:params => url_parameters, :payload => ActiveSupport::JSON.encode(request_data(properties))}
|
230
|
-
send_args[:header] = properties[:header] if (!properties.nil? && properties.has_key?(:header))
|
231
|
-
|
232
|
-
# send the POST or PUT methond along with the arguments to the OEHClient class
|
233
|
-
OEHClient.send(method.downcase.to_sym,
|
234
|
-
url,
|
235
|
-
@space.oauth_consumer,
|
236
|
-
send_args)
|
237
|
-
|
238
|
-
end
|
239
|
-
|
240
|
-
# map_response takes the attributes returned in an interaction response and maps it to exiting
|
241
|
-
# attributes in the current instance of the interaction object
|
242
|
-
def map_response(response)
|
243
|
-
|
244
|
-
body = response[:body]
|
245
|
-
|
246
|
-
# Save the tid and session data if they where not previously used in the request
|
247
|
-
@tid = body[ONE_PARAM_TID] if (@tid.nil? || (!@tid.blank? && @tid != body[ONE_PARAM_TID]))
|
248
|
-
@session = body[ONE_PARAM_SESSION] if @session.nil?
|
249
|
-
|
250
|
-
# capture the optimizations returned from the request and map it to the OEHClient::Realtime::Optimization
|
251
|
-
# class
|
252
|
-
|
253
|
-
# initialize the optimizations collection if it is null
|
254
|
-
@optimizations ||= Array.new
|
255
|
-
# map each of the optimizations to the OEHClient::Realtime::Optmization class
|
256
|
-
body[ONE_RESPONSE_OPTIMIZATIONS].each do | response_optimization |
|
257
|
-
# decode the data of the optimization
|
258
|
-
optimization_data = ActiveSupport::JSON.decode(Base64.decode64(response_optimization[ONE_RESPONSE_OPTIMIZATION_DATA]))
|
259
|
-
# get the actions for each optimization
|
260
|
-
optimization_data[ONE_RESPONSE_ACTIONS].each do | one_action |
|
261
|
-
@optimizations << OEHClient::Realtime::Optimization.create(self, one_action)
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
# store the cookies passed back by the system
|
266
|
-
@cookies = response[:cookies]
|
267
|
-
|
268
|
-
# capture the trackers returned from the request and mpt it to the OEHClient::Realtime::Tracker
|
269
|
-
# class
|
270
|
-
# TODO: Create OEHClient::Realtime::Tracker class
|
271
|
-
@trackers = body[ONE_RESPONSE_TRACKERS]
|
272
|
-
|
273
|
-
# capture the capture points returned from the request and map it to the OEHClient::Realtime::Capture
|
274
|
-
# class
|
275
|
-
# TODO: Create OEHClient::Realtime::Capture class
|
276
|
-
@captures = body[ONE_RESPONSE_CAPTURES]
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
end
|
281
|
-
|
282
|
-
# minimal_parameters? determines if the minimal number of request parameters (uri & site_key) are
|
283
|
-
# present in the current instance of the interaction class. This is a helper method that is used
|
284
|
-
# before making any request
|
285
|
-
def minimal_parameters?()
|
286
|
-
((!@uri.nil? && !@uri.empty?) && !@space.nil?)
|
287
|
-
end
|
288
|
-
|
289
|
-
# missing_minimal_parameters returns an array of the minimal attributes that are missing from the current
|
290
|
-
# instance of OEHClient::Realtime::Interaction class
|
291
|
-
def missing_minimal_parameters
|
292
|
-
|
293
|
-
missing_parameters = []
|
294
|
-
|
295
|
-
missing_parameters << "site_key" if (!minimal_parameters? && @site_key.nil?)
|
296
|
-
missing_parameters << "uri" if (!minimal_parameters? && @uri.nil?)
|
297
|
-
|
298
|
-
missing_parameters
|
299
|
-
|
300
|
-
end
|
301
|
-
|
302
|
-
# request_url returns the base of the request URL used to make either a realtime or offline request
|
303
|
-
# through published API
|
304
|
-
def request_url()
|
305
|
-
"#{OEHClient::Helper::Request::ONE_PROTOCOL}#{@space.host}#{OEHClient::Helper::Request::ONE_URI_PART}#{OEHClient::Helper::Request::API_URI_PART}#{OEHClient::Helper::Request::API_VERSION}"
|
306
|
-
end
|
307
|
-
|
308
|
-
# realtime_url is the interaction part of the API URI
|
309
|
-
def realtime_url()
|
310
|
-
"#{request_url}#{API_REALTIME}"
|
311
|
-
end
|
312
|
-
|
313
|
-
# offline_url appends the /offiline URI part to add support for historic data loading of interactions
|
314
|
-
def offline_url()
|
315
|
-
"#{realtime_url}#{API_OFFLINE}"
|
316
|
-
end
|
317
|
-
|
318
|
-
# request_data creates a properly formatted Hash object that represents the body of the request needed
|
319
|
-
# for POST and PUT operations
|
320
|
-
def request_data(passed_properties={})
|
321
|
-
|
322
|
-
# protect agains a NIL value in the passed_properties Hash
|
323
|
-
passed_properties ||= Hash.new
|
324
|
-
|
325
|
-
# Initialize the parameters hash
|
326
|
-
parameters ||= Hash.new
|
327
|
-
|
328
|
-
# merge in the different parts of the request data if the values currently exist within
|
329
|
-
# the instance of the class
|
330
|
-
parameters.merge!({ONE_PARAM_URI => @uri}) if (!@uri.nil? && @uri.length > 0)
|
331
|
-
|
332
|
-
parameters.merge!({"customerKeyName" => @keyname}) if (!@keyname.nil? && @keyname.length > 0)
|
333
|
-
parameters.merge!({"customerKey" => @customer_key}) if (!@customer_key.nil? && @customer_key.length > 0)
|
334
|
-
|
335
|
-
|
336
|
-
parameters.merge!({ONE_PARAM_SESSION => @session}) if (!@session.nil? && @session.length > 0)
|
337
|
-
#parameters.merge!({ONE_PARAM_TS => @timestamp}) if (!@timestamp.nil?)
|
338
|
-
|
339
|
-
# for each of the properties hash entry, build a name/value pair in the properties collection
|
340
|
-
properties = Array.new
|
341
|
-
passed_properties.each do | key, value |
|
342
|
-
properties << {ONE_PROPERTIES_NAME => key.to_s, ONE_PROPERTIES_VALUE => value} unless (key == :header)
|
343
|
-
end
|
344
|
-
# merge the properties (name / value) connections if there are additonal values to pass
|
345
|
-
parameters.merge!({ONE_PARAM_PROPERTIES => properties}) if (properties.length > 0)
|
346
|
-
|
347
|
-
# return the full parameter hash
|
348
|
-
return(parameters)
|
349
|
-
|
350
|
-
end
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require 'cgi'
|
3
|
-
|
4
|
-
class OEHClient::Realtime::Optimization
|
5
|
-
|
6
|
-
# HASH keys based on the response data
|
7
|
-
OPT_RESPONSE_NAME = "name"
|
8
|
-
OPT_RESPONSE_ASSET = "asset"
|
9
|
-
OPT_RESPONSE_CONTENT = "content"
|
10
|
-
OPT_RESPONSE_CONTENT_URL = "contentUrl"
|
11
|
-
OPT_RESPONSE_MIME_TYPE = "mimeType"
|
12
|
-
OPT_RESPONSE_PROPOSITION = "proposition"
|
13
|
-
OPT_RESPONSE_RESPONSES = "responses"
|
14
|
-
|
15
|
-
# Localized attributes equivalent to the returned Hash object in the response
|
16
|
-
attr_accessor :name, # The name of the action
|
17
|
-
:content, # The decoded content of the asset
|
18
|
-
:content_url, # The URL to the referential asset
|
19
|
-
:mime_type, # The MIME Type of the asset based on the OEH Configuration
|
20
|
-
:proposition, # The code of the proposition, related to the optimization
|
21
|
-
:responses, # The collection of responses valid for this optmization
|
22
|
-
:interaction # The parent interaction object
|
23
|
-
|
24
|
-
# ---- Class Methods
|
25
|
-
|
26
|
-
def self.create(interaction, properties={})
|
27
|
-
|
28
|
-
one_asset = properties[OPT_RESPONSE_ASSET]
|
29
|
-
|
30
|
-
# create a new instance of the OEHClient::Realtime::Optimization class
|
31
|
-
optimization_instance = OEHClient::Realtime::Optimization.new()
|
32
|
-
|
33
|
-
# assign all data attributes based on the properties object that is passed
|
34
|
-
optimization_instance.name = properties[OPT_RESPONSE_NAME] if (properties.has_key?(OPT_RESPONSE_NAME))
|
35
|
-
optimization_instance.proposition = properties[OPT_RESPONSE_PROPOSITION] if (properties.has_key?(OPT_RESPONSE_PROPOSITION))
|
36
|
-
# map the asset data to the class instance variables
|
37
|
-
optimization_instance.content = CGI.unescapeHTML(one_asset[OPT_RESPONSE_CONTENT]) if (one_asset.has_key?(OPT_RESPONSE_CONTENT))
|
38
|
-
optimization_instance.content_url = one_asset[OPT_RESPONSE_CONTENT_URL] if (one_asset.has_key?(OPT_RESPONSE_CONTENT_URL))
|
39
|
-
optimization_instance.mime_type = one_asset[OPT_RESPONSE_MIME_TYPE] if (one_asset.has_key?(OPT_RESPONSE_MIME_TYPE))
|
40
|
-
# map each of the respones to the response object
|
41
|
-
optimization_instance.responses ||= Array.new
|
42
|
-
one_asset[OPT_RESPONSE_RESPONSES].each do | asset_response |
|
43
|
-
optimization_instance.responses << OEHClient::Realtime::Response.create(optimization_instance, asset_response)
|
44
|
-
end
|
45
|
-
# set the parent interaction object
|
46
|
-
optimization_instance.interaction = interaction
|
47
|
-
#return the new instance of the optimzation class
|
48
|
-
optimization_instance
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
# ---- Instance Methods
|
53
|
-
|
54
|
-
|
55
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
|
2
|
-
class OEHClient::Realtime::Response
|
3
|
-
|
4
|
-
# HASH keys based on the response data
|
5
|
-
OPT_RESPONSE_CODE = "code"
|
6
|
-
OPT_RESPONSE_SENTIMENT = "sentiment"
|
7
|
-
OPT_RESPONSE_LABEL = "label"
|
8
|
-
OPT_RESPONSE_IMAGE_URL = "imageUrl"
|
9
|
-
OPT_RESPONSE_TARGET_URL = "targetUrl"
|
10
|
-
OPT_RESPONSE_TARGET = "target"
|
11
|
-
|
12
|
-
RESPONSE_CODE_PROPERTY = "_RESP_CODE_"
|
13
|
-
|
14
|
-
SENTIMENT_POSITIVE = "positive"
|
15
|
-
SENTIMENT_NEUTRAL = "neutral"
|
16
|
-
SENTIMENT_NEGATIVE = "negative"
|
17
|
-
|
18
|
-
# Localized attributes equivalent to the returned Hash object in the response
|
19
|
-
attr_accessor :code, # The response code needed for responses
|
20
|
-
:sentiment, # The sentiment of the response (POSITIVE, NEUTRAL, NEGATIVE)
|
21
|
-
:label, # The label used for display
|
22
|
-
:image_url, # The URL to the image
|
23
|
-
:target_url, # The url to redirect to when the response is selected
|
24
|
-
:target, # The Target Type (ONE, ...)
|
25
|
-
:optimization
|
26
|
-
|
27
|
-
# ---- Class Methods
|
28
|
-
|
29
|
-
def self.create(optimization, properties={})
|
30
|
-
|
31
|
-
# create a new instance of the OEHClient::Realtime::Optimization class
|
32
|
-
response_instance = OEHClient::Realtime::Response.new()
|
33
|
-
|
34
|
-
# assign all data attributes based on the properties object that is passed
|
35
|
-
response_instance.code = properties[OPT_RESPONSE_CODE] if (properties.has_key?(OPT_RESPONSE_CODE))
|
36
|
-
response_instance.sentiment = properties[OPT_RESPONSE_SENTIMENT] if (properties.has_key?(OPT_RESPONSE_SENTIMENT))
|
37
|
-
response_instance.label = properties[OPT_RESPONSE_LABEL] if (properties.has_key?(OPT_RESPONSE_LABEL))
|
38
|
-
response_instance.image_url = properties[OPT_RESPONSE_IMAGE_URL] if (properties.has_key?(OPT_RESPONSE_IMAGE_URL))
|
39
|
-
response_instance.target_url = properties[OPT_RESPONSE_TARGET_URL] if (properties.has_key?(OPT_RESPONSE_TARGET_URL))
|
40
|
-
response_instance.target = properties[OPT_RESPONSE_TARGET] if (properties.has_key?(OPT_RESPONSE_TARGET))
|
41
|
-
# map the parent object
|
42
|
-
response_instance.optimization = optimization
|
43
|
-
#return the new instance of the optimization class
|
44
|
-
response_instance
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
# ---- Instance Methods
|
49
|
-
|
50
|
-
# helper method to get the interacton object from the parent optimization
|
51
|
-
def interaction
|
52
|
-
@optimization.interaction
|
53
|
-
end
|
54
|
-
|
55
|
-
# wrapper for sending the response from the existing object
|
56
|
-
def send
|
57
|
-
interaction.send_update({RESPONSE_CODE_PROPERTY => @code})
|
58
|
-
end
|
59
|
-
|
60
|
-
# returns true if the curent response is a positive response
|
61
|
-
def is_positive?()
|
62
|
-
(@sentiment.casecmp(SENTIMENT_POSITIVE) == 0)
|
63
|
-
end
|
64
|
-
# returns true if the current response is a neutral response
|
65
|
-
def is_neutral?()
|
66
|
-
( @sentiment.casecmp(SENTIMENT_NEUTRAL) == 0)
|
67
|
-
end
|
68
|
-
# returns true if the current response is a negative response
|
69
|
-
def is_negative?
|
70
|
-
( @sentiment.casecmp(SENTIMENT_NEGATIVE) == 0)
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
end
|
data/lib/oehclient/realtime.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
module OEHClient
|
2
|
-
|
3
|
-
module Realtime
|
4
|
-
end
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
require File.dirname(__FILE__) + '/realtime/interaction'
|
9
|
-
require File.dirname(__FILE__) + '/realtime/event'
|
10
|
-
require File.dirname(__FILE__) + '/realtime/optimization'
|
11
|
-
require File.dirname(__FILE__) + '/realtime/response'
|
data/lib/oehclient/version.rb
DELETED
data/oeh-client.gemspec
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'oehclient/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "oeh-client"
|
8
|
-
spec.version = OEHClient::VERSION
|
9
|
-
spec.authors = ["Jason Balliet"]
|
10
|
-
spec.email = ["jballiet@thunderhead.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{Simple class-based client for integration to ONE Engagement Hub}
|
13
|
-
spec.description = %q{A simple set of classes that allow access to Interactions, Documents, and Structures from within Thunderhead's ONE Enagement Hub}
|
14
|
-
spec.homepage = "https://rubygems.org/gems/oeh-client"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
-
# delete this section to allow pushing this gem to any host.
|
19
|
-
#if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
#else
|
22
|
-
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
#end
|
24
|
-
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
spec.bindir = "exe"
|
27
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = ["lib"]
|
29
|
-
|
30
|
-
spec.add_development_dependency "bundler", "~> 1", ">= 1.10"
|
31
|
-
spec.add_development_dependency "rake", "~> 12.0.0", ">= 12.0.0"
|
32
|
-
spec.add_development_dependency "rspec-rails", "~> 3", ">= 3.2"
|
33
|
-
|
34
|
-
spec.add_dependency "oauth", "~> 0.5"
|
35
|
-
spec.add_dependency "json", "~> 2"
|
36
|
-
spec.add_dependency "uuidtools", "~> 2.1"
|
37
|
-
spec.add_dependency "activesupport", "~> 5", '>= 5.0.1'
|
38
|
-
spec.add_dependency "railties", "~> 5", '>= 5.0.1'
|
39
|
-
spec.add_dependency "rest-client", "~> 2.0"
|
40
|
-
|
41
|
-
end
|