Class: AlexaRubykit::IntentRequest
- Defined in:
- lib/alexa_rubykit/intent_request.rb
Instance Attribute Summary collapse
-
#intent ⇒ Object
Returns the value of attribute intent.
-
#name ⇒ Object
Returns the value of attribute name.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
-
#slots ⇒ Object
Returns the value of attribute slots.
Attributes inherited from Request
#response, #session, #shouldEndSession, #type, #version
Instance Method Summary collapse
-
#add_hash_slots(slots) ⇒ Object
Takes a Hash object.
-
#add_slot(name, value) ⇒ Object
Adds a slot from a name and a value.
-
#add_slots(slots) ⇒ Object
Takes a JSON Object and symbolizes its keys.
-
#initialize(request_id, intent) ⇒ IntentRequest
constructor
We still don’t know if all of the parameters in the request are required.
- #to_s ⇒ Object
Methods inherited from Request
Constructor Details
#initialize(request_id, intent) ⇒ IntentRequest
We still don’t know if all of the parameters in the request are required. Checking for the presence of intent on an IntentRequest.
7 8 9 10 11 12 13 14 |
# File 'lib/alexa_rubykit/intent_request.rb', line 7 def initialize(request_id, intent) raise ArgumentError, 'Intent should exist on an IntentRequest' if intent.nil? @type = 'INTENT_REQUEST' @request_id = request_id @intent = intent @name = intent['name'] @slots = intent['slots'] end |
Instance Attribute Details
#intent ⇒ Object
Returns the value of attribute intent.
3 4 5 |
# File 'lib/alexa_rubykit/intent_request.rb', line 3 def intent @intent end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/alexa_rubykit/intent_request.rb', line 3 def name @name end |
#request_id ⇒ Object
Returns the value of attribute request_id.
3 4 5 |
# File 'lib/alexa_rubykit/intent_request.rb', line 3 def request_id @request_id end |
#slots ⇒ Object
Returns the value of attribute slots.
3 4 5 |
# File 'lib/alexa_rubykit/intent_request.rb', line 3 def slots @slots end |
Instance Method Details
#add_hash_slots(slots) ⇒ Object
Takes a Hash object.
17 18 19 20 21 22 23 |
# File 'lib/alexa_rubykit/intent_request.rb', line 17 def add_hash_slots(slots) raise ArgumentError, 'Slots can\'t be empty' slots.each do |slot| @slots[:slot[:name]] = Slot.new(slot[:name], slot[:value]) end @slots end |
#add_slot(name, value) ⇒ Object
Adds a slot from a name and a value.
32 33 34 35 36 |
# File 'lib/alexa_rubykit/intent_request.rb', line 32 def add_slot(name, value) slot = Slot.new(name, value) @slots[:name] = slot slot end |
#add_slots(slots) ⇒ Object
Takes a JSON Object and symbolizes its keys.
26 27 28 29 |
# File 'lib/alexa_rubykit/intent_request.rb', line 26 def add_slots(slots) slot_hash = AlexaRubykit.transform_keys_to_symbols(value) add_hash_slots(slot_hash) end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/alexa_rubykit/intent_request.rb', line 38 def to_s "IntentRequest: #{@name} requestID: #{request_id} Slots: #{@slots}" end |