diff --git a/alexa_ruby.gemspec b/alexa_ruby.gemspec index 9095a06..33d0c4d 100644 --- a/alexa_ruby.gemspec +++ b/alexa_ruby.gemspec @@ -20,12 +20,12 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] - spec.add_runtime_dependency 'bundler', '>= 1.6.9' - spec.add_runtime_dependency 'rake' - spec.add_runtime_dependency 'oj', '~> 3.0' + spec.add_runtime_dependency 'addressable', '>= 2.5.1' spec.add_runtime_dependency 'httparty', '>= 0.15.5' + spec.add_development_dependency 'bundler', '>= 1.6.9' + spec.add_development_dependency 'rake' spec.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.2' spec.add_development_dependency 'minitest-reporters', '~> 1.1', '>= 1.1.14' end diff --git a/lib/alexa_ruby.rb b/lib/alexa_ruby.rb index b31d8f4..03973ad 100644 --- a/lib/alexa_ruby.rb +++ b/lib/alexa_ruby.rb @@ -1,7 +1,8 @@ # Utilities require 'addressable/uri' -require 'oj' require 'securerandom' +require 'json' +require 'ostruct' # Gem core require 'alexa_ruby/alexa' @@ -18,6 +19,7 @@ require 'alexa_ruby/request/launch_request' require 'alexa_ruby/request/intent_request' require 'alexa_ruby/request/intent_request/slot' +require 'alexa_ruby/request/intent_request/resolution_authority' require 'alexa_ruby/request/session_ended_request' require 'alexa_ruby/response/response' require 'alexa_ruby/response/audio_player' @@ -51,8 +53,8 @@ def new(request, opts = {}) # @return [Hash] valid builded JSON # @raise [ArgumentError] if given object isn't a valid JSON object def build_json(obj) - obj = Oj.generate(obj) if hash?(obj) - Oj.load(obj, symbol_keys: true) + obj = JSON.generate(obj) if hash?(obj) + JSON.parse(obj, symbolize_names: true) rescue StandardError raise ArgumentError, 'Request must be a valid JSON object' end diff --git a/lib/alexa_ruby/request/base_request.rb b/lib/alexa_ruby/request/base_request.rb index bca269d..5a56aa4 100644 --- a/lib/alexa_ruby/request/base_request.rb +++ b/lib/alexa_ruby/request/base_request.rb @@ -30,7 +30,7 @@ def valid? # # @return [String] request json def json - Oj.to_json(@req) + JSON.generate(@req) end private diff --git a/lib/alexa_ruby/request/base_request/validator.rb b/lib/alexa_ruby/request/base_request/validator.rb index 00d1243..b4c9214 100644 --- a/lib/alexa_ruby/request/base_request/validator.rb +++ b/lib/alexa_ruby/request/base_request/validator.rb @@ -54,7 +54,7 @@ def valid_uri? # # @return [Boolean] def valid_certificates? - Certificates.new(@chain_url, @signature, Oj.to_json(@request)).valid? + Certificates.new(@chain_url, @signature, JSON.generate(@request)).valid? end end end diff --git a/lib/alexa_ruby/request/intent_request/resolution_authority.rb b/lib/alexa_ruby/request/intent_request/resolution_authority.rb new file mode 100644 index 0000000..538ccea --- /dev/null +++ b/lib/alexa_ruby/request/intent_request/resolution_authority.rb @@ -0,0 +1,34 @@ +module AlexaRuby + # Class that encapsulates each slot + class ResolutionAuthority + attr_accessor :authority, :status_code, :values + + # Initialize slot and define its name and value + # + # @param resolution_authority [Hash] resolution_authority parameters + def initialize(resolution_authority) + @resolution_authority = resolution_authority + @authority = @resolution_authority[:authority] + @status_code = define_status_code + @values = @resolution_authority[:values]&.map { |value| OpenStruct.new(value[:value]) } || [] + end + + private + + # Define user confirmation status + # + # @return [Symbol] current authority status code + def define_status_code + case @resolution_authority.dig(:status, :code) + when 'ER_SUCCESS_MATCH' + :success_match + when 'ER_SUCCESS_NO_MATCH' + :success_no_match + when 'ER_ERROR_TIMEOUT' + :error_timeout + when 'ER_ERROR_EXCEPTION' + :error_exception + end + end + end +end diff --git a/lib/alexa_ruby/request/intent_request/slot.rb b/lib/alexa_ruby/request/intent_request/slot.rb index ff7f740..98ecd36 100644 --- a/lib/alexa_ruby/request/intent_request/slot.rb +++ b/lib/alexa_ruby/request/intent_request/slot.rb @@ -1,7 +1,7 @@ module AlexaRuby # Class that encapsulates each slot class Slot - attr_accessor :name, :value, :confirmation_status + attr_accessor :name, :value, :confirmation_status, :resolution_authorities, :resolved_values # Initialize slot and define its name and value # @@ -12,6 +12,8 @@ def initialize(slot) @name = @slot[:name] @value = @slot[:value] @confirmation_status = define_confirmation_status + @resolution_authorities = define_resolution_authorities + @resolved_values = define_resolved_values end private @@ -36,5 +38,21 @@ def define_confirmation_status :denied end end + + # Define entity resolution authorities + # + # @return [Array] resolution authorities + def define_resolution_authorities + authorities = @slot.dig(:resolutions, :resolutionsPerAuthority) + &.map { |resolution_authority| ResolutionAuthority.new(resolution_authority) } + authorities || [] + end + + # Define entity resolution values + # + # @return [Array] resolved values + def define_resolved_values + @resolution_authorities.map(&:values)&.flatten + end end end diff --git a/lib/alexa_ruby/response/response.rb b/lib/alexa_ruby/response/response.rb index 2bba201..7236f76 100644 --- a/lib/alexa_ruby/response/response.rb +++ b/lib/alexa_ruby/response/response.rb @@ -88,7 +88,7 @@ def add_audio_player_directive(directive, params = {}) # # @return [JSON] response object def json - Oj.to_json(@resp) + JSON.generate(@resp) end # Tell something to Alexa user and close conversation. diff --git a/spec/fixtures/request/intent_request.json b/spec/fixtures/request/intent_request.json index 69b8ecf..42f8137 100644 --- a/spec/fixtures/request/intent_request.json +++ b/spec/fixtures/request/intent_request.json @@ -33,7 +33,7 @@ }, "request": { "type": "IntentRequest", - "requestId": " amzn1.echo-api.request.0000000-0000-0000-0000-00000000000", + "requestId": "amzn1.echo-api.request.0000000-0000-0000-0000-00000000000", "timestamp": "2015-05-13T12:34:56Z", "dialogState": "COMPLETED", "locale": "string", diff --git a/spec/fixtures/request/resolution_request.json b/spec/fixtures/request/resolution_request.json new file mode 100644 index 0000000..6d57a66 --- /dev/null +++ b/spec/fixtures/request/resolution_request.json @@ -0,0 +1,77 @@ +{ + "version": "1.0", + "session": { + "new": false, + "sessionId": "amzn1.echo-api.session.0000000-0000-0000-0000-00000000000", + "application": { + "applicationId": "amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe" + }, + "user": { + "userId": "amzn1.account.AM3B00000000000000000000000" + } + }, + "context": { + "System": { + "application": { + "applicationId": "amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe" + }, + "user": { + "userId": "amzn1.account.AM3B00000000000000000000000" + }, + "device": { + "deviceId": "TEST", + "supportedInterfaces": {} + }, + "apiEndpoint": "https://api.amazonalexa.com", + "apiAccessToken": "token" + }, + "Viewport": { + "experiences": [ + { + "arcMinuteWidth": 246, + "arcMinuteHeight": 144, + "canRotate": false, + "canResize": false + } + ], + "shape": "RECTANGLE", + "pixelWidth": 1024, + "pixelHeight": 600, + "dpi": 160, + "currentPixelWidth": 1024, + "currentPixelHeight": 600, + "touch": [ + "SINGLE" + ] + } + }, + "request": { + "type": "IntentRequest", + "requestId": "amzn1.echo-api.request.0000000-0000-0000-0000-00000000000", + "timestamp": "2019-02-07T14:49:57Z", + "locale": "en-US", + "dialogState": "COMPLETED", + "intent": { + "name": "RebuildLatest", + "confirmationStatus": "CONFIRMED", + "slots": { + "statusFilter": { + "name": "statusFilter", + "value": "yeah", + "confirmationStatus": "NONE", + "source": "USER", + "resolutions": { + "resolutionsPerAuthority": [ + { + "authority": "skill.arn.statusFilter", + "status": { + "code": "ER_SUCCESS_NO_MATCH" + } + } + ] + } + } + } + } + } +} \ No newline at end of file diff --git a/spec/fixtures/request/resolution_success_request.json b/spec/fixtures/request/resolution_success_request.json new file mode 100644 index 0000000..0634bde --- /dev/null +++ b/spec/fixtures/request/resolution_success_request.json @@ -0,0 +1,91 @@ +{ + "version": "1.0", + "session": { + "new": false, + "sessionId": "amzn1.echo-api.session.0000000-0000-0000-0000-00000000000", + "application": { + "applicationId": "amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe" + }, + "user": { + "userId": "amzn1.account.AM3B00000000000000000000000" + } + }, + "context": { + "System": { + "application": { + "applicationId": "amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe" + }, + "user": { + "userId": "amzn1.account.AM3B00000000000000000000000" + }, + "device": { + "deviceId": "TEST", + "supportedInterfaces": {} + }, + "apiEndpoint": "https://api.amazonalexa.com", + "apiAccessToken": "token" + }, + "Viewport": { + "experiences": [ + { + "arcMinuteWidth": 246, + "arcMinuteHeight": 144, + "canRotate": false, + "canResize": false + } + ], + "shape": "RECTANGLE", + "pixelWidth": 1024, + "pixelHeight": 600, + "dpi": 160, + "currentPixelWidth": 1024, + "currentPixelHeight": 600, + "touch": [ + "SINGLE" + ] + } + }, + "request": { + "type": "IntentRequest", + "requestId": "amzn1.echo-api.request.0000000-0000-0000-0000-00000000000", + "timestamp": "2019-02-06T22:09:26Z", + "locale": "en-US", + "dialogState": "COMPLETED", + "intent": { + "name": "RebuildLatest", + "confirmationStatus": "CONFIRMED", + "slots": { + "edgeVersion": { + "name": "edgeVersion", + "value": "9732", + "confirmationStatus": "CONFIRMED", + "source": "USER" + }, + "statusFilter": { + "name": "statusFilter", + "value": "all", + "confirmationStatus": "NONE", + "source": "USER", + "resolutions": { + "resolutionsPerAuthority": [ + { + "authority": "skill.arn.statusFilter", + "status": { + "code": "ER_SUCCESS_MATCH" + }, + "values": [ + { + "value": { + "name": "both", + "id": "BOTH" + } + } + ] + } + ] + } + } + } + } + } +} \ No newline at end of file diff --git a/spec/request/base_request_spec.rb b/spec/request/base_request_spec.rb index 700d6e7..0a895ab 100644 --- a/spec/request/base_request_spec.rb +++ b/spec/request/base_request_spec.rb @@ -22,12 +22,12 @@ end it 'should build a Request object for valid Hash' do - alexa = AlexaRuby.new(Oj.load(@json)) + alexa = AlexaRuby.new(JSON.parse(@json)) alexa.request.wont_be_nil end it 'should build a Response object for valid Hash' do - alexa = AlexaRuby.new(Oj.load(@json)) + alexa = AlexaRuby.new(JSON.parse(@json)) alexa.response.wont_be_nil end @@ -52,28 +52,28 @@ end it 'should raise ArgumentError if request ID is missing' do - req = Oj.load(@json, symbol_keys: true) + req = JSON.parse(@json, symbolize_names: true) req[:request][:requestId] = nil err = proc { AlexaRuby.new(req) }.must_raise ArgumentError err.message.must_equal 'Missing request ID' end it 'should raise ArgumentError if request timestamp is missing' do - req = Oj.load(@json, symbol_keys: true) + req = JSON.parse(@json, symbolize_names: true) req[:request][:timestamp] = nil err = proc { AlexaRuby.new(req) }.must_raise ArgumentError err.message.must_equal 'Missing request timestamp' end it 'should raise ArgumentError if request type unknown' do - req = Oj.load(@json, symbol_keys: true) + req = JSON.parse(@json, symbolize_names: true) req[:request][:type] = 'dummy' err = proc { AlexaRuby.new(req) }.must_raise ArgumentError err.message.must_equal 'Unknown type of Alexa request' end it 'should raise ArgumentError if request structure isn\'t valid' do - req = Oj.load(@json, symbol_keys: true) + req = JSON.parse(@json, symbolize_names: true) req[:request] = nil msg = 'Invalid request structure, ' \ 'please, refer to the Amazon Alexa manual: ' \ @@ -84,7 +84,7 @@ end it 'should not raise ArgumentError if request structure isn\'t valid and validations are disabled' do - req = Oj.load(@json, symbol_keys: true) + req = JSON.parse(@json, symbolize_names: true) req[:version] = nil alexa = AlexaRuby.new(req, disable_validations: true) alexa.request.version.must_be_nil @@ -92,7 +92,7 @@ it 'should return received request in JSON format' do alexa = AlexaRuby.new(@json) - sample = Oj.to_json(Oj.load(@json)) + sample = JSON.generate(JSON.parse(@json)) alexa.request.json.must_equal sample end end diff --git a/spec/request/context_spec.rb b/spec/request/context_spec.rb index 5ac3172..bc58f8b 100644 --- a/spec/request/context_spec.rb +++ b/spec/request/context_spec.rb @@ -24,28 +24,28 @@ end it 'should raise ArgumentError if application ID is missing' do - req = Oj.load(@json, symbol_keys: true) + req = JSON.parse(@json, symbolize_names: true) req[:context][:System][:application][:applicationId] = nil err = proc { AlexaRuby.new(req) }.must_raise ArgumentError err.message.must_equal 'Missing application ID' end it 'should raise ArgumentError if user ID is missing' do - req = Oj.load(@json, symbol_keys: true) + req = JSON.parse(@json, symbolize_names: true) req[:context][:System][:user][:userId] = nil err = proc { AlexaRuby.new(req) }.must_raise ArgumentError err.message.must_equal 'Missing user ID' end it 'should raise ArgumentError if device ID is missing' do - req = Oj.load(@json, symbol_keys: true) + req = JSON.parse(@json, symbolize_names: true) req[:context][:System][:device][:deviceId] = nil err = proc { AlexaRuby.new(req) }.must_raise ArgumentError err.message.must_equal 'Missing device ID' end it 'should remain valid if audio player section is missing' do - req = Oj.load(@json, symbol_keys: true) + req = JSON.parse(@json, symbolize_names: true) req[:context][:AudioPlayer] = nil alexa = AlexaRuby.new(req) alexa.request.context.audio_state.must_be_nil diff --git a/spec/request/intent_request_spec.rb b/spec/request/intent_request_spec.rb index 6308feb..8b2f39c 100644 --- a/spec/request/intent_request_spec.rb +++ b/spec/request/intent_request_spec.rb @@ -20,7 +20,7 @@ end it 'should raise an ArgumentError if intent is undefined' do - req = Oj.load(@json, symbol_keys: true) + req = JSON.parse(@json, symbolize_names: true) req[:request][:intent] = nil err = proc { AlexaRuby.new(req) }.must_raise ArgumentError err.message.must_equal 'Intent must be defined' diff --git a/spec/request/no_match_resolution_spec.rb b/spec/request/no_match_resolution_spec.rb new file mode 100644 index 0000000..fa73a67 --- /dev/null +++ b/spec/request/no_match_resolution_spec.rb @@ -0,0 +1,31 @@ +require_relative '../spec_helper' + +describe 'AlexaRuby' do + before do + @fpath = 'spec/fixtures/request' + end + + describe 'IntentRequestWithResolutions' do + before do + @json = File.read("#{@fpath}/resolution_success_request.json") + end + + it 'should parse valid IntentRequest correctly' do + alexa = AlexaRuby.new(@json) + alexa.request.type.must_equal :intent + alexa.request.intent_name.must_equal 'RebuildLatest' + alexa.request.confirmation_status.must_equal :confirmed + alexa.request.dialog_state.must_equal :completed + alexa.request.slots[1].name.must_equal 'statusFilter' + end + + it 'resolved_values should return expected values' do + alexa = AlexaRuby.new(@json) + alexa.request.slots[1].name.must_equal 'statusFilter' + alexa.request.slots[1].resolved_values.each do |resolved_value| + resolved_value.name.must_equal "both" + resolved_value.id.must_equal "BOTH" + end + end + end +end diff --git a/spec/request/resolution_spec.rb b/spec/request/resolution_spec.rb new file mode 100644 index 0000000..c187995 --- /dev/null +++ b/spec/request/resolution_spec.rb @@ -0,0 +1,29 @@ +require_relative '../spec_helper' + +describe 'AlexaRuby' do + before do + @fpath = 'spec/fixtures/request' + end + + describe 'IntentRequestWithResolutions' do + before do + @json = File.read("#{@fpath}/resolution_request.json") + end + + it 'should parse valid IntentRequest correctly' do + alexa = AlexaRuby.new(@json) + alexa.request.type.must_equal :intent + alexa.request.intent_name.must_equal 'RebuildLatest' + alexa.request.confirmation_status.must_equal :confirmed + alexa.request.dialog_state.must_equal :completed + alexa.request.slots[0].name.must_equal 'statusFilter' + end + + it 'no match authority with no resolved_values should return empty array' do + alexa = AlexaRuby.new(@json) + alexa.request.slots[0].name.must_equal 'statusFilter' + alexa.request.slots[0].resolution_authorities.first.status_code.must_equal :success_no_match + alexa.request.slots[0].resolved_values.must_equal [] + end + end +end diff --git a/spec/request/session_spec.rb b/spec/request/session_spec.rb index 9baed2d..3e6db1d 100644 --- a/spec/request/session_spec.rb +++ b/spec/request/session_spec.rb @@ -20,21 +20,21 @@ end it 'should set OAuth access token if it is present in request' do - req = Oj.load(@json, symbol_keys: true) + req = JSON.parse(@json, symbolize_names: true) req[:session][:user][:accessToken] = 'test' alexa = AlexaRuby.new(req) alexa.request.session.user.access_token.must_equal 'test' end it 'should raise ArgumentError if session isn\'t valid' do - req = Oj.load(@json, symbol_keys: true) + req = JSON.parse(@json, symbolize_names: true) req[:session] = nil err = proc { AlexaRuby.new(req) }.must_raise ArgumentError err.message.must_equal 'Empty user session' end it 'should raise ArgumentError if user ID is missing' do - req = Oj.load(@json, symbol_keys: true) + req = JSON.parse(@json, symbolize_names: true) req[:session][:user][:userId] = nil err = proc { AlexaRuby.new(req) }.must_raise ArgumentError err.message.must_equal 'Missing user ID' diff --git a/spec/response/response_audio_spec.rb b/spec/response/response_audio_spec.rb index 2a13501..5887e6d 100644 --- a/spec/response/response_audio_spec.rb +++ b/spec/response/response_audio_spec.rb @@ -9,16 +9,16 @@ describe 'AudioPlayer' do before do @json = File.read("#{@req_path}/launch_request.json") - @audio = Oj.load( + @audio = JSON.parse( File.read("#{@resp_path}/sample_audio.json"), - symbol_keys: true + symbolize_names: true ) @alexa = AlexaRuby.new(@json) end it 'should add replacing all AudioPlayer.Play directive' do @alexa.response.add_audio_player_directive(:start, @audio) - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) directive = resp[:response][:directives][0] directive[:type].must_equal 'AudioPlayer.Play' directive[:playBehavior].must_equal 'REPLACE_ALL' @@ -31,7 +31,7 @@ it 'should add replacing enqueued AudioPlayer.Play directive' do @audio[:play_behavior] = :replace_enqueued @alexa.response.add_audio_player_directive(:start, @audio) - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) directive = resp[:response][:directives][0] directive[:type].must_equal 'AudioPlayer.Play' directive[:playBehavior].must_equal 'REPLACE_ENQUEUED' @@ -44,7 +44,7 @@ it 'should add enqueuing AudioPlayer.Play directive' do @audio[:play_behavior] = :enqueue @alexa.response.add_audio_player_directive(:start, @audio) - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) directive = resp[:response][:directives][0] directive[:type].must_equal 'AudioPlayer.Play' directive[:playBehavior].must_equal 'ENQUEUE' @@ -56,7 +56,7 @@ it 'should add AudioPlayer.ClearQueue directive that clears all' do @alexa.response.add_audio_player_directive(:clear) - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) directive = resp[:response][:directives][0] directive[:type].must_equal 'AudioPlayer.ClearQueue' directive[:clearBehavior].must_equal 'CLEAR_ALL' @@ -67,7 +67,7 @@ :clear, clear_behavior: :clear_queue ) - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) directive = resp[:response][:directives][0] directive[:type].must_equal 'AudioPlayer.ClearQueue' directive[:clearBehavior].must_equal 'CLEAR_ENQUEUED' @@ -75,7 +75,7 @@ it 'should add AudioPlayer.Stop directive' do @alexa.response.add_audio_player_directive(:stop) - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) resp[:response][:directives][0][:type].must_equal 'AudioPlayer.Stop' end diff --git a/spec/response/response_cards_spec.rb b/spec/response/response_cards_spec.rb index 0fdf59b..dd6cb38 100644 --- a/spec/response/response_cards_spec.rb +++ b/spec/response/response_cards_spec.rb @@ -9,16 +9,16 @@ describe 'Card' do before do @json = File.read("#{@req_path}/launch_request.json") - @card = Oj.load( + @card = JSON.parse( File.read("#{@resp_path}/sample_card.json"), - symbol_keys: true + symbolize_names: true ) @alexa = AlexaRuby.new(@json) end it 'should add card to response' do @alexa.response.add_card(@card) - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) resp[:response][:card][:type].must_equal 'Simple' resp[:response][:card][:title].must_equal 'title' resp[:response][:card][:content].must_equal 'text' @@ -34,7 +34,7 @@ it 'should add "text" and "image" nodes if card type is Standard' do @card[:type] = 'Standard' @alexa.response.add_card(@card) - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) small_url = 'https://test.ru/example_small.jpg' large_url = 'https://test.ru/example_large.jpg' resp[:response][:card][:type].must_equal 'Standard' diff --git a/spec/response/response_session_spec.rb b/spec/response/response_session_spec.rb index e8f89a9..30794c6 100644 --- a/spec/response/response_session_spec.rb +++ b/spec/response/response_session_spec.rb @@ -14,7 +14,7 @@ it 'should add one session attribute correctly' do @alexa.response.add_session_attribute(:id, 'djsdhdsjhdsjhdsjh') - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) resp[:sessionAttributes][:id].must_equal 'djsdhdsjhdsjhdsjh' end @@ -23,7 +23,7 @@ id: 'djsdhdsjhdsjhdsjh', test: 'test' ) - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) resp[:sessionAttributes][:id].must_equal 'djsdhdsjhdsjhdsjh' resp[:sessionAttributes][:test].must_equal 'test' end @@ -34,7 +34,7 @@ test: 'test' ) @alexa.response.merge_session_attributes(token: '7783y3h43hg4ghh') - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) resp[:sessionAttributes][:id].must_equal 'djsdhdsjhdsjhdsjh' resp[:sessionAttributes][:test].must_equal 'test' resp[:sessionAttributes][:token].must_equal '7783y3h43hg4ghh' diff --git a/spec/response/response_spec.rb b/spec/response/response_spec.rb index e4a7fc4..f3716c5 100644 --- a/spec/response/response_spec.rb +++ b/spec/response/response_spec.rb @@ -14,7 +14,7 @@ it 'should build a Response object for valid JSON' do @alexa.response.wont_be_nil - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) resp[:version].wont_be_nil resp[:response][:shouldEndSession].must_equal true end diff --git a/spec/response/response_speech_spec.rb b/spec/response/response_speech_spec.rb index 1f40070..f5d7e76 100644 --- a/spec/response/response_speech_spec.rb +++ b/spec/response/response_speech_spec.rb @@ -14,7 +14,7 @@ it 'should add plain text output to response' do @alexa.response.tell('Test') - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) resp[:response][:outputSpeech][:type].must_equal 'PlainText' resp[:response][:outputSpeech][:text].must_equal 'Test' resp[:response][:outputSpeech][:ssml].must_be_nil @@ -22,7 +22,7 @@ it 'should add SSML output to response' do @alexa.response.tell('Test', nil, true) - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) resp[:response][:outputSpeech][:type].must_equal 'SSML' resp[:response][:outputSpeech][:ssml].must_equal 'Test' resp[:response][:outputSpeech][:text].must_be_nil @@ -30,7 +30,7 @@ it 'should add output with repromt' do @alexa.response.tell('Test', 'One more test') - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) resp[:response][:outputSpeech][:type].must_equal 'PlainText' resp[:response][:outputSpeech][:text].must_equal 'Test' resp[:response][:outputSpeech][:ssml].must_be_nil @@ -41,9 +41,9 @@ end it 'should add output speech and return JSON' do - sample = Oj.load( + sample = JSON.parse( File.read("#{@resp_path}/sample_response.json"), - symbol_keys: true + symbolize_names: true ) sample[:response][:reprompt] = { outputSpeech: { @@ -51,22 +51,22 @@ text: 'Test' } } - @alexa.response.tell!('Test', 'Test').must_equal Oj.to_json(sample) + @alexa.response.tell!('Test', 'Test').must_equal JSON.generate(sample) end it 'should add output speech without closing session' do @alexa.response.ask('Test') - resp = Oj.load(@alexa.response.json, symbol_keys: true) + resp = JSON.parse(@alexa.response.json, symbolize_names: true) resp[:response][:shouldEndSession].must_equal false end it 'should add output speech without closing session and return JSON' do - sample = Oj.load( + sample = JSON.parse( File.read("#{@resp_path}/sample_response.json"), - symbol_keys: true + symbolize_names: true ) sample[:response][:shouldEndSession] = false - @alexa.response.ask!('Test').must_equal Oj.to_json(sample) + @alexa.response.ask!('Test').must_equal JSON.generate(sample) end end end