class BetterAlexaRubyKit::IntentRequest

Attributes

intent[RW]
name[RW]
slots[RW]

Public Class Methods

new(json_request) click to toggle source

We still don't know if all of the parameters in the request are required. Checking for the presence of intent on an IntentRequest.

Calls superclass method
# File lib/better_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

Public Instance Methods

add_hash_slots(slots) click to toggle source

Takes a Hash object.

# File lib/better_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) click to toggle source

Adds a slot from a name and a value.

# File lib/better_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) click to toggle source

Takes a JSON Object and symbolizes its keys.

# File lib/better_alexa_rubykit/intent_request.rb, line 26
def add_slots(slots)
  slot_hash = BetterAlexaRubyKit.transform_keys_to_symbols(value)
  add_hash_slots(slot_hash)
end
to_s() click to toggle source

Outputs the Intent Name, request Id and slot information.

# File lib/better_alexa_rubykit/intent_request.rb, line 39
def to_s
  "IntentRequest: #{name} requestID: #{request_id}  Slots: #{slots}"
end