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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4914d46433c089f9f961bdc39d0f58a2ed106872
4
- data.tar.gz: 97248da62edaa4d7124ebf75da051ba22ecaaa59
3
+ metadata.gz: e329ef9084462966190cde7df9afadd941a63d63
4
+ data.tar.gz: 2883d18464bd912779cf8e1f45c8e9f70f9e1c01
5
5
  SHA512:
6
- metadata.gz: 5279577a63e004b9f9fcac636b582c9250901bff34cc245677917f23ea8b4ec3f0a0575504a3995354b0a3dee9c76a1f002014fb9011e0a1239fd72eeeeddb6d
7
- data.tar.gz: f0f3401766d11ea8d0b44ac661309cfccb38ca602d1a25a7228bdc9e7b7d11e13899a3905da884e68ea04e9d6cb64ea4d980d7dfca089d6b9ab24a3ebb92f426
6
+ metadata.gz: 76178d87e2ed00917e314fe83be1f86e5d59276e748a9593d5a9109bffbc67a69a10e69c7e627e860c4158de9c6c03b0e862dcda1d656096cea53c519ff04edc
7
+ data.tar.gz: f61c150e15dbd33c17a781e73337b7a9eff598d002df6b1dc65a80994dfcaec1cfbdd17c91e12ac5e3d30d378e1cecfead7f83e39bef334272dc9aaec78c7de5
@@ -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 = "/interaction"
10
- API_OFFLINE = "/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 = "uri"
13
- ONE_PARAM_CK = "customerKey"
14
- ONE_PARAM_TID = "tid"
15
- ONE_PARAM_SESSION = "session"
16
- ONE_PARAM_SK = "sk"
17
- ONE_PARAM_TS = "timestamp"
18
- ONE_PARAM_PROPERTIES = "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 = "name"
21
- ONE_PROPERTIES_VALUE = "value"
21
+ ONE_PROPERTIES_NAME = "name"
22
+ ONE_PROPERTIES_VALUE = "value"
22
23
  # Collection objects returned in the response
23
- ONE_RESPONSE_OPTIMIZATIONS = "optimizations"
24
- ONE_RESPONSE_TRACKERS = "trackers"
25
- ONE_RESPONSE_CAPTURES = "captures"
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
- @optimizations << OEHClient::Interaction::Optimization.create(response_optimization)
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
- OPT_RESPONSE_DATA = "data"
8
- OPT_RESPONSE_PATH = "path"
9
- OPT_RESPONSE_ID = "responseId"
10
- OPT_RESPONSE_MIME_TYPE = "dataMimeType"
11
- OPT_RESPONSE_DIRECTIVES = "directives"
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 :data, # Base64 Encoded Asset returned by OEH
15
- :path, # The path of the optimization based on the OEH Configuration
16
- :response_id, # The Response ID of the asset based on the OEH Configuration
17
- :mime_type, # The MIME Type of the asset based on the OEH Configuration
18
- :directives
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.data = properties[OPT_RESPONSE_DATA] if (properties.has_key?(OPT_RESPONSE_DATA))
30
- optimization_instance.path = properties[OPT_RESPONSE_PATH] if (properties.has_key?(OPT_RESPONSE_PATH))
31
- optimization_instance.response_id = properties[OPT_RESPONSE_ID] if (properties.has_key?(OPT_RESPONSE_ID))
32
- optimization_instance.mime_type = properties[OPT_RESPONSE_MIME_TYPE] if (properties.has_key?(OPT_RESPONSE_ID))
33
- optimization_instance.directives = properties[OPT_RESPONSE_DIRECTIVES] if (properties.has_key?(OPT_RESPONSE_DIRECTIVES))
34
-
35
- #puts "Response ID is #{Base64.decode64(optimization_instance.response_id)}"
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
@@ -7,3 +7,4 @@ end
7
7
 
8
8
  require File.dirname(__FILE__) + '/interaction/interaction'
9
9
  require File.dirname(__FILE__) + '/interaction/optimization'
10
+ require File.dirname(__FILE__) + '/interaction/response'
@@ -1,3 +1,3 @@
1
1
  module OEHClient
2
- VERSION = "0.2.5"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.5
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-13 00:00:00.000000000 Z
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