alexa_toolbox 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +0 -2
- data/README.md +206 -15
- data/lib/alexa_toolbox/request.rb +1 -3
- data/lib/alexa_toolbox/version.rb +1 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd37cd19bb97de4723fc60c858e3b4c2a2af637b
|
4
|
+
data.tar.gz: de407de0f2d6409107f4319786fd06e6ba4a228f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c822745695ce11cff21386472fd36cd1c8e1df50142cbab6b3f3bb0b0d59d553110e931d6ee0a23b39596e87cfe824621174e9d45fc21a4cfaaa2c6ce9d88ad6
|
7
|
+
data.tar.gz: 17eedcdcf1e1fe44289982706ec48b75ad1069c5338de63868a4dfffbb3982f39667c7eb047feb9d01177a90b4b1001578e4171f2cb55a1e4c23c52a01aa5319
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -130,27 +130,218 @@ response.build_response
|
|
130
130
|
```ruby
|
131
131
|
require 'alexa_toolbox'
|
132
132
|
response = AlexaToolbox::Response.new
|
133
|
-
# add_card(type,title,
|
133
|
+
# add_card(type,title,content)
|
134
134
|
# or
|
135
|
-
# add_hash_card({ :type => type, :title => title, :
|
136
|
-
response.add_card("PlainText","Card Title","
|
135
|
+
# add_hash_card({ :type => type, :title => title, :content => content })
|
136
|
+
response.add_card("PlainText","Card Title","This card should have some interesting content for your user.")
|
137
137
|
response.build_response
|
138
138
|
```
|
139
139
|
|
140
|
-
|
140
|
+
## Full Documentation
|
141
141
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
"shouldEndSession": true
|
151
|
-
}
|
152
|
-
}
|
142
|
+
### Request
|
143
|
+
|
144
|
+
##### Initialization:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
request = AlexaToolbox::Request.new(json_request, {
|
148
|
+
:application_id => 'SKILL_APP_ID'
|
149
|
+
})
|
153
150
|
```
|
151
|
+
json_request should be a valid JSON request object.
|
152
|
+
If you are using Ruby on Rails, this will be the params variable in your controller.
|
153
|
+
While :application_id in the options hash is not required, part of Amazon Alexa security best practices is to compare request applicationId against your skill's application id. As such, I recommend this is set and you check validity (see below) before going further.
|
154
|
+
If you don't know where to find your application id, you can get it here:
|
155
|
+
[Get Your Application ID](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/handling-requests-sent-by-alexa#getting-the-application-id-for-a-skill)
|
156
|
+
|
157
|
+
##### .valid?
|
158
|
+
|
159
|
+
Check if the request is valid and intended for your application.
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
request = AlexaToolbox::Request.new(json_request, {
|
163
|
+
:application_id => 'SKILL_APP_ID'
|
164
|
+
})
|
165
|
+
if request.valid?
|
166
|
+
# continue with your skill logic
|
167
|
+
else
|
168
|
+
# return 500 as per Amazon Alexa Documentation
|
169
|
+
end
|
170
|
+
```
|
171
|
+
|
172
|
+
##### .json
|
173
|
+
|
174
|
+
JSON representation of the request. Use this if you are familiar with the Alexa request structure and rules and don't wish to use AlexToolbox's request handling.
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
request = AlexaToolbox::Request.new(json_request, {
|
178
|
+
:application_id => 'SKILL_APP_ID'
|
179
|
+
})
|
180
|
+
request_json = request.json
|
181
|
+
|
182
|
+
request.json[:version]
|
183
|
+
# "1.0"
|
184
|
+
```
|
185
|
+
|
186
|
+
##### .type
|
187
|
+
|
188
|
+
Return the type of request being made.
|
189
|
+
|
190
|
+
Possible Types:
|
191
|
+
LaunchRequest
|
192
|
+
IntentRequest
|
193
|
+
SessionEndedRequest
|
194
|
+
AudioPlayer
|
195
|
+
System.ExceptionEncountered
|
196
|
+
PlaybackController.NextCommandIssued
|
197
|
+
|
198
|
+
For AudioPlayer requests, it will return as "AudioPlayer" and not the full request type.
|
199
|
+
AudioPlayer requests will have an .audioplayer object
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
request = AlexaToolbox::Request.new(json_request, {
|
203
|
+
:application_id => 'SKILL_APP_ID'
|
204
|
+
})
|
205
|
+
request.type
|
206
|
+
# "IntentRequest"
|
207
|
+
```
|
208
|
+
|
209
|
+
##### .version
|
210
|
+
|
211
|
+
Return the version of the request (always "1.0" currently)
|
212
|
+
|
213
|
+
```ruby
|
214
|
+
request = AlexaToolbox::Request.new(json_request, {
|
215
|
+
:application_id => 'SKILL_APP_ID'
|
216
|
+
})
|
217
|
+
request.version
|
218
|
+
# "1.0"
|
219
|
+
```
|
220
|
+
|
221
|
+
##### .request_id
|
222
|
+
|
223
|
+
Return the requestId of the request
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
request = AlexaToolbox::Request.new(json_request, {
|
227
|
+
:application_id => 'SKILL_APP_ID'
|
228
|
+
})
|
229
|
+
request.request_id
|
230
|
+
# "EdwRequestId.d2fb326f-337d-4ca9-b99b-c308d7cbf8dd"
|
231
|
+
```
|
232
|
+
|
233
|
+
##### .locale
|
234
|
+
|
235
|
+
Return the locale of the request ("en-US","en-UK",etc.)
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
request = AlexaToolbox::Request.new(json_request, {
|
239
|
+
:application_id => 'SKILL_APP_ID'
|
240
|
+
})
|
241
|
+
request.locale
|
242
|
+
# "en-US"
|
243
|
+
```
|
244
|
+
|
245
|
+
##### .options
|
246
|
+
|
247
|
+
Read the options set for the request (this will house your application_id)
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
request = AlexaToolbox::Request.new(json_request, {
|
251
|
+
:application_id => 'SKILL_APP_ID'
|
252
|
+
})
|
253
|
+
request.options
|
254
|
+
# { :application_id => 'SKILL_APP_ID' }
|
255
|
+
```
|
256
|
+
|
257
|
+
##### .session
|
258
|
+
|
259
|
+
Access information on the session, view the session section for more information on the session object.
|
260
|
+
Is not included in AudioPlayer requests.
|
261
|
+
|
262
|
+
```ruby
|
263
|
+
request = AlexaToolbox::Request.new(json_request, {
|
264
|
+
:application_id => 'SKILL_APP_ID'
|
265
|
+
})
|
266
|
+
request.session
|
267
|
+
```
|
268
|
+
|
269
|
+
##### .intent
|
270
|
+
|
271
|
+
Access information on the intent, view the intent section for more information on the intent object.
|
272
|
+
Is only included for requests with type "IntentRequest".
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
request = AlexaToolbox::Request.new(json_request, {
|
276
|
+
:application_id => 'SKILL_APP_ID'
|
277
|
+
})
|
278
|
+
request.intent
|
279
|
+
```
|
280
|
+
|
281
|
+
##### .audioplayer
|
282
|
+
|
283
|
+
Access information on the audioplayer, view the audioplayer section for more information on the audioplayer object.
|
284
|
+
Is only included for requests with type "AudioPlayer".
|
285
|
+
|
286
|
+
```ruby
|
287
|
+
request = AlexaToolbox::Request.new(json_request, {
|
288
|
+
:application_id => 'SKILL_APP_ID'
|
289
|
+
})
|
290
|
+
request.audioplayer
|
291
|
+
```
|
292
|
+
|
293
|
+
##### .error
|
294
|
+
|
295
|
+
Access information for errors.
|
296
|
+
This is only included for requests with type "System.ExceptionEncountered" and "AudioPlayer".
|
297
|
+
error has two keys, :type and :message.
|
298
|
+
|
299
|
+
```ruby
|
300
|
+
request = AlexaToolbox::Request.new(json_request, {
|
301
|
+
:application_id => 'SKILL_APP_ID'
|
302
|
+
})
|
303
|
+
request.error
|
304
|
+
# { :type => "MEDIA_ERROR_INVALID_REQUEST", :message => "Alexa recognized the request as being malformed. E.g. bad request, unauthorized, forbidden, not found, etc." }
|
305
|
+
```
|
306
|
+
|
307
|
+
##### .cause
|
308
|
+
|
309
|
+
Access information for error cause.
|
310
|
+
This is only included for requests with type "System.ExceptionEncountered".
|
311
|
+
cause has one keys, :requestId.
|
312
|
+
|
313
|
+
```ruby
|
314
|
+
request = AlexaToolbox::Request.new(json_request, {
|
315
|
+
:application_id => 'SKILL_APP_ID'
|
316
|
+
})
|
317
|
+
request.cause
|
318
|
+
# { :requestId => "EdwRequestId.d2b326f-37d-4a9-b9b-c307cbf8d" }
|
319
|
+
```
|
320
|
+
|
321
|
+
##### .context
|
322
|
+
|
323
|
+
Access context information for the request, not always provided and may be phased out for most request types.
|
324
|
+
|
325
|
+
```ruby
|
326
|
+
request = AlexaToolbox::Request.new(json_request, {
|
327
|
+
:application_id => 'SKILL_APP_ID'
|
328
|
+
})
|
329
|
+
request.context
|
330
|
+
```
|
331
|
+
|
332
|
+
|
333
|
+
### Session
|
334
|
+
|
335
|
+
### Intent
|
336
|
+
|
337
|
+
### Audioplayer
|
338
|
+
|
339
|
+
### Context
|
340
|
+
|
341
|
+
### Request
|
342
|
+
|
343
|
+
### Address
|
344
|
+
|
154
345
|
|
155
346
|
## Troubleshooting
|
156
347
|
|
@@ -6,7 +6,6 @@ module AlexaToolbox
|
|
6
6
|
|
7
7
|
class Request
|
8
8
|
require 'json'
|
9
|
-
require 'deep_merge'
|
10
9
|
require 'alexa_toolbox/session'
|
11
10
|
require 'alexa_toolbox/intent'
|
12
11
|
require 'alexa_toolbox/audioplayer'
|
@@ -20,8 +19,7 @@ module AlexaToolbox
|
|
20
19
|
end
|
21
20
|
|
22
21
|
def initialize(json_request, options = {})
|
23
|
-
options = options.
|
24
|
-
@options = options
|
22
|
+
@options = options if options.key?(:application_id)
|
25
23
|
|
26
24
|
@request_id = json_request[:request][:requestId]
|
27
25
|
raise ArgumentError, 'Request ID not present' if @request_id.nil?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alexa_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul McMahon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: deep_merge
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rspec
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|