Class: AlexaRubykit::IntentRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/alexa_rubykit/intent_request.rb

Instance Attribute Summary collapse

Attributes inherited from Request

#json, #locale, #request_id, #session, #type, #version

Instance Method Summary collapse

Constructor Details

#initialize(json_request) ⇒ 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.

Raises:

  • (ArgumentError)

7
8
9
10
11
12
13
14
# File 'lib/alexa_rubykit/intent_request.rb', line 7

def initialize(json_request)
  super
  @intent = json_request['request']['intent']
  raise ArgumentError, 'Intent should exist on an IntentRequest' if @intent.nil?
  @type = 'INTENT_REQUEST'
  @name  = @intent['name']
  @slots = @intent['slots']
end

Instance Attribute Details

#intentObject

Returns the value of attribute intent


3
4
5
# File 'lib/alexa_rubykit/intent_request.rb', line 3

def intent
  @intent
end

#nameObject

Returns the value of attribute name


3
4
5
# File 'lib/alexa_rubykit/intent_request.rb', line 3

def name
  @name
end

#slotsObject

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.

Raises:

  • (ArgumentError)

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_sObject

Outputs the Intent Name, request Id and slot information.


39
40
41
# File 'lib/alexa_rubykit/intent_request.rb', line 39

def to_s
  "IntentRequest: #{name} requestID: #{request_id}  Slots: #{slots}"
end