lib/oehclient/interaction/interaction.rb in oeh-client-0.2.5 vs lib/oehclient/interaction/interaction.rb in oeh-client-0.3.0
- old
+ new
@@ -1,30 +1,33 @@
+require 'base64'
class OEHClient::Interaction::Interaction
#
# -------[ CONSTANTS ]
#
# constants used to construct the restful API Request URL
- API_REALTIME = "/interaction"
- API_OFFLINE = "/offline"
+ 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_CK = "customerKey"
- ONE_PARAM_TID = "tid"
- ONE_PARAM_SESSION = "session"
- ONE_PARAM_SK = "sk"
- ONE_PARAM_TS = "timestamp"
- ONE_PARAM_PROPERTIES = "properties"
+ ONE_PARAM_URI = "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"
# Property Hash Keys
- ONE_PROPERTIES_NAME = "name"
- ONE_PROPERTIES_VALUE = "value"
+ ONE_PROPERTIES_NAME = "name"
+ ONE_PROPERTIES_VALUE = "value"
# Collection objects returned in the response
- ONE_RESPONSE_OPTIMIZATIONS = "optimizations"
- ONE_RESPONSE_TRACKERS = "trackers"
- ONE_RESPONSE_CAPTURES = "captures"
+ ONE_RESPONSE_OPTIMIZATIONS = "optimizations"
+ ONE_RESPONSE_OPTIMIZATION_DATA = "data"
+ ONE_RESPONSE_ACTIONS = "actions"
+ ONE_RESPONSE_TRACKERS = "trackers"
+ ONE_RESPONSE_CAPTURES = "captures"
#
# -------[ CLASS ATTRIBUTES ]
#
@@ -229,10 +232,15 @@
# initialize the optimizations collection if it is null
@optimizations ||= Array.new
# map each of the optimizations to the OEHClient::Interaction::Optmization class
body[ONE_RESPONSE_OPTIMIZATIONS].each do | response_optimization |
- @optimizations << OEHClient::Interaction::Optimization.create(response_optimization)
+ # decode the data of the optimization
+ optimization_data = ActiveSupport::JSON.decode(Base64.decode64(response_optimization[ONE_RESPONSE_OPTIMIZATION_DATA]))
+ # get the actions for each optimization
+ optimization_data[ONE_RESPONSE_ACTIONS].each do | one_action |
+ @optimizations << OEHClient::Interaction::Optimization.create(self, one_action)
+ end
end
# store the cookies passed back by the system
@cookies = response[:cookies]
\ No newline at end of file