ralyxa 1.6.2 → 1.7.0
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/.gitignore +2 -1
- data/.rubocop.yml +3 -0
- data/CONTRIBUTING.md +19 -0
- data/README.md +67 -2
- data/lib/ralyxa/configuration.rb +6 -1
- data/lib/ralyxa/errors.rb +3 -1
- data/lib/ralyxa/handler.rb +12 -1
- data/lib/ralyxa/request_entities/request.rb +9 -3
- data/lib/ralyxa/request_entities/user.rb +4 -2
- data/lib/ralyxa/response_builder.rb +5 -1
- data/lib/ralyxa/response_entities/card.rb +27 -10
- data/lib/ralyxa/response_entities/directives/audio/audio_item.rb +23 -0
- data/lib/ralyxa/response_entities/directives/audio/stream.rb +37 -0
- data/lib/ralyxa/response_entities/directives/audio.rb +11 -0
- data/lib/ralyxa/response_entities/directives/audio_player/clear_queue.rb +27 -0
- data/lib/ralyxa/response_entities/directives/audio_player/play.rb +32 -0
- data/lib/ralyxa/response_entities/directives/audio_player/stop.rb +19 -0
- data/lib/ralyxa/response_entities/directives/audio_player.rb +46 -0
- data/lib/ralyxa/response_entities/directives.rb +9 -0
- data/lib/ralyxa/response_entities/response.rb +11 -7
- data/lib/ralyxa/version.rb +1 -1
- data/ralyxa.gemspec +1 -0
- metadata +26 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2097ed5c0dd85b2f0f5d04d0f6c524b9cc90b8b
|
4
|
+
data.tar.gz: 004060b9f538e547270050bcab4a584bd243ef02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec37369ea357d04fbde3353ae06b12407eb34282b466a3895ace4a0276f9c0a63ee05c4359436141ec02db1aca8b9e40a0dfa8a9030767c851032a5075c48008
|
7
|
+
data.tar.gz: 840cf253a18ff2a3e552ea359a7ed15e9a120f869c0cf93020286394add6b86cee9d98f054f404abf83ee3c84eb73dc29b9685f41854442335d5445fcfa1758d
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Contributing to Ralyxa
|
2
|
+
|
3
|
+
1. Have tests.
|
4
|
+
|
5
|
+
## The basic idea
|
6
|
+
|
7
|
+
Ralyxa is in two parts:
|
8
|
+
|
9
|
+
1. The user-facing Ruby interface which looks a bit like Sinatra.
|
10
|
+
2. The under-the-hood Ruby-to-JSON translator which directly references Alexa structures.
|
11
|
+
|
12
|
+
This gives rise to some principles:
|
13
|
+
|
14
|
+
1. The user-facing Ruby interface should try to provide thoughtful abstractions to the Alexa structures.
|
15
|
+
2. The under-the-hood Ruby-to-JSON translator should contain objects which directly map onto Alexa structures.
|
16
|
+
|
17
|
+
Some other principles:
|
18
|
+
|
19
|
+
1. Keep the user-facing Ruby interface as simple as possible. Imagine a brand-new Ruby developer using this.
|
data/README.md
CHANGED
@@ -93,6 +93,55 @@ intent "ReadFromSession" do
|
|
93
93
|
end
|
94
94
|
```
|
95
95
|
|
96
|
+
##### Playing audio with the `AudioPlayer` directive
|
97
|
+
|
98
|
+
###### Play
|
99
|
+
|
100
|
+
You can play an audio stream right away with:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
intent "PlayAudio" do
|
104
|
+
audio_player.play(
|
105
|
+
'https://s3.amazonaws.com/my-ssml-samples/Flourish.mp3',
|
106
|
+
'flourish-token',
|
107
|
+
speech: 'Playing Audio'
|
108
|
+
)
|
109
|
+
end
|
110
|
+
```
|
111
|
+
|
112
|
+
###### Play Later (Enqueue)
|
113
|
+
|
114
|
+
You can queue a song to play next with:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
intent "PlayAudioLater" do
|
118
|
+
audio_player.play_later(
|
119
|
+
'https://s3.amazonaws.com/my-ssml-samples/Flourish.mp3',
|
120
|
+
'flourish-token'
|
121
|
+
)
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
###### Stop
|
126
|
+
|
127
|
+
You can stop playing with:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
intent "StopAudio" do
|
131
|
+
audio_player.stop
|
132
|
+
end
|
133
|
+
```
|
134
|
+
|
135
|
+
###### Clear Queued
|
136
|
+
|
137
|
+
You can clear enqueued audio with:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
intent "ClearQueue" do
|
141
|
+
audio_player.clear_queue
|
142
|
+
end
|
143
|
+
```
|
144
|
+
|
96
145
|
##### Reading the session user
|
97
146
|
|
98
147
|
You can read the session user's `userId` and `accessToken`, and check that the `accessToken` exists:
|
@@ -148,7 +197,8 @@ end
|
|
148
197
|
|
149
198
|
# Standard card
|
150
199
|
intent "SendStandardCard" do
|
151
|
-
standard_card = card("Hello World", "I'm alive!", "
|
200
|
+
standard_card = card("Hello World", "I'm alive!", "http://placehold.it/720x480", "http://placehold.it/1200x800")
|
201
|
+
|
152
202
|
ask("What do you think of the Standard card I just sent?", card: standard_card)
|
153
203
|
end
|
154
204
|
```
|
@@ -190,6 +240,20 @@ end
|
|
190
240
|
|
191
241
|
> You can't actually respond to a `SessionEndedRequest`, but you might want to do some tidying in this action.
|
192
242
|
|
243
|
+
|
244
|
+
### I want to serve card images, audio stream etc. over HTTP not HTTPS
|
245
|
+
|
246
|
+
In some special cases, you may be allowed to serve content over HTTP instead of HTTPS. To allow this within Ralyxa, you need to set the `require_secure_urls` configuration option to false.
|
247
|
+
|
248
|
+
> **NOTE:** In order to use HTTP sources, you must be given special approval directly from Amazon. If you use HTTP sources without getting advanced approval, your skill will not work correctly.
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
Ralyxa.configure do |config|
|
252
|
+
config.require_secure_urls = false
|
253
|
+
end
|
254
|
+
```
|
255
|
+
|
256
|
+
|
193
257
|
## Testing
|
194
258
|
Part of Amazon's requirements for Alexa skills is that they have to ensure requests are sent from Amazon. This is done in a number of ways documented [here](https://developer.amazon.com/docs/custom-skills/host-a-custom-skill-as-a-web-service.html). This verification is built into Ralyxa and can cause issues when testing your skills with stubbed data.
|
195
259
|
|
@@ -219,9 +283,10 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/sjmog/
|
|
219
283
|
|
220
284
|
The main areas of focus are:
|
221
285
|
|
222
|
-
- Audio directives :construction:
|
223
286
|
- Reprompts :construction:
|
287
|
+
- Dialogue :construction:
|
224
288
|
- Generators of built-in Intents e.g. `SessionEndedRequest`
|
289
|
+
- Automation with the `AVS` command line tool
|
225
290
|
|
226
291
|
## License
|
227
292
|
|
data/lib/ralyxa/configuration.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
module Ralyxa
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :validate_requests
|
3
|
+
attr_accessor :validate_requests, :require_secure_urls
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@validate_requests = true
|
7
|
+
@require_secure_urls = true
|
7
8
|
end
|
8
9
|
|
9
10
|
def validate_requests?
|
10
11
|
validate_requests
|
11
12
|
end
|
13
|
+
|
14
|
+
def require_secure_urls?
|
15
|
+
require_secure_urls
|
16
|
+
end
|
12
17
|
end
|
13
18
|
end
|
data/lib/ralyxa/errors.rb
CHANGED
data/lib/ralyxa/handler.rb
CHANGED
@@ -13,7 +13,10 @@ module Ralyxa
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def respond(response_text = '', response_details = {}, response_builder = Ralyxa::ResponseBuilder)
|
16
|
-
|
16
|
+
options = response_details
|
17
|
+
options[:response_text] = response_text if response_text
|
18
|
+
|
19
|
+
response_builder.build(options)
|
17
20
|
end
|
18
21
|
|
19
22
|
def tell(response_text = '', response_details = {})
|
@@ -24,10 +27,18 @@ module Ralyxa
|
|
24
27
|
card_class.as_hash(title, body, image_url)
|
25
28
|
end
|
26
29
|
|
30
|
+
def audio_player
|
31
|
+
Ralyxa::ResponseEntities::Directives::AudioPlayer
|
32
|
+
end
|
33
|
+
|
27
34
|
def link_account_card(card_class = Ralyxa::ResponseEntities::Card)
|
28
35
|
card_class.link_account
|
29
36
|
end
|
30
37
|
|
38
|
+
def log(level, message)
|
39
|
+
puts "[#{Time.new}] [#{@request.user_id}] #{level} - #{message}"
|
40
|
+
end
|
41
|
+
|
31
42
|
alias ask respond
|
32
43
|
|
33
44
|
attr_reader :request
|
@@ -13,13 +13,15 @@ module Ralyxa
|
|
13
13
|
def_delegator :@user, :access_token, :user_access_token
|
14
14
|
def_delegator :@user, :access_token_exists?, :user_access_token_exists?
|
15
15
|
|
16
|
+
attr_reader :request
|
17
|
+
|
16
18
|
def initialize(original_request, user_class = Ralyxa::RequestEntities::User)
|
19
|
+
validate_request(original_request) if Ralyxa.configuration.validate_requests?
|
20
|
+
|
17
21
|
@request = JSON.parse(original_request.body.read)
|
18
22
|
attempt_to_rewind_request_body(original_request)
|
19
23
|
|
20
24
|
@user = user_class.build(@request)
|
21
|
-
|
22
|
-
validate_request(original_request) if Ralyxa.configuration.validate_requests?
|
23
25
|
end
|
24
26
|
|
25
27
|
def intent_name
|
@@ -35,8 +37,12 @@ module Ralyxa
|
|
35
37
|
@request['session']['new']
|
36
38
|
end
|
37
39
|
|
40
|
+
def session_attributes
|
41
|
+
@request['session']['attributes']
|
42
|
+
end
|
43
|
+
|
38
44
|
def session_attribute(attribute_name)
|
39
|
-
|
45
|
+
session_attributes[attribute_name]
|
40
46
|
end
|
41
47
|
|
42
48
|
private
|
@@ -9,9 +9,11 @@ module Ralyxa
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.build(request)
|
12
|
+
user_hash = request.dig('session', 'user') || request.dig('context', 'System', 'user') || {}
|
13
|
+
|
12
14
|
new(
|
13
|
-
id:
|
14
|
-
access_token:
|
15
|
+
id: user_hash['userId'],
|
16
|
+
access_token: user_hash['accessToken']
|
15
17
|
)
|
16
18
|
end
|
17
19
|
|
@@ -14,7 +14,7 @@ module Ralyxa
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def build
|
17
|
-
merge_output_speech
|
17
|
+
merge_output_speech if response_text_exists?
|
18
18
|
merge_card if card_exists?
|
19
19
|
|
20
20
|
@response_class.as_hash(@options).to_json
|
@@ -34,6 +34,10 @@ module Ralyxa
|
|
34
34
|
@options[:card]
|
35
35
|
end
|
36
36
|
|
37
|
+
def response_text_exists?
|
38
|
+
@options[:response_text]
|
39
|
+
end
|
40
|
+
|
37
41
|
def output_speech
|
38
42
|
output_speech_params = { speech: @options.delete(:response_text) }
|
39
43
|
output_speech_params[:ssml] = @options.delete(:ssml) if @options[:ssml]
|
@@ -11,8 +11,8 @@ module Ralyxa
|
|
11
11
|
@options = options
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.as_hash(title, body,
|
15
|
-
new(title: title, body: body,
|
14
|
+
def self.as_hash(title, body, small_image_url = nil, large_image_url = small_image_url)
|
15
|
+
new(title: title, body: body, small_image_url: small_image_url, large_image_url: large_image_url).to_h
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.link_account
|
@@ -24,7 +24,7 @@ module Ralyxa
|
|
24
24
|
add_type(card)
|
25
25
|
add_title(card) if @options[:title]
|
26
26
|
add_body(card) if @options[:body]
|
27
|
-
add_image(card) if
|
27
|
+
add_image(card) if standard?
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -46,10 +46,14 @@ module Ralyxa
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def add_image(card)
|
49
|
-
raise UnsecureUrlError, "Card images must be available at an SSL-enabled (HTTPS) endpoint. Your current image
|
49
|
+
raise Ralyxa::UnsecureUrlError, "Card images must be available at an SSL-enabled (HTTPS) endpoint. Your current image urls are: (small: #{@options[:small_image_url]}, large: #{@options[:large_image_url]}" unless secure_images?
|
50
50
|
card[:image] = {}
|
51
|
-
|
52
|
-
|
51
|
+
|
52
|
+
small_image = @options[:small_image_url] || @options[:large_image_url]
|
53
|
+
large_image = @options[:large_image_url] || @options[:small_image_url]
|
54
|
+
|
55
|
+
card[:image][:smallImageUrl] = small_image if small_image
|
56
|
+
card[:image][:largeImageUrl] = large_image if large_image
|
53
57
|
end
|
54
58
|
|
55
59
|
def link_account?
|
@@ -57,15 +61,28 @@ module Ralyxa
|
|
57
61
|
end
|
58
62
|
|
59
63
|
def simple?
|
60
|
-
!@options[:
|
64
|
+
!@options[:small_image_url] && !@options[:large_image_url]
|
61
65
|
end
|
62
66
|
|
63
67
|
def standard?
|
64
|
-
|
68
|
+
@options[:small_image_url] || @options[:large_image_url]
|
69
|
+
end
|
70
|
+
|
71
|
+
def secure_images?
|
72
|
+
small_secure = secure_uri?(@options[:small_image_url])
|
73
|
+
large_secure = secure_uri?(@options[:large_image_url])
|
74
|
+
|
75
|
+
small_secure && large_secure
|
65
76
|
end
|
66
77
|
|
67
|
-
|
68
|
-
|
78
|
+
# Given a uri string, retutrn true if:
|
79
|
+
# * the scheme is https
|
80
|
+
# * or if we are not interested in the uri being secure
|
81
|
+
# * or if the value that has been passed is nil
|
82
|
+
def secure_uri?(uri_string)
|
83
|
+
return true if uri_string.nil?
|
84
|
+
|
85
|
+
(URI.parse(uri_string).scheme == 'https' || !Ralyxa.require_secure_urls?)
|
69
86
|
end
|
70
87
|
end
|
71
88
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Ralyxa
|
2
|
+
module ResponseEntities
|
3
|
+
module Directives
|
4
|
+
module Audio
|
5
|
+
class AudioItem
|
6
|
+
def initialize(stream)
|
7
|
+
@stream = stream
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_h
|
11
|
+
{}.tap do |audio_item|
|
12
|
+
audio_item['stream'] = @stream.to_h
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.as_hash(stream)
|
17
|
+
new(stream).to_h
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Ralyxa
|
2
|
+
module ResponseEntities
|
3
|
+
module Directives
|
4
|
+
module Audio
|
5
|
+
class Stream
|
6
|
+
def initialize(url, token, offset_in_milliseconds = 0, expected_previous_token = nil)
|
7
|
+
raise Ralyxa::UnsecureUrlError, "Audio streams must be served from at an SSL-enabled (HTTPS) endpoint. Your current stream url is: #{url}" unless secure?(url)
|
8
|
+
|
9
|
+
@url = url
|
10
|
+
@token = token
|
11
|
+
@offset_in_milliseconds = offset_in_milliseconds
|
12
|
+
@expected_previous_token = expected_previous_token
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_h
|
16
|
+
{}.tap do |stream|
|
17
|
+
stream['url'] = @url
|
18
|
+
stream['token'] = @token
|
19
|
+
stream['offsetInMilliseconds'] = @offset_in_milliseconds
|
20
|
+
stream['expectedPreviousToken'] = @expected_previous_token if @expected_previous_token
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.as_hash(url, token, offset_in_milliseconds = 0, expected_previous_token = nil)
|
25
|
+
new(url, token, offset_in_milliseconds, expected_previous_token).to_h
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def secure?(url)
|
31
|
+
URI.parse(url).scheme == 'https' || !Ralyxa.require_secure_urls?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Ralyxa
|
2
|
+
module ResponseEntities
|
3
|
+
module Directives
|
4
|
+
class AudioPlayer
|
5
|
+
class ClearQueue
|
6
|
+
CLEAR_ENQUEUED = 'CLEAR_ENQUEUED'.freeze
|
7
|
+
CLEAR_ALL = 'CLEAR_ALL'.freeze
|
8
|
+
|
9
|
+
def initialize(behaviour = Ralyxa::ResponseEntities::Directives::AudioPlayer::ClearQueue::CLEAR_ENQUEUED)
|
10
|
+
@behaviour = behaviour
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_h
|
14
|
+
{}.tap do |audio_player|
|
15
|
+
audio_player['type'] = 'AudioPlayer.ClearQueue'
|
16
|
+
audio_player['clearBehavior'] = @behaviour
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.as_hash(behaviour = Ralyxa::ResponseEntities::Directives::AudioPlayer::ClearQueue::CLEAR_ENQUEUED)
|
21
|
+
new(behaviour).to_h
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Ralyxa
|
2
|
+
module ResponseEntities
|
3
|
+
module Directives
|
4
|
+
class AudioPlayer
|
5
|
+
class Play
|
6
|
+
CLEAR_ENQUEUE = 'CLEAR_ENQUEUE'.freeze
|
7
|
+
ENQUEUE = 'ENQUEUE'.freeze
|
8
|
+
REPLACE_ALL = 'REPLACE_ALL'.freeze
|
9
|
+
REPLACE_ENQUEUED = 'REPLACE_ENQUEUED'.freeze
|
10
|
+
|
11
|
+
def initialize(stream, behaviour = Ralyxa::ResponseEntities::Directives::AudioPlayer::Play::REPLACE_ALL)
|
12
|
+
@stream = stream
|
13
|
+
@behaviour = behaviour
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_h
|
17
|
+
{}.tap do |audio_player|
|
18
|
+
audio_player['type'] = 'AudioPlayer.Play'
|
19
|
+
audio_player['playBehavior'] = @behaviour
|
20
|
+
|
21
|
+
audio_player['audioItem'] = Ralyxa::ResponseEntities::Directives::Audio::AudioItem.new(@stream).to_h
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.as_hash(stream, behaviour = nil)
|
26
|
+
new(stream, behaviour).to_h
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Ralyxa
|
2
|
+
module ResponseEntities
|
3
|
+
module Directives
|
4
|
+
class AudioPlayer
|
5
|
+
class Stop
|
6
|
+
def to_h
|
7
|
+
{}.tap do |audio_player|
|
8
|
+
audio_player['type'] = 'AudioPlayer.Stop'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.as_hash
|
13
|
+
new.to_h
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative './audio_player/clear_queue'
|
2
|
+
require_relative './audio_player/play'
|
3
|
+
require_relative './audio_player/stop'
|
4
|
+
|
5
|
+
module Ralyxa
|
6
|
+
module ResponseEntities
|
7
|
+
module Directives
|
8
|
+
class AudioPlayer
|
9
|
+
class << self
|
10
|
+
def play(url, token, speech: nil, card: nil, offset_in_milliseconds: 0, expected_previous_token: nil, behaviour: Ralyxa::ResponseEntities::Directives::AudioPlayer::Play::REPLACE_ALL, audio_player_class: Ralyxa::ResponseEntities::Directives::AudioPlayer::Play, response_builder: Ralyxa::ResponseBuilder)
|
11
|
+
directive = audio_player_class.as_hash(Ralyxa::ResponseEntities::Directives::Audio::Stream.new(url, token, offset_in_milliseconds, expected_previous_token), behaviour)
|
12
|
+
|
13
|
+
response_builder.build(build_options(directive, speech, card))
|
14
|
+
end
|
15
|
+
|
16
|
+
def play_later(url, token, speech: nil, card: nil, offset_in_milliseconds: 0, expected_previous_token: nil, behaviour: Ralyxa::ResponseEntities::Directives::AudioPlayer::Play::REPLACE_ENQUEUED, audio_player_class: Ralyxa::ResponseEntities::Directives::AudioPlayer::Play, response_builder: Ralyxa::ResponseBuilder)
|
17
|
+
play(url, token, speech: speech, card: card, offset_in_milliseconds: offset_in_milliseconds, expected_previous_token: expected_previous_token, behaviour: behaviour, audio_player_class: audio_player_class, response_builder: response_builder)
|
18
|
+
end
|
19
|
+
|
20
|
+
def stop(speech: nil, card: nil, audio_player_class: Ralyxa::ResponseEntities::Directives::AudioPlayer::Stop, response_builder: Ralyxa::ResponseBuilder)
|
21
|
+
directive = audio_player_class.as_hash
|
22
|
+
|
23
|
+
response_builder.build(build_options(directive, speech, card))
|
24
|
+
end
|
25
|
+
|
26
|
+
def clear_queue(speech: nil, card: nil, behaviour: Ralyxa::ResponseEntities::Directives::AudioPlayer::ClearQueue::CLEAR_ALL, audio_player_class: Ralyxa::ResponseEntities::Directives::AudioPlayer::ClearQueue, response_builder: Ralyxa::ResponseBuilder)
|
27
|
+
directive = audio_player_class.as_hash(behaviour)
|
28
|
+
|
29
|
+
response_builder.build(build_options(directive, speech, card))
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def build_options(directive, speech, card)
|
35
|
+
{}.tap do |option|
|
36
|
+
option[:directives] = [directive]
|
37
|
+
option[:end_session] = false
|
38
|
+
option[:response_text] = speech if speech
|
39
|
+
option[:card] = card if card
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require_relative './output_speech'
|
2
|
+
require_relative './directives'
|
2
3
|
|
3
4
|
module Ralyxa
|
4
5
|
module ResponseEntities
|
5
6
|
class Response
|
6
|
-
def initialize(output_speech, session_attributes, end_session, start_over, card)
|
7
|
+
def initialize(output_speech, session_attributes, end_session, start_over, card, directives)
|
7
8
|
@output_speech = output_speech
|
8
9
|
@session_attributes = session_attributes
|
9
10
|
@end_session = end_session
|
10
11
|
@start_over = start_over
|
11
12
|
@card = card
|
13
|
+
@directives = directives
|
12
14
|
end
|
13
15
|
|
14
16
|
def to_h
|
@@ -19,8 +21,8 @@ module Ralyxa
|
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
|
-
def self.as_hash(output_speech:
|
23
|
-
new(output_speech, session_attributes, end_session, start_over, card).to_h
|
24
|
+
def self.as_hash(output_speech: false, session_attributes: {}, end_session: false, start_over: false, card: false, directives: false)
|
25
|
+
new(output_speech, session_attributes, end_session, start_over, card, directives).to_h
|
24
26
|
end
|
25
27
|
|
26
28
|
private
|
@@ -37,10 +39,12 @@ module Ralyxa
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def add_response(response)
|
40
|
-
response[:response] = {}
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
response[:response] = {}.tap do |response_object|
|
43
|
+
response_object[:outputSpeech] = @output_speech if @output_speech
|
44
|
+
response_object[:card] = @card if @card
|
45
|
+
response_object[:directives] = @directives if @directives
|
46
|
+
response_object[:shouldEndSession] = @end_session
|
47
|
+
end
|
44
48
|
end
|
45
49
|
end
|
46
50
|
end
|
data/lib/ralyxa/version.rb
CHANGED
data/ralyxa.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ralyxa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: alexa_verifier
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.15'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.15'
|
111
125
|
description: A Ruby framework for interacting with Amazon Alexa. Designed to work
|
112
126
|
with Sinatra, although can be used with a few other web frameworks.
|
113
127
|
email:
|
@@ -122,6 +136,7 @@ files:
|
|
122
136
|
- ".ruby-version"
|
123
137
|
- ".travis.yml"
|
124
138
|
- CODE_OF_CONDUCT.md
|
139
|
+
- CONTRIBUTING.md
|
125
140
|
- Gemfile
|
126
141
|
- LICENSE.txt
|
127
142
|
- README.md
|
@@ -137,6 +152,14 @@ files:
|
|
137
152
|
- lib/ralyxa/request_entities/user.rb
|
138
153
|
- lib/ralyxa/response_builder.rb
|
139
154
|
- lib/ralyxa/response_entities/card.rb
|
155
|
+
- lib/ralyxa/response_entities/directives.rb
|
156
|
+
- lib/ralyxa/response_entities/directives/audio.rb
|
157
|
+
- lib/ralyxa/response_entities/directives/audio/audio_item.rb
|
158
|
+
- lib/ralyxa/response_entities/directives/audio/stream.rb
|
159
|
+
- lib/ralyxa/response_entities/directives/audio_player.rb
|
160
|
+
- lib/ralyxa/response_entities/directives/audio_player/clear_queue.rb
|
161
|
+
- lib/ralyxa/response_entities/directives/audio_player/play.rb
|
162
|
+
- lib/ralyxa/response_entities/directives/audio_player/stop.rb
|
140
163
|
- lib/ralyxa/response_entities/output_speech.rb
|
141
164
|
- lib/ralyxa/response_entities/response.rb
|
142
165
|
- lib/ralyxa/skill.rb
|
@@ -163,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
186
|
version: '0'
|
164
187
|
requirements: []
|
165
188
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.6.
|
189
|
+
rubygems_version: 2.6.10
|
167
190
|
signing_key:
|
168
191
|
specification_version: 4
|
169
192
|
summary: A Ruby framework for interacting with Amazon Alexa.
|