oeh-client 0.2.5 → 0.3.0
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
- data/lib/oehclient/helper.rb +1 -1
- data/lib/oehclient/interaction/interaction.rb +23 -15
- data/lib/oehclient/interaction/optimization.rb +30 -28
- data/lib/oehclient/interaction/response.rb +74 -0
- data/lib/oehclient/interaction.rb +1 -0
- data/lib/oehclient/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e329ef9084462966190cde7df9afadd941a63d63
|
4
|
+
data.tar.gz: 2883d18464bd912779cf8e1f45c8e9f70f9e1c01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76178d87e2ed00917e314fe83be1f86e5d59276e748a9593d5a9109bffbc67a69a10e69c7e627e860c4158de9c6c03b0e862dcda1d656096cea53c519ff04edc
|
7
|
+
data.tar.gz: f61c150e15dbd33c17a781e73337b7a9eff598d002df6b1dc65a80994dfcaec1cfbdd17c91e12ac5e3d30d378e1cecfead7f83e39bef334272dc9aaec78c7de5
|
data/lib/oehclient/helper.rb
CHANGED
@@ -38,7 +38,7 @@ module OEHClient
|
|
38
38
|
# default_JSON_header is the default header that is passed to any OEH Request if not provided explicitly by the
|
39
39
|
# calling methods
|
40
40
|
def self.default_JSON_header()
|
41
|
-
{'Accept' => 'application/json' , 'Content-Type' =>'application/json', 'X-Requested-With' => 'XMLHttpRequest' }
|
41
|
+
{'Accept' => 'application/json' , 'dataMimeType' => 'application/json','Content-Type' =>'application/json', 'X-Requested-With' => 'XMLHttpRequest' }
|
42
42
|
end
|
43
43
|
|
44
44
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'base64'
|
1
2
|
|
2
3
|
class OEHClient::Interaction::Interaction
|
3
4
|
|
@@ -6,23 +7,25 @@ class OEHClient::Interaction::Interaction
|
|
6
7
|
#
|
7
8
|
|
8
9
|
# constants used to construct the restful API Request URL
|
9
|
-
API_REALTIME
|
10
|
-
API_OFFLINE
|
10
|
+
API_REALTIME = "/interaction"
|
11
|
+
API_OFFLINE = "/offline"
|
11
12
|
# ONE attributes that are either in the request and/or returned in the response
|
12
|
-
ONE_PARAM_URI
|
13
|
-
ONE_PARAM_CK
|
14
|
-
ONE_PARAM_TID
|
15
|
-
ONE_PARAM_SESSION
|
16
|
-
ONE_PARAM_SK
|
17
|
-
ONE_PARAM_TS
|
18
|
-
ONE_PARAM_PROPERTIES
|
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"
|
19
20
|
# Property Hash Keys
|
20
|
-
ONE_PROPERTIES_NAME
|
21
|
-
ONE_PROPERTIES_VALUE
|
21
|
+
ONE_PROPERTIES_NAME = "name"
|
22
|
+
ONE_PROPERTIES_VALUE = "value"
|
22
23
|
# Collection objects returned in the response
|
23
|
-
ONE_RESPONSE_OPTIMIZATIONS
|
24
|
-
|
25
|
-
|
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"
|
26
29
|
|
27
30
|
|
28
31
|
#
|
@@ -231,7 +234,12 @@ class OEHClient::Interaction::Interaction
|
|
231
234
|
@optimizations ||= Array.new
|
232
235
|
# map each of the optimizations to the OEHClient::Interaction::Optmization class
|
233
236
|
body[ONE_RESPONSE_OPTIMIZATIONS].each do | response_optimization |
|
234
|
-
|
237
|
+
# decode the data of the optimization
|
238
|
+
optimization_data = ActiveSupport::JSON.decode(Base64.decode64(response_optimization[ONE_RESPONSE_OPTIMIZATION_DATA]))
|
239
|
+
# get the actions for each optimization
|
240
|
+
optimization_data[ONE_RESPONSE_ACTIONS].each do | one_action |
|
241
|
+
@optimizations << OEHClient::Interaction::Optimization.create(self, one_action)
|
242
|
+
end
|
235
243
|
end
|
236
244
|
|
237
245
|
# store the cookies passed back by the system
|
@@ -4,36 +4,46 @@ require 'cgi'
|
|
4
4
|
class OEHClient::Interaction::Optimization
|
5
5
|
|
6
6
|
# HASH keys based on the response data
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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"
|
12
14
|
|
13
15
|
# Localized attributes equivalent to the returned Hash object in the response
|
14
|
-
attr_accessor :
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:mime_type,
|
18
|
-
:
|
19
|
-
|
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
|
20
23
|
|
21
24
|
# ---- Class Methods
|
22
25
|
|
23
|
-
def self.create(properties={})
|
26
|
+
def self.create(interaction, properties={})
|
27
|
+
|
28
|
+
one_asset = properties[OPT_RESPONSE_ASSET]
|
24
29
|
|
25
30
|
# create a new instance of the OEHClient::Interaction::Optimization class
|
26
31
|
optimization_instance = OEHClient::Interaction::Optimization.new()
|
27
32
|
|
28
33
|
# assign all data attributes based on the properties object that is passed
|
29
|
-
optimization_instance.
|
30
|
-
optimization_instance.
|
31
|
-
|
32
|
-
optimization_instance.
|
33
|
-
optimization_instance.
|
34
|
-
|
35
|
-
#
|
36
|
-
|
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::Interaction::Response.create(optimization_instance, asset_response)
|
44
|
+
end
|
45
|
+
# set the parent interaction object
|
46
|
+
optimization_instance.interaction = interaction
|
37
47
|
#return the new instance of the optimzation class
|
38
48
|
optimization_instance
|
39
49
|
|
@@ -41,13 +51,5 @@ class OEHClient::Interaction::Optimization
|
|
41
51
|
|
42
52
|
# ---- Instance Methods
|
43
53
|
|
44
|
-
# TODO: Need to create a series of methods that properly decodes the object based on Mime Type
|
45
|
-
# decodes the Base64 encoded data and returns it raw form
|
46
|
-
def decode_data()
|
47
|
-
|
48
|
-
CGI.unescapeHTML(Base64.decode64(@data.to_json))
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
54
|
|
53
55
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
|
2
|
+
class OEHClient::Interaction::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::Interaction::Optimization class
|
32
|
+
response_instance = OEHClient::Interaction::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)
|
63
|
+
end
|
64
|
+
# returns true if the current response is a neutral response
|
65
|
+
def is_neutral?()
|
66
|
+
@sentiment.casecmp(SENTIMENT_NEUTRAL)
|
67
|
+
end
|
68
|
+
# returns true if the current response is a negative response
|
69
|
+
def is_negative?
|
70
|
+
@sentiment.casecmp(SENTIMENT_NEGATIVE)
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
end
|
data/lib/oehclient/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oeh-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Balliet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- lib/oehclient/interaction.rb
|
169
169
|
- lib/oehclient/interaction/interaction.rb
|
170
170
|
- lib/oehclient/interaction/optimization.rb
|
171
|
+
- lib/oehclient/interaction/response.rb
|
171
172
|
- lib/oehclient/meta.rb
|
172
173
|
- lib/oehclient/meta/entity.rb
|
173
174
|
- lib/oehclient/meta/workspace.rb
|