Sha256: 8ab30cbce13f377a4cc7a23408ef0d6a5548ce027bd11330e5c8b563e963301c

Contents?: true

Size: 1.94 KB

Versions: 10

Compression:

Stored size: 1.94 KB

Contents

require 'base64'
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"

	# 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


	# ---- Class Methods 

	def self.create(properties={})

		# 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)}"

		#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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
oeh-client-0.2.5 lib/oehclient/interaction/optimization.rb
oeh-client-0.2.4 lib/oehclient/interaction/optimization.rb
oeh-client-0.2.3 lib/oehclient/interaction/optimization.rb
oeh-client-0.2.2 lib/oehclient/interaction/optimization.rb
oeh-client-0.2.1 lib/oehclient/interaction/optimization.rb
oeh-client-0.2.0 lib/oehclient/interaction/optimization.rb
oeh-client-0.1.4 lib/oehclient/interaction/optimization.rb
oeh-client-0.1.3 lib/oehclient/interaction/optimization.rb
oeh-client-0.1.2 lib/oehclient/interaction/optimization.rb
oeh-client-0.1.1 lib/oehclient/interaction/optimization.rb