lib/oehclient/interaction/optimization.rb in oeh-client-0.2.5 vs lib/oehclient/interaction/optimization.rb in oeh-client-0.3.0
- old
+ new
@@ -2,52 +2,54 @@
require 'cgi'
class OEHClient::Interaction::Optimization
# HASH keys based on the response data
- OPT_RESPONSE_DATA = "data"
- OPT_RESPONSE_PATH = "path"
- OPT_RESPONSE_ID = "responseId"
- OPT_RESPONSE_MIME_TYPE = "dataMimeType"
- OPT_RESPONSE_DIRECTIVES = "directives"
+ OPT_RESPONSE_NAME = "name"
+ OPT_RESPONSE_ASSET = "asset"
+ OPT_RESPONSE_CONTENT = "content"
+ OPT_RESPONSE_CONTENT_URL = "contentUrl"
+ OPT_RESPONSE_MIME_TYPE = "mimeType"
+ OPT_RESPONSE_PROPOSITION = "proposition"
+ OPT_RESPONSE_RESPONSES = "responses"
# Localized attributes equivalent to the returned Hash object in the response
- attr_accessor :data, # Base64 Encoded Asset returned by OEH
- :path, # The path of the optimization based on the OEH Configuration
- :response_id, # The Response ID of the asset based on the OEH Configuration
- :mime_type, # The MIME Type of the asset based on the OEH Configuration
- :directives
+ attr_accessor :name, # The name of the action
+ :content, # The decoded content of the asset
+ :content_url, # The URL to the referential asset
+ :mime_type, # The MIME Type of the asset based on the OEH Configuration
+ :proposition, # The code of the proposition, related to the optimization
+ :responses, # The collection of responses valid for this optmization
+ :interaction # The parent interaction object
-
# ---- Class Methods
- def self.create(properties={})
+ def self.create(interaction, properties={})
+ one_asset = properties[OPT_RESPONSE_ASSET]
+
# create a new instance of the OEHClient::Interaction::Optimization class
optimization_instance = OEHClient::Interaction::Optimization.new()
# assign all data attributes based on the properties object that is passed
- optimization_instance.data = properties[OPT_RESPONSE_DATA] if (properties.has_key?(OPT_RESPONSE_DATA))
- optimization_instance.path = properties[OPT_RESPONSE_PATH] if (properties.has_key?(OPT_RESPONSE_PATH))
- optimization_instance.response_id = properties[OPT_RESPONSE_ID] if (properties.has_key?(OPT_RESPONSE_ID))
- optimization_instance.mime_type = properties[OPT_RESPONSE_MIME_TYPE] if (properties.has_key?(OPT_RESPONSE_ID))
- optimization_instance.directives = properties[OPT_RESPONSE_DIRECTIVES] if (properties.has_key?(OPT_RESPONSE_DIRECTIVES))
-
- #puts "Response ID is #{Base64.decode64(optimization_instance.response_id)}"
-
+ optimization_instance.name = properties[OPT_RESPONSE_NAME] if (properties.has_key?(OPT_RESPONSE_NAME))
+ optimization_instance.proposition = properties[OPT_RESPONSE_PROPOSITION] if (properties.has_key?(OPT_RESPONSE_PROPOSITION))
+ # map the asset data to the class instance variables
+ optimization_instance.content = CGI.unescapeHTML(one_asset[OPT_RESPONSE_CONTENT]) if (one_asset.has_key?(OPT_RESPONSE_CONTENT))
+ optimization_instance.content_url = one_asset[OPT_RESPONSE_CONTENT_URL] if (one_asset.has_key?(OPT_RESPONSE_CONTENT_URL))
+ optimization_instance.mime_type = one_asset[OPT_RESPONSE_MIME_TYPE] if (one_asset.has_key?(OPT_RESPONSE_MIME_TYPE))
+ # map each of the respones to the response object
+ optimization_instance.responses ||= Array.new
+ one_asset[OPT_RESPONSE_RESPONSES].each do | asset_response |
+ optimization_instance.responses << OEHClient::Interaction::Response.create(optimization_instance, asset_response)
+ end
+ # set the parent interaction object
+ optimization_instance.interaction = interaction
#return the new instance of the optimzation class
optimization_instance
end
# ---- Instance Methods
-
- # TODO: Need to create a series of methods that properly decodes the object based on Mime Type
- # decodes the Base64 encoded data and returns it raw form
- def decode_data()
-
- CGI.unescapeHTML(Base64.decode64(@data.to_json))
-
- end
end
\ No newline at end of file