alexa_rubykit 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/alexa_rubykit/intent_request.rb +57 -0
- data/lib/alexa_rubykit/launch_request.rb +16 -0
- data/lib/alexa_rubykit/request.rb +24 -17
- data/lib/alexa_rubykit/version.rb +1 -1
- data/lib/alexa_rubykit.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bb6171d59540cf84093f975baadecce2e845ee1
|
4
|
+
data.tar.gz: b283a2cf1d67ed6e51d43a223ebe2c96321c0827
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 973f24b4cd65410b41a85fd80eaac170f2e9383a5ec04d413670333fb96f3028d6494427ce04940dae1b3b0e4427444244a1c2f8aa1d058584c53ac89a879eb7
|
7
|
+
data.tar.gz: edd21dda5ad14808798304018e85a09306dd41af059883d1d219fcd7ea72c29ea31ac5b6ed9a7769b67634da149a9b9770b524190a863495f609ab71dc8be2ba
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
module AlexaRubykit
|
2
|
+
class IntentRequest < Request
|
3
|
+
attr_accessor :request_id, :intent, :name, :slots
|
4
|
+
|
5
|
+
# We still don't know if all of the parameters in the request are required.
|
6
|
+
# Checking for the presence of intent on an IntentRequest.
|
7
|
+
def initialize(request_id, intent)
|
8
|
+
raise ArgumentError, 'Intent should exist on an IntentRequest' if intent.nil?
|
9
|
+
@type = 'INTENT_REQUEST'
|
10
|
+
@request_id = request_id
|
11
|
+
@intent = intent
|
12
|
+
@name = intent['name']
|
13
|
+
@slots = intent['slots']
|
14
|
+
end
|
15
|
+
|
16
|
+
# Takes a Hash object.
|
17
|
+
def add_hash_slots(slots)
|
18
|
+
raise ArgumentError, 'Slots can\'t be empty'
|
19
|
+
slots.each do |slot|
|
20
|
+
@slots[:slot[:name]] = Slot.new(slot[:name], slot[:value])
|
21
|
+
end
|
22
|
+
@slots
|
23
|
+
end
|
24
|
+
|
25
|
+
# Takes a JSON Object and symbolizes its keys.
|
26
|
+
def add_slots(slots)
|
27
|
+
slot_hash = AlexaRubykit.transform_keys_to_symbols(value)
|
28
|
+
add_hash_slots(slot_hash)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Adds a slot from a name and a value.
|
32
|
+
def add_slot(name, value)
|
33
|
+
slot = Slot.new(name, value)
|
34
|
+
@slots[:name] = slot
|
35
|
+
slot
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
"IntentRequest: #{@name} requestID: #{request_id} Slots: #{@slots}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
class Slot
|
45
|
+
attr_accessor :name, :value
|
46
|
+
|
47
|
+
def initialize(name, value)
|
48
|
+
raise ArgumentError, 'Need a name and a value' if name.nil? || value.nil?
|
49
|
+
@name = name
|
50
|
+
@value = value
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_s
|
54
|
+
"Slot Name: #{@name}, Value: #{value}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module AlexaRubykit
|
2
|
+
class LaunchRequest < Request
|
3
|
+
attr_accessor :request_id
|
4
|
+
|
5
|
+
# We still don't know if all of the parameters in the request are required.
|
6
|
+
# Checking for the presence of intent on an IntentRequest.
|
7
|
+
def initialize(request_id)
|
8
|
+
raise ArgumentError, 'Request ID should exist on a LaunchRequest' if request_id.nil?
|
9
|
+
@type = 'LAUNCH_REQUEST'
|
10
|
+
@request_id = request_id
|
11
|
+
end
|
12
|
+
def to_s
|
13
|
+
"LaunchRequest requestID: #{@request_id}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -5,25 +5,32 @@ module AlexaRubykit
|
|
5
5
|
# - SessionEndedRequest: Session has ended.
|
6
6
|
class Request
|
7
7
|
require 'json'
|
8
|
-
require 'sinatra'
|
9
|
-
require 'alexa_rubykit'
|
10
8
|
attr_accessor :version, :session_return, :response, :shouldEndSession, :type
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.build_request(json_request)
|
12
|
+
raise ArgumentError, 'Invalid Alexa Request.' unless AlexaRubykit.valid_alexa?(json_request)
|
13
|
+
@request = nil
|
14
|
+
case json_request['request']['type']
|
15
|
+
when /Launch/
|
16
|
+
@request = LaunchRequest.new(json_request['request']['requestId'])
|
17
|
+
when /Intent/
|
18
|
+
@request = IntentRequest.new(json_request['request']['requestId'], json_request['request']['intent'])
|
19
|
+
when /SessionEnded/
|
20
|
+
'SESSION_ENDED'
|
21
|
+
else
|
22
|
+
raise ArgumentError, 'Invalid Request Type.'
|
23
|
+
end
|
24
|
+
@request
|
25
|
+
end
|
11
26
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@type = 'LAUNCH'
|
20
|
-
when /Intent/
|
21
|
-
@type = 'INTENT'
|
22
|
-
when /SessionEnded/
|
23
|
-
@type = 'SESSIONENDED'
|
24
|
-
else
|
25
|
-
halt 500
|
26
|
-
end
|
27
|
+
# Let's monkey patch Hash.
|
28
|
+
refine Hash do
|
29
|
+
# Take keys of hash and transform those to a symbols
|
30
|
+
def self.transform_keys_to_symbols(value)
|
31
|
+
return value if not value.is_a?(Hash)
|
32
|
+
hash = value.inject({}){|memo,(k,v)| memo[k.to_sym] = Hash.transform_keys_to_symbols(v); memo}
|
33
|
+
return hash
|
27
34
|
end
|
28
35
|
end
|
29
36
|
end
|
data/lib/alexa_rubykit.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alexa_rubykit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damian Finol
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,6 +93,8 @@ files:
|
|
93
93
|
- README.md
|
94
94
|
- Rakefile
|
95
95
|
- lib/alexa_rubykit.rb
|
96
|
+
- lib/alexa_rubykit/intent_request.rb
|
97
|
+
- lib/alexa_rubykit/launch_request.rb
|
96
98
|
- lib/alexa_rubykit/request.rb
|
97
99
|
- lib/alexa_rubykit/response.rb
|
98
100
|
- lib/alexa_rubykit/version.rb
|