class OEHClient::Realtime::Response # HASH keys based on the response data OPT_RESPONSE_CODE = "code" OPT_RESPONSE_SENTIMENT = "sentiment" OPT_RESPONSE_LABEL = "label" OPT_RESPONSE_IMAGE_URL = "imageUrl" OPT_RESPONSE_TARGET_URL = "targetUrl" OPT_RESPONSE_TARGET = "target" RESPONSE_CODE_PROPERTY = "_RESP_CODE_" SENTIMENT_POSITIVE = "positive" SENTIMENT_NEUTRAL = "neutral" SENTIMENT_NEGATIVE = "negative" # Localized attributes equivalent to the returned Hash object in the response attr_accessor :code, # The response code needed for responses :sentiment, # The sentiment of the response (POSITIVE, NEUTRAL, NEGATIVE) :label, # The label used for display :image_url, # The URL to the image :target_url, # The url to redirect to when the response is selected :target, # The Target Type (ONE, ...) :optimization # ---- Class Methods def self.create(optimization, properties={}) # create a new instance of the OEHClient::Realtime::Optimization class response_instance = OEHClient::Realtime::Response.new() # assign all data attributes based on the properties object that is passed response_instance.code = properties[OPT_RESPONSE_CODE] if (properties.has_key?(OPT_RESPONSE_CODE)) response_instance.sentiment = properties[OPT_RESPONSE_SENTIMENT] if (properties.has_key?(OPT_RESPONSE_SENTIMENT)) response_instance.label = properties[OPT_RESPONSE_LABEL] if (properties.has_key?(OPT_RESPONSE_LABEL)) response_instance.image_url = properties[OPT_RESPONSE_IMAGE_URL] if (properties.has_key?(OPT_RESPONSE_IMAGE_URL)) response_instance.target_url = properties[OPT_RESPONSE_TARGET_URL] if (properties.has_key?(OPT_RESPONSE_TARGET_URL)) response_instance.target = properties[OPT_RESPONSE_TARGET] if (properties.has_key?(OPT_RESPONSE_TARGET)) # map the parent object response_instance.optimization = optimization #return the new instance of the optimization class response_instance end # ---- Instance Methods # helper method to get the interacton object from the parent optimization def interaction @optimization.interaction end # wrapper for sending the response from the existing object def send interaction.send_update({RESPONSE_CODE_PROPERTY => @code}) end # returns true if the curent response is a positive response def is_positive?() (@sentiment.casecmp(SENTIMENT_POSITIVE) == 0) end # returns true if the current response is a neutral response def is_neutral?() ( @sentiment.casecmp(SENTIMENT_NEUTRAL) == 0) end # returns true if the current response is a negative response def is_negative? ( @sentiment.casecmp(SENTIMENT_NEGATIVE) == 0) end end