Class: OEHClient::Realtime::Optimization

Inherits:
Object
  • Object
show all
Defined in:
lib/oehclient/realtime/optimization.rb

Constant Summary collapse

OPT_RESPONSE_NAME =

HASH keys based on the response data

"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"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#contentObject

Localized attributes equivalent to the returned Hash object in the response


16
17
18
# File 'lib/oehclient/realtime/optimization.rb', line 16

def content
  @content
end

#content_urlObject

Localized attributes equivalent to the returned Hash object in the response


16
17
18
# File 'lib/oehclient/realtime/optimization.rb', line 16

def content_url
  @content_url
end

#interactionObject

Localized attributes equivalent to the returned Hash object in the response


16
17
18
# File 'lib/oehclient/realtime/optimization.rb', line 16

def interaction
  @interaction
end

#mime_typeObject

Localized attributes equivalent to the returned Hash object in the response


16
17
18
# File 'lib/oehclient/realtime/optimization.rb', line 16

def mime_type
  @mime_type
end

#nameObject

Localized attributes equivalent to the returned Hash object in the response


16
17
18
# File 'lib/oehclient/realtime/optimization.rb', line 16

def name
  @name
end

#propositionObject

Localized attributes equivalent to the returned Hash object in the response


16
17
18
# File 'lib/oehclient/realtime/optimization.rb', line 16

def proposition
  @proposition
end

#responsesObject

Localized attributes equivalent to the returned Hash object in the response


16
17
18
# File 'lib/oehclient/realtime/optimization.rb', line 16

def responses
  @responses
end

Class Method Details

.create(interaction, properties = {}) ⇒ Object

—- Class Methods


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/oehclient/realtime/optimization.rb', line 26

def self.create(interaction, properties={})

	one_asset = properties[OPT_RESPONSE_ASSET]

	# create a new instance of the OEHClient::Realtime::Optimization class
	optimization_instance = OEHClient::Realtime::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::Realtime::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