Class: Ralyxa::RequestEntities::Request

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ralyxa/request_entities/request.rb

Constant Summary collapse

INTENT_REQUEST_TYPE =
'IntentRequest'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_request, user_class = Ralyxa::RequestEntities::User) ⇒ Request

Returns a new instance of Request.



18
19
20
21
22
23
24
25
# File 'lib/ralyxa/request_entities/request.rb', line 18

def initialize(original_request, user_class = Ralyxa::RequestEntities::User)
  validate_request(original_request) if Ralyxa.configuration.validate_requests?

  @request = JSON.parse(original_request.body.read)
  attempt_to_rewind_request_body(original_request)

  @user = user_class.build(@request)
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



16
17
18
# File 'lib/ralyxa/request_entities/request.rb', line 16

def request
  @request
end

Instance Method Details

#intent_nameObject



27
28
29
30
# File 'lib/ralyxa/request_entities/request.rb', line 27

def intent_name
  return @request['request']['type'] unless intent_request?
  @request['request']['intent']['name']
end

#new_session?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ralyxa/request_entities/request.rb', line 36

def new_session?
  @request['session']['new']
end

#session_attribute(attribute_name) ⇒ Object



44
45
46
# File 'lib/ralyxa/request_entities/request.rb', line 44

def session_attribute(attribute_name)
  session_attributes[attribute_name]
end

#session_attributesObject



40
41
42
# File 'lib/ralyxa/request_entities/request.rb', line 40

def session_attributes
  @request['session']['attributes']
end

#slot_value(slot_name) ⇒ Object



32
33
34
# File 'lib/ralyxa/request_entities/request.rb', line 32

def slot_value(slot_name)
  @request['request']['intent']['slots'][slot_name]['value']
end