require 'base64' require 'cgi' class OEHClient::Interaction::Optimization # HASH keys based on the response data 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 :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(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.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 end