alexa_ruby 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f50f6b0d5edcf02161fa117fb7bbef6b4d0f5bb2
4
- data.tar.gz: bf10e598ff42213da48f2d3895d7a6d45dbafa74
3
+ metadata.gz: 81b1c1d716759449c12046344b3cd8fc75a39063
4
+ data.tar.gz: ad89af2cee60262bdb2f00c2283113fd575a1a20
5
5
  SHA512:
6
- metadata.gz: 404a9c0de4e59bbef6ec9f4f7e73383f2cb039ca62ce1ccfd2e9a6de05de6384ca0d46406e03df25ad78ea0a330fac0b1ced706c79d2f89d19f0f9bc5d981ce1
7
- data.tar.gz: e74a94a45a662f5c9ae2b6d141da4b86b285a29c0707a4333c8ae329e7cc9b8284d37337cf9c80fa6dd24fe532b06ea7fdca4f3c192f34decfdd1f2cbba540bb
6
+ metadata.gz: 9282ec9d6a7fe0a36e0121da659d3dbfe17eaff4f4a9f961d2b05190c1eb92cab63e73f886ce613ec2596d935caf334c55f50f5bfd696ca27b2d9159c073e6fc
7
+ data.tar.gz: 5b508751a1daafd887f0f29b33b9915b3aa3372386b82e11c699667fc1384737c38748d5b60980d777819ef1259e1a12d03db4e887ca954ad9a5515e69e59223
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in alexa_rubykit.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- alexa_ruby (1.0.0)
4
+ alexa_ruby (1.0.3)
5
5
  bundler (>= 1.6.9)
6
6
  oj (~> 3.0)
7
7
  rake
@@ -11,8 +11,12 @@ GEM
11
11
  specs:
12
12
  ansi (1.5.0)
13
13
  builder (3.2.3)
14
- codeclimate-test-reporter (1.0.8)
15
- simplecov (<= 0.13)
14
+ coveralls (0.8.21)
15
+ json (>= 1.8, < 3)
16
+ simplecov (~> 0.14.1)
17
+ term-ansicolor (~> 1.3)
18
+ thor (~> 0.19.4)
19
+ tins (~> 1.6)
16
20
  docile (1.1.5)
17
21
  json (2.1.0)
18
22
  minitest (5.10.2)
@@ -24,21 +28,24 @@ GEM
24
28
  oj (3.0.10)
25
29
  rake (12.0.0)
26
30
  ruby-progressbar (1.8.1)
27
- simplecov (0.13.0)
31
+ simplecov (0.14.1)
28
32
  docile (~> 1.1.0)
29
33
  json (>= 1.8, < 3)
30
34
  simplecov-html (~> 0.10.0)
31
35
  simplecov-html (0.10.1)
36
+ term-ansicolor (1.6.0)
37
+ tins (~> 1.0)
38
+ thor (0.19.4)
39
+ tins (1.14.0)
32
40
 
33
41
  PLATFORMS
34
42
  ruby
35
43
 
36
44
  DEPENDENCIES
37
45
  alexa_ruby!
38
- codeclimate-test-reporter (~> 1.0.0)
46
+ coveralls
39
47
  minitest (~> 5.10, >= 5.10.2)
40
48
  minitest-reporters (~> 1.1, >= 1.1.14)
41
- simplecov
42
49
 
43
50
  BUNDLED WITH
