Class: AlexaRuby::IntentRequest
- Defined in:
- lib/alexa_ruby/request/intent_request.rb
Overview
IntentRequest class implements Alexa “IntentRequest” request type
Instance Attribute Summary collapse
-
#intent ⇒ Object
Returns the value of attribute intent.
-
#name ⇒ Object
Returns the value of attribute name.
-
#slots ⇒ Object
Returns the value of attribute slots.
Attributes inherited from Request
#json, #locale, #request_id, #session, #type, #version
Instance Method Summary collapse
-
#add_hash_slots(slots) ⇒ Object
Takes a Hash object with slots and add it to slots node.
-
#add_slot(name, value) ⇒ Object
Adds a slot from a name and a value.
-
#add_slots(slots) ⇒ Object
Takes a JSON with slots and add it to slots node.
-
#initialize(json) ⇒ IntentRequest
constructor
Initialize new Intent request.
-
#to_s ⇒ String
Outputs the Intent Name, request Id and slot information.
Constructor Details
#initialize(json) ⇒ IntentRequest
Initialize new Intent request
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/alexa_ruby/request/intent_request.rb', line 11 def initialize(json) @intent = json[:request][:intent] if @intent.nil? raise ArgumentError, 'Intent should exist on an IntentRequest' end @type = :intent @name = @intent[:name] @slots = @intent[:slots] super end |
Instance Attribute Details
#intent ⇒ Object
Returns the value of attribute intent.
6 7 8 |
# File 'lib/alexa_ruby/request/intent_request.rb', line 6 def intent @intent end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/alexa_ruby/request/intent_request.rb', line 6 def name @name end |
#slots ⇒ Object
Returns the value of attribute slots.
6 7 8 |
# File 'lib/alexa_ruby/request/intent_request.rb', line 6 def slots @slots end |
Instance Method Details
#add_hash_slots(slots) ⇒ Object
Takes a Hash object with slots and add it to slots node
27 28 29 30 31 32 33 |
# File 'lib/alexa_ruby/request/intent_request.rb', line 27 def add_hash_slots(slots) raise ArgumentError, 'Slots can\'t be empty' if slots.nil? 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
48 49 50 51 52 |
# File 'lib/alexa_ruby/request/intent_request.rb', line 48 def add_slot(name, value) slot = Slot.new(name, value) @slots[:name] = slot slot end |
#add_slots(slots) ⇒ Object
Takes a JSON with slots and add it to slots node
38 39 40 41 |
# File 'lib/alexa_ruby/request/intent_request.rb', line 38 def add_slots(slots) slot_hash = Oj.load(slots, symbol_keys: true) add_hash_slots(slot_hash) end |
#to_s ⇒ String
Outputs the Intent Name, request Id and slot information
57 58 59 |
# File 'lib/alexa_ruby/request/intent_request.rb', line 57 def to_s "IntentRequest: #{name} requestID: #{request_id} Slots: #{slots}" end |