Class: OEHClient::Realtime::Response

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

Constant Summary collapse

OPT_RESPONSE_CODE =

HASH keys based on the response data

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#codeObject

Localized attributes equivalent to the returned Hash object in the response


19
20
21
# File 'lib/oehclient/realtime/response.rb', line 19

def code
  @code
end

#image_urlObject

Localized attributes equivalent to the returned Hash object in the response


19
20
21
# File 'lib/oehclient/realtime/response.rb', line 19

def image_url
  @image_url
end

#labelObject

Localized attributes equivalent to the returned Hash object in the response


19
20
21
# File 'lib/oehclient/realtime/response.rb', line 19

def label
  @label
end

#optimizationObject

Localized attributes equivalent to the returned Hash object in the response


19
20
21
# File 'lib/oehclient/realtime/response.rb', line 19

def optimization
  @optimization
end

#sentimentObject

Localized attributes equivalent to the returned Hash object in the response


19
20
21
# File 'lib/oehclient/realtime/response.rb', line 19

def sentiment
  @sentiment
end

#targetObject

Localized attributes equivalent to the returned Hash object in the response


19
20
21
# File 'lib/oehclient/realtime/response.rb', line 19

def target
  @target
end

#target_urlObject

Localized attributes equivalent to the returned Hash object in the response


19
20
21
# File 'lib/oehclient/realtime/response.rb', line 19

def target_url
  @target_url
end

Class Method Details

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

—- Class Methods

[View source]

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/oehclient/realtime/response.rb', line 29

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 Method Details

#interactionObject

helper method to get the interacton object from the parent optimization

[View source]

51
52
53
# File 'lib/oehclient/realtime/response.rb', line 51

def interaction
  @optimization.interaction
end

#is_negative?Boolean

returns true if the current response is a negative response

Returns:

  • (Boolean)
[View source]

69
70
71
# File 'lib/oehclient/realtime/response.rb', line 69

def is_negative?
  ( @sentiment.casecmp(SENTIMENT_NEGATIVE) == 0)
end

#is_neutral?Boolean

returns true if the current response is a neutral response

Returns:

  • (Boolean)
[View source]

65
66
67
# File 'lib/oehclient/realtime/response.rb', line 65

def is_neutral?()
  ( @sentiment.casecmp(SENTIMENT_NEUTRAL) == 0)
end

#is_positive?Boolean

returns true if the curent response is a positive response

Returns:

  • (Boolean)
[View source]

61
62
63
# File 'lib/oehclient/realtime/response.rb', line 61

def is_positive?()
   (@sentiment.casecmp(SENTIMENT_POSITIVE) == 0)
end

#sendObject

wrapper for sending the response from the existing object

[View source]

56
57
58
# File 'lib/oehclient/realtime/response.rb', line 56

def send
  interaction.send_update({RESPONSE_CODE_PROPERTY => @code})
end