44
51
  1.15.0
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/alexa_ruby.svg)](https://badge.fury.io/rb/alexa_ruby)
4
4
  [![Build Status](https://travis-ci.org/mulev/alexa-ruby.svg?branch=master)](https://travis-ci.org/mulev/alexa-ruby)
5
5
  [![Code Climate](https://codeclimate.com/github/mulev/alexa-ruby/badges/gpa.svg)](https://codeclimate.com/github/mulev/alexa-ruby)
6
+ [![Coverage Status](https://coveralls.io/repos/github/mulev/alexa-ruby/badge.svg?branch=develop)](https://coveralls.io/github/mulev/alexa-ruby?branch=develop)
6
7
 
7
8
  Originally forked from [damianFC's AlexaRubykit](https://github.com/damianFC/alexa-rubykit), this gem implements a convenient back-end service for interaction with Amazon Alexa API.
8
9
 
@@ -8,8 +8,13 @@ module AlexaRuby
8
8
  # token [String] streaming service token
9
9
  # offset [Integer] playback offset
10
10
  # @return [Hash] AudioPlayer.Play directive
11
+ # @raise [ArgumentError] if audio URL isn't valid
11
12
  def play_directive(params)
12
13
  url = params[:url]
14
+ if invalid_url?(url)
15
+ raise ArgumentError, 'Audio URL must be a valid ' \
16
+ 'SSL-enabled (HTTPS) endpoint'
17
+ end
13
18
  token = params[:token] || SecureRandom.uuid
14
19
  offset = params[:offset] || 0
15
20
  build_directive('AudioPlayer.Play', url, token, offset)
@@ -40,5 +45,13 @@ module AlexaRuby
40
45
  directive[:audioItem][:stream][:offsetInMilliseconds] = offset
41
46
  directive
42
47
  end
48
+
49
+ # Check if given URL isn't an SSL-enabled endpoint
50
+ #
51
+ # @param url [String] some URL
52
+ # @return [Boolean]
53
+ def invalid_url?(url)
54
+ URI.parse(url).scheme != 'https'
55
+ end
43
56
  end
44
57
  end
@@ -70,11 +70,32 @@ module AlexaRuby
70
70
  @obj[:image] = {}
71
71
 
72
72
  if @params[:small_image_url]
73
- @obj[:image][:smallImageUrl] = @params[:small_image_url]
73
+ add_image(:smallImageUrl, @params[:small_image_url])
74
74
  end
75
75
 
76
76
  return unless @params[:large_image_url]
77
- @obj[:image][:largeImageUrl] = @params[:large_image_url]
77
+ add_image(:largeImageUrl, @params[:large_image_url])
78
+ end
79
+
80
+ # Add image to object
81
+ #
82
+ # @param type [Symbol] image type
83
+ # @param image_url [String] image URL
84
+ # @raise [ArgumentError] if card URL doesn't starts with HTTPS
85
+ def add_image(type, image_url)
86
+ if invalid_url?(image_url)
87
+ raise ArgumentError, 'Card image URL must be a valid ' \
88
+ 'SSL-enabled (HTTPS) endpoint'
89
+ end
90
+ @obj[:image][type] = image_url
91
+ end
92
+
93
+ # Check if given URL isn't an SSL-enabled endpoint
94
+ #
95
+ # @param url [String] some URL
96
+ # @return [Boolean]
97
+ def invalid_url?(url)
98
+ URI.parse(url).scheme != 'https'
78
99
  end
79
100
  end
80
101
  end
@@ -59,7 +59,7 @@ module AlexaRuby
59
59
  # content [String] card content (line breaks must be already included)
60
60
  # small_image_url [String] an URL for small card image
61
61
  # large_image_url [String] an URL for large card image
62
- # @raise [NoMethodError] if card is not allowed
62
+ # @raise [ArgumentError] if card is not allowed
63
63
  def add_card(params = {})
64
64
  card_exception unless %i[launch intent].include? @req_type
65
65
  card = Card.new(params)
@@ -195,9 +195,9 @@ module AlexaRuby
195
195
 
196
196
  # Raise card exception
197
197
  #
198
- # @raise [NoMethodError] if card is not allowed
198
+ # @raise [ArgumentError] if card is not allowed
199
199
  def card_exception
200
- raise NoMethodError, 'Card can only be included in response ' \
200
+ raise ArgumentError, 'Card can only be included in response ' \
201
201
  'to a "LaunchRequest" or "IntentRequest"'
202
202
  end
203
203
  end
@@ -1,3 +1,3 @@
1
1
  module AlexaRuby
2
- VERSION = '1.0.3'.freeze
2
+ VERSION = '1.0.4'.freeze
3
3
  end
data/lib/alexa_ruby.rb CHANGED
@@ -14,7 +14,7 @@ require 'alexa_ruby/request/launch_request'
14
14
  require 'alexa_ruby/request/intent_request'
15
15
  require 'alexa_ruby/request/intent_request/slot'
16
16
  require 'alexa_ruby/request/session_ended_request'
17
- require 'alexa_ruby/response'
17
+ require 'alexa_ruby/response/response'
18
18
  require 'alexa_ruby/response/audio_player'
19
19
  require 'alexa_ruby/response/card'
20
20
  require 'alexa_ruby/version'
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,8 @@
1
- require 'simplecov'
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
2
4
  require 'minitest/autorun'
3
5
  require 'minitest/reporters'
4
6
  require 'alexa_ruby'
5
7
 
6
8
  Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new(color: true)
7
- SimpleCov.start
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexa_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Mulev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-31 00:00:00.000000000 Z
11
+ date: 2017-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,34 +92,6 @@ dependencies:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: 1.1.14
95
- - !ruby/object:Gem::Dependency
96
- name: simplecov
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- version: '0'
109
- - !ruby/object:Gem::Dependency
110
- name: codeclimate-test-reporter
111
- requirement: !ruby/object:Gem::Requirement
112
- requirements:
113
- - - "~>"
114
- - !ruby/object:Gem::Version
115
- version: 1.0.0
116
- type: :development
117
- prerelease: false
118
- version_requirements: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - "~>"
121
- - !ruby/object:Gem::Version
122
- version: 1.0.0
123
95
  description: Ruby toolkit for Amazon Alexa API
124
96
  email:
125
97
  - m.mulev@gmail.com
@@ -144,12 +116,10 @@ files:
144
116
  - lib/alexa_ruby/request/intent_request/slot.rb
145
117
  - lib/alexa_ruby/request/launch_request.rb
146
118
  - lib/alexa_ruby/request/session_ended_request.rb
147
- - lib/alexa_ruby/response.rb
148
119
  - lib/alexa_ruby/response/audio_player.rb
149
120
  - lib/alexa_ruby/response/card.rb
121
+ - lib/alexa_ruby/response/response.rb
150
122
  - lib/alexa_ruby/version.rb
151
- - spec/request_spec.rb
152
- - spec/response_spec.rb
153
123
  - spec/spec_helper.rb
154
124
  homepage: https://github.com/mulev/alexa-ruby
155
125
  licenses:
@@ -171,11 +141,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
141
  version: '0'
172
142
  requirements: []
173
143
  rubyforge_project:
174
- rubygems_version: 2.2.2
144
+ rubygems_version: 2.6.12
175
145
  signing_key:
176
146
  specification_version: 4
177
147
  summary: Ruby toolkit for Amazon Alexa API
178
148
  test_files:
179
- - spec/request_spec.rb
180
- - spec/response_spec.rb
181
149
  - spec/spec_helper.rb
data/spec/request_spec.rb DELETED
@@ -1,197 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe 'Amazon Alexa request handling' do
4
- before do
5
- @fpath = 'spec/fixtures/request'
6
- end
7
-
8
- describe 'General request handling' do
9
- before do
10
- @json = File.read("#{@fpath}/launch_request.json")
11
- end
12
-
13
- describe 'Request' do
14
- it 'should build a Request object for valid JSON' do
15
- alexa = AlexaRuby.new(@json)
16
- alexa.request.wont_be_nil
17
- end
18
-
19
- it 'should build a Response object for valid JSON' do
20
- alexa = AlexaRuby.new(@json)
21
- alexa.response.wont_be_nil
22
- end
23
-
24
- it 'should build a Request object for valid Hash' do
25
- alexa = AlexaRuby.new(Oj.load(@json))
26
- alexa.request.wont_be_nil
27
- end
28
-
29
- it 'should build a Response object for valid Hash' do
30
- alexa = AlexaRuby.new(Oj.load(@json))
31
- alexa.response.wont_be_nil
32
- end
33
-
34
- it 'should raise ArgumentError in case of invalid JSON' do
35
- err = proc { AlexaRuby.new('{"test":}') }.must_raise ArgumentError
36
- err.message.must_equal 'Request must be a valid JSON object'
37
- end
38
-
39
- it 'should raise ArgumentError in case of invalid Hash' do
40
- err = proc { AlexaRuby.new('{"test":}') }.must_raise ArgumentError
41
- err.message.must_equal 'Request must be a valid JSON object'
42
- end
43
-
44
- it 'should setup all request parameters' do
45
- alexa = AlexaRuby.new(@json)
46
- alexa.request.version.wont_be_nil
47
- alexa.request.type.wont_be_nil
48
- alexa.request.context.wont_be_nil
49
- alexa.request.id.wont_be_nil
50
- alexa.request.timestamp.wont_be_nil
51
- alexa.request.locale.wont_be_nil
52
- end
53
-
54
- it 'should raise ArgumentError if request ID is missing' do
55
- req = Oj.load(@json, symbol_keys: true)
56
- req[:request][:requestId] = nil
57
- err = proc { AlexaRuby.new(req) }.must_raise ArgumentError
58
- err.message.must_equal 'Missing request ID'
59
- end
60
-
61
- it 'should raise ArgumentError if request timestamp is missing' do
62
- req = Oj.load(@json, symbol_keys: true)
63
- req[:request][:timestamp] = nil
64
- err = proc { AlexaRuby.new(req) }.must_raise ArgumentError
65
- err.message.must_equal 'Missing request timestamp'
66
- end
67
-
68
- it 'should raise ArgumentError if request type unknown' do
69
- req = Oj.load(@json, symbol_keys: true)
70
- req[:request][:type] = 'dummy'
71
- err = proc { AlexaRuby.new(req) }.must_raise ArgumentError
72
- err.message.must_equal 'Unknown type of Alexa request'
73
- end
74
-
75
- it 'should raise ArgumentError if request structure isn\'t valid' do
76
- req = Oj.load(@json, symbol_keys: true)
77
- req[:request] = nil
78
- msg = 'Invalid request structure, ' \
79
- 'please, refer to the Amazon Alexa manual: ' \
80
- 'https://developer.amazon.com/public/solutions' \
81
- '/alexa/alexa-skills-kit/docs/alexa-skills-kit-interface-reference'
82
- err = proc { AlexaRuby.new(req) }.must_raise ArgumentError
83
- err.message.must_equal msg
84
- end
85
- end
86
-
87
- describe 'Session' do
88
- it 'should set correct session params' do
89
- alexa = AlexaRuby.new(@json)
90
- alexa.request.session.state.wont_be_nil
91
- alexa.request.session.id.wont_be_nil
92
- end
93
-
94
- it 'should raise ArgumentError if session isn\'t valid' do
95
- req = Oj.load(@json, symbol_keys: true)
96
- req[:session] = nil
97
- err = proc { AlexaRuby.new(req) }.must_raise ArgumentError
98
- err.message.must_equal 'Empty user session'
99
- end
100
- end
101
-
102
- describe 'Context' do
103
- it 'should set correct context params' do
104
- alexa = AlexaRuby.new(@json)
105
- alexa.request.context.app_id.wont_be_nil
106
- alexa.request.context.user.wont_be_nil
107
- alexa.request.context.user.id.wont_be_nil
108
- alexa.request.context.device.wont_be_nil
109
- alexa.request.context.device.id.wont_be_nil
110
- end
111
-
112
- it 'should raise ArgumentError if application ID is missing' do
113
- req = Oj.load(@json, symbol_keys: true)
114
- req[:context][:System][:application][:applicationId] = nil
115
- err = proc { AlexaRuby.new(req) }.must_raise ArgumentError
116
- err.message.must_equal 'Missing application ID'
117
- end
118
-
119
- it 'should raise ArgumentError if user ID is missing' do
120
- req = Oj.load(@json, symbol_keys: true)
121
- req[:context][:System][:user][:userId] = nil
122
- err = proc { AlexaRuby.new(req) }.must_raise ArgumentError
123
- err.message.must_equal 'Missing user ID'
124
- end
125
-
126
- it 'should raise ArgumentError if device ID is missing' do
127
- req = Oj.load(@json, symbol_keys: true)
128
- req[:context][:System][:device][:deviceId] = nil
129
- err = proc { AlexaRuby.new(req) }.must_raise ArgumentError
130
- err.message.must_equal 'Missing device ID'
131
- end
132
- end
133
- end
134
-
135
- describe 'LaunchRequest' do
136
- before do
137
- @json = File.read("#{@fpath}/launch_request.json")
138
- end
139
-
140
- it 'should parse valid LaunchRequest correctly' do
141
- alexa = AlexaRuby.new(@json)
142
- alexa.request.type.must_equal :launch
143
- end
144
- end
145
-
146
- describe 'IntentRequest' do
147
- before do
148
- @json = File.read("#{@fpath}/intent_request.json")
149
- end
150
-
151
- it 'should parse valid IntentRequest correctly' do
152
- alexa = AlexaRuby.new(@json)
153
- alexa.request.type.must_equal :intent
154
- alexa.request.intent_name.must_equal 'GetZodiacHoroscopeIntent'
155
- alexa.request.confirmation_status.must_equal :unknown
156
- alexa.request.dialog_state.must_equal :completed
157
- alexa.request.slots[0].name.must_equal 'ZodiacSign'
158
- end
159
-
160
- it 'should raise an ArgumentError if intent is undefined' do
161
- req = Oj.load(@json, symbol_keys: true)
162
- req[:request][:intent] = nil
163
- err = proc { AlexaRuby.new(req) }.must_raise ArgumentError
164
- err.message.must_equal 'Intent must be defined'
165
- end
166
- end
167
-
168
- describe 'SessionEndedRequest' do
169
- before do
170
- @json = File.read("#{@fpath}/session_ended_request.json")
171
- end
172
-
173
- it 'should parse valid SessionEndedRequest correctly' do
174
- alexa = AlexaRuby.new(@json)
175
- alexa.request.type.must_equal :session_ended
176
- alexa.request.session.state.must_equal :ended
177
- alexa.request.session.end_reason.must_equal :user_quit
178
- end
179
- end
180
-
181
- describe 'AudioPlayerRequest' do
182
- before do
183
- @json = File.read("#{@fpath}/audio_player_request.json")
184
- end
185
-
186
- it 'should parse valid AudioPlayerRequest correctly' do
187
- alexa = AlexaRuby.new(@json)
188
- alexa.request.type.must_equal :audio_player
189
- alexa.request.playback_state.must_equal 'PlaybackFailed'
190
- alexa.request.playback_offset.must_equal 0
191
- alexa.request.error_type.must_equal 'string'
192
- alexa.request.error_message.must_equal 'string'
193
- alexa.request.error_playback_token.must_equal 'string'
194
- alexa.request.error_player_activity.must_equal 'string'
195
- end
196
- end
197
- end
@@ -1,201 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe 'Build response to Amazon Alexa service' do
4
- before do
5
- @req_path = 'spec/fixtures/request'
6
- @resp_path = 'spec/fixtures/response'
7
- end
8
-
9
- describe 'General response handling' do
10
- before do
11
- @json = File.read("#{@req_path}/launch_request.json")
12
- @alexa = AlexaRuby.new(@json)
13
- end
14
-
15
- it 'should build a Response object for valid JSON' do
16
- @alexa.response.wont_be_nil
17
- resp = Oj.load(@alexa.response.json, symbol_keys: true)
18
- resp[:version].wont_be_nil
19
- resp[:response][:shouldEndSession].must_equal true
20
- end
21
- end
22
-
23
- describe 'Session parameters management' do
24
- before do
25
- @json = File.read("#{@req_path}/launch_request.json")
26
- @alexa = AlexaRuby.new(@json)
27
- end
28
-
29
- it 'should add one session attribute correctly' do
30
- @alexa.response.add_session_attribute(:id, 'djsdhdsjhdsjhdsjh')
31
- resp = Oj.load(@alexa.response.json, symbol_keys: true)
32
- resp[:sessionAttributes][:id].must_equal 'djsdhdsjhdsjhdsjh'
33
- end
34
-
35
- it 'should add pack of session attributes correctly' do
36
- @alexa.response.add_session_attributes(
37
- id: 'djsdhdsjhdsjhdsjh',
38
- test: 'test'
39
- )
40
- resp = Oj.load(@alexa.response.json, symbol_keys: true)
41
- resp[:sessionAttributes][:id].must_equal 'djsdhdsjhdsjhdsjh'
42
- resp[:sessionAttributes][:test].must_equal 'test'
43
- end
44
-
45
- it 'should merge pack of session attributes correctly' do
46
- @alexa.response.add_session_attributes(
47
- id: 'djsdhdsjhdsjhdsjh',
48
- test: 'test'
49
- )
50
- @alexa.response.merge_session_attributes(token: '7783y3h43hg4ghh')
51
- resp = Oj.load(@alexa.response.json, symbol_keys: true)
52
- resp[:sessionAttributes][:id].must_equal 'djsdhdsjhdsjhdsjh'
53
- resp[:sessionAttributes][:test].must_equal 'test'
54
- resp[:sessionAttributes][:token].must_equal '7783y3h43hg4ghh'
55
- end
56
-
57
- it 'should raise ArgumentError if duplicate attribute found' do
58
- @alexa.response.add_session_attribute(:id, 'djsdhdsjhdsjhdsjh')
59
- err = proc {
60
- @alexa.response.add_session_attribute(:id, '833hj33jh3hj')
61
- }.must_raise ArgumentError
62
- err.message.must_equal 'Duplicate session attributes not allowed'
63
- end
64
-
65
- it 'should raise ArgumentError if attributes pack isn\'t a Hash' do
66
- err = proc {
67
- @alexa.response.add_session_attributes('Test')
68
- }.must_raise ArgumentError
69
- err.message.must_equal 'Attributes must be a Hash'
70
- end
71
- end
72
-
73
- describe 'Cards management' do
74
- before do
75
- @json = File.read("#{@req_path}/launch_request.json")
76
- @card = Oj.load(
77
- File.read("#{@resp_path}/sample_card.json"),
78
- symbol_keys: true
79
- )
80
- @alexa = AlexaRuby.new(@json)
81
- end
82
-
83
- it 'should add card to response' do
84
- @alexa.response.add_card(@card)
85
- resp = Oj.load(@alexa.response.json, symbol_keys: true)
86
- resp[:response][:card][:type].must_equal 'Simple'
87
- resp[:response][:card][:title].must_equal 'title'
88
- resp[:response][:card][:content].must_equal 'text'
89
- end
90
-
91
- it 'should add "text" and "image" nodes if card type is Standard' do
92
- @card[:type] = 'Standard'
93
- @alexa.response.add_card(@card)
94
- resp = Oj.load(@alexa.response.json, symbol_keys: true)
95
- small_url = 'https://test.ru/example_small.jpg'
96
- large_url = 'https://test.ru/example_large.jpg'
97
- resp[:response][:card][:type].must_equal 'Standard'
98
- resp[:response][:card][:text].must_equal 'text'
99
- resp[:response][:card][:image][:smallImageUrl].must_equal small_url
100
- resp[:response][:card][:image][:largeImageUrl].must_equal large_url
101
- end
102
-
103
- it 'should raise ArgumentError if no title given' do
104
- @card[:title] = nil
105
- err = proc { @alexa.response.add_card(@card) }.must_raise ArgumentError
106
- err.message.must_equal 'Card need a title'
107
- end
108
-
109
- it 'should raise ArgumentError if card type unknown' do
110
- @card[:type] = 'Test'
111
- err = proc { @alexa.response.add_card(@card) }.must_raise ArgumentError
112
- err.message.must_equal 'Unknown card type'
113
- end
114
- end
115
-
116
- describe 'Audio directives management' do
117
- before do
118
- @json = File.read("#{@req_path}/launch_request.json")
119
- @audio = Oj.load(
120
- File.read("#{@resp_path}/sample_audio.json"),
121
- symbol_keys: true
122
- )
123
- @alexa = AlexaRuby.new(@json)
124
- end
125
-
126
- it 'should add AudioPlayer.Play directive' do
127
- @alexa.response.add_audio_player_directive(:start, @audio)
128
- resp = Oj.load(@alexa.response.json, symbol_keys: true)
129
- directive = resp[:response][:directives][0]
130
- directive[:type].must_equal 'AudioPlayer.Play'
131
- directive[:playBehavior].must_equal 'REPLACE_ALL'
132
- stream = directive[:audioItem][:stream]
133
- stream[:url].must_equal @audio[:url]
134
- stream[:token].must_equal @audio[:token]
135
- stream[:offsetInMilliseconds].must_equal @audio[:offset]
136
- end
137
-
138
- it 'should add AudioPlayer.Stop directive' do
139
- @alexa.response.add_audio_player_directive(:stop)
140
- resp = Oj.load(@alexa.response.json, symbol_keys: true)
141
- resp[:response][:directives][0][:type].must_equal 'AudioPlayer.Stop'
142
- end
143
- end
144
-
145
- describe 'Speech management' do
146
- before do
147
- @json = File.read("#{@req_path}/launch_request.json")
148
- @alexa = AlexaRuby.new(@json)
149
- end
150
-
151
- it 'should add plain text output to response' do
152
- @alexa.response.tell('Test')
153
- resp = Oj.load(@alexa.response.json, symbol_keys: true)
154
- resp[:response][:outputSpeech][:type].must_equal 'PlainText'
155
- resp[:response][:outputSpeech][:text].must_equal 'Test'
156
- resp[:response][:outputSpeech][:ssml].must_be_nil
157
- end
158
-
159
- it 'should add SSML output to response' do
160
- @alexa.response.tell('Test', nil, true)
161
- resp = Oj.load(@alexa.response.json, symbol_keys: true)
162
- resp[:response][:outputSpeech][:type].must_equal 'SSML'
163
- resp[:response][:outputSpeech][:ssml].must_equal '<speak>Test</speak>'
164
- resp[:response][:outputSpeech][:text].must_be_nil
165
- end
166
-
167
- it 'should add output with repromt' do
168
- @alexa.response.tell('Test', 'One more test')
169
- resp = Oj.load(@alexa.response.json, symbol_keys: true)
170
- resp[:response][:outputSpeech][:type].must_equal 'PlainText'
171
- resp[:response][:outputSpeech][:text].must_equal 'Test'
172
- resp[:response][:outputSpeech][:ssml].must_be_nil
173
- repromt = resp[:response][:reprompt][:outputSpeech]
174
- repromt[:type].must_equal 'PlainText'
175
- repromt[:text].must_equal 'One more test'
176
- repromt[:ssml].must_be_nil
177
- end
178
-
179
- it 'should add output speech and return JSON' do
180
- sample = Oj.to_json(
181
- Oj.load(File.read("#{@resp_path}/sample_response.json"))
182
- )
183
- @alexa.response.tell!('Test').must_equal sample
184
- end
185
-
186
- it 'should add output speech without closing session' do
187
- @alexa.response.ask('Test')
188
- resp = Oj.load(@alexa.response.json, symbol_keys: true)
189
- resp[:response][:shouldEndSession].must_equal false
190
- end
191
-
192
- it 'should add output speech without closing session and return JSON' do
193
- sample = Oj.load(
194
- File.read("#{@resp_path}/sample_response.json"),
195
- symbol_keys: true
196
- )
197
- sample[:response][:shouldEndSession] = false
198
- @alexa.response.ask!('Test').must_equal Oj.to_json(sample)
199
- end
200
- end
201
- end