Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create slot objects on initializing an intent request #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/alexa_rubykit/intent_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ def initialize(json_request)
raise ArgumentError, 'Intent should exist on an IntentRequest' if @intent.nil?
@type = 'INTENT_REQUEST'
@name = @intent['name']
@slots = @intent['slots']
@slots = {}
add_slots(@intent['slots'])
end

# Takes a Hash object.
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])
raise ArgumentError, 'Slots can\'t be empty' if slots.empty?
slots.each do |name, slot|
@slots[name] = Slot.new(slot[:name], slot[:value])
end
@slots
end

# Takes a JSON Object and symbolizes its keys.
def add_slots(slots)
slot_hash = AlexaRubykit.transform_keys_to_symbols(value)
slot_hash = AlexaRubykit.transform_keys_to_symbols(slots)
add_hash_slots(slot_hash)
end

Expand Down Expand Up @@ -57,4 +58,4 @@ def to_s
"Slot Name: #{name}, Value: #{value}"
end
end
end
end
37 changes: 37 additions & 0 deletions spec/intent_request_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'rspec'
require 'alexa_rubykit'

describe AlexaRubykit::IntentRequest do

let :json_request do
JSON.parse(File.read('fixtures/sample-IntentRequest.json'))
end

let :request do
AlexaRubykit.build_request(json_request)
end

it do
expect(request).to be_a(described_class)
end

context '#slots' do
let :slots do
request.slots
end

it do
expect(slots).to be_a(Hash)

expect(slots.size).to eq(1)

expect(slots).to have_key(:ZodiacSign)

expect(slots[:ZodiacSign]).to be_a(AlexaRubykit::Slot)

expect(slots[:ZodiacSign].name).to eq('ZodiacSign')

expect(slots[:ZodiacSign].value).to eq('virgo')
end
end
end