diff --git a/lib/request_builder.rb b/lib/request_builder.rb index ca64a01..d254e98 100644 --- a/lib/request_builder.rb +++ b/lib/request_builder.rb @@ -1,3 +1,4 @@ +# encoding: UTF-8 require 'net/http' require 'net/https' require 'json' @@ -12,12 +13,15 @@ class RequestBuilder attr_accessor :params # Rosette API key attr_accessor :user_key + # Rosette API binding version + attr_accessor :binding_version - def initialize(user_key, alternate_url, params = {}) #:notnew: + def initialize(user_key, alternate_url, params = {}, binding_version) #:notnew: @user_key = user_key @alternate_url = alternate_url @params = params @retries = 5 + @binding_version = binding_version end # Prepares a plain POST request for Rosette API. @@ -40,6 +44,8 @@ def prepare_plain_request(params) request['X-RosetteAPI-Key'] = @user_key request['Content-Type'] = 'application/json' request['Accept'] = 'application/json' + request['X-RosetteAPI-Binding'] = 'ruby' + request['X-RosetteAPI-Binding-Version'] = @binding_version request.body = params.to_json [http, request] @@ -84,6 +90,8 @@ def prepare_multipart_request(params) request = Net::HTTP::Post.new uri.request_uri request.add_field 'Content-Type', "multipart/form-data; boundary=#{boundary}" request.add_field 'X-RosetteAPI-Key', @user_key + request.add_field 'X-RosetteAPI-Binding', 'ruby' + request.add_field 'X-RosetteAPI-Binding-Version', @binding_version request.body = post_body.join [http, request] @@ -107,8 +115,6 @@ def send_get_request # # Returns JSON response or raises RosetteAPIError if encountered. def send_post_request - params = (@alternate_url.to_s.include? '/info?clientVersion=') ? '{"body": "version check"}' : @params - if !params['filePath'].nil? http, request = self.prepare_multipart_request params else diff --git a/lib/rosette_api.rb b/lib/rosette_api.rb index 3e958f3..25f852a 100644 --- a/lib/rosette_api.rb +++ b/lib/rosette_api.rb @@ -32,8 +32,6 @@ class RosetteAPI SENTENCES_ENDPOINT = '/sentences' # Rosette API info endpoint INFO = '/info' - # Rosette API version check endpoint - VERSION_CHECK = '/info?clientVersion=' + BINDING_VERSION # Rosette API ping endpoint PING = '/ping' @@ -49,20 +47,6 @@ def initialize(user_key, alternate_url = 'https://api.rosette.com/rest/v1') #:no if @alternate_url.to_s.end_with?('/') @alternate_url = alternate_url.to_s.slice(0..-2) end - - self.check_version_compatibility - end - - # Checks binding version compatibility against the Rosette API server. - def check_version_compatibility - response = RequestBuilder.new(@user_key, @alternate_url + VERSION_CHECK) - .send_post_request - - unless response['versionChecked'] - puts JSON.pretty_generate(response) - - exit - end end # Identifies in which language(s) the input is written. @@ -77,7 +61,7 @@ def get_language(params) params = params.load_params - RequestBuilder.new(@user_key, @alternate_url + LANGUAGE_ENDPOINT, params) + RequestBuilder.new(@user_key, @alternate_url + LANGUAGE_ENDPOINT, params, BINDING_VERSION) .send_post_request end @@ -95,7 +79,7 @@ def get_morphology_complete(params) params = params.load_params - RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/complete', params) + RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/complete', params, BINDING_VERSION) .send_post_request end @@ -112,7 +96,7 @@ def get_compound_components(params) params = params.load_params - RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/compound-components', params) + RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/compound-components', params, BINDING_VERSION) .send_post_request end @@ -129,7 +113,7 @@ def get_han_readings(params) params = params.load_params - RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/han-readings', params) + RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/han-readings', params, BINDING_VERSION) .send_post_request end @@ -145,7 +129,7 @@ def get_lemmas(params) params = params.load_params - RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/lemmas', params) + RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/lemmas', params, BINDING_VERSION) .send_post_request end @@ -162,7 +146,7 @@ def get_parts_of_speech(params) params = params.load_params - RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/parts-of-speech', params) + RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/parts-of-speech', params, BINDING_VERSION) .send_post_request end @@ -183,7 +167,7 @@ def get_entities(params, resolve_entities = false) endpoint = resolve_entities ? (ENTITIES_ENDPOINT + '/linked') : ENTITIES_ENDPOINT - RequestBuilder.new(@user_key, @alternate_url + endpoint, params) + RequestBuilder.new(@user_key, @alternate_url + endpoint, params, BINDING_VERSION) .send_post_request end @@ -213,7 +197,7 @@ def get_categories(params) params = params.load_params - RequestBuilder.new(@user_key, @alternate_url + CATEGORIES_ENDPOINT, params) + RequestBuilder.new(@user_key, @alternate_url + CATEGORIES_ENDPOINT, params, BINDING_VERSION) .send_post_request end @@ -229,7 +213,7 @@ def get_relationships(params) params = params.load_params - RequestBuilder.new(@user_key, @alternate_url + RELATIONSHIPS_ENDPOINT, params) + RequestBuilder.new(@user_key, @alternate_url + RELATIONSHIPS_ENDPOINT, params, BINDING_VERSION) .send_post_request end @@ -245,7 +229,7 @@ def get_sentiment(params) params = params.load_params - RequestBuilder.new(@user_key, @alternate_url + SENTIMENT_ENDPOINT, params) + RequestBuilder.new(@user_key, @alternate_url + SENTIMENT_ENDPOINT, params, BINDING_VERSION) .send_post_request end @@ -261,7 +245,7 @@ def name_translation(params) params = params.load_params - RequestBuilder.new(@user_key, @alternate_url + NAME_TRANSLATION_ENDPOINT, params) + RequestBuilder.new(@user_key, @alternate_url + NAME_TRANSLATION_ENDPOINT, params, BINDING_VERSION) .send_post_request end @@ -278,7 +262,7 @@ def name_similarity(params) params = params.load_params - RequestBuilder.new(@user_key, @alternate_url + NAME_SIMILARITY_ENDPOINT, params) + RequestBuilder.new(@user_key, @alternate_url + NAME_SIMILARITY_ENDPOINT, params, BINDING_VERSION) .send_post_request end @@ -294,7 +278,7 @@ def get_tokens(params) params = params.load_params - RequestBuilder.new(@user_key, @alternate_url + TOKENS_ENDPOINT, params) + RequestBuilder.new(@user_key, @alternate_url + TOKENS_ENDPOINT, params, BINDING_VERSION) .send_post_request end @@ -310,21 +294,21 @@ def get_sentences(params) params = params.load_params - RequestBuilder.new(@user_key, @alternate_url + SENTENCES_ENDPOINT, params) + RequestBuilder.new(@user_key, @alternate_url + SENTENCES_ENDPOINT, params, BINDING_VERSION) .send_post_request end - # Gets information about the Rosette API, returns name, version, build number + # Gets information about the Rosette API, returns name, build number # and build time. def info - RequestBuilder.new(@user_key, @alternate_url + INFO) + RequestBuilder.new(@user_key, @alternate_url + INFO, BINDING_VERSION) .send_get_request end # Pings the Rosette API for a response indicting that the service is # available. def ping - RequestBuilder.new(@user_key, @alternate_url + PING) + RequestBuilder.new(@user_key, @alternate_url + PING, BINDING_VERSION) .send_get_request end diff --git a/tests/tests_spec.rb b/tests/tests_spec.rb index 2b7d511..b39c1c8 100644 --- a/tests/tests_spec.rb +++ b/tests/tests_spec.rb @@ -10,21 +10,15 @@ describe '.get_language' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/language.json')) before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/language'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'language'}.to_json, headers: {}) end it 'test language' do @@ -47,26 +41,21 @@ .get_language(params) } .to raise_error(BadRequestFormatError) end + end describe '.get_morphology_complete' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/morphology_complete.json')) before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/complete'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'morphology/complete'}.to_json, headers: {}) end it 'test morphology complete' do @@ -80,21 +69,15 @@ describe '.get_compound_components' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/morphology_compound_components.json')) before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/compound-components'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'morphology/compound-components'}.to_json, headers: {}) end it 'test morphology compound components' do @@ -108,21 +91,15 @@ describe '.get_han_readings' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/morphology_han_readings.json')), encoding: 'utf-8' before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/han-readings'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'morphology/han-readings'}.to_json, headers: {}) end it 'test morphology han readings' do @@ -136,21 +113,15 @@ describe '.get_parts_of_speech' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/morphology_parts_of_speech.json')) before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/parts-of-speech'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'morphology/parts-of-speech'}.to_json, headers: {}) end it 'test morphology parts of speech' do @@ -164,21 +135,15 @@ describe '.get_lemmas' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/morphology_lemmas.json')) before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/lemmas'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'morphology/lemmas'}.to_json, headers: {}) end it 'test morphology lemmas' do @@ -192,21 +157,15 @@ describe '.get_entities' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/entities.json')), encoding: 'utf-8' before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/entities'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'entities'}.to_json, headers: {}) end it 'test entities' do @@ -221,21 +180,15 @@ describe '.get_entities_linked' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/entities_linked.json')) before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/entities/linked'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'entities/linked'}.to_json, headers: {}) end it 'test entities linked' do @@ -257,21 +210,15 @@ describe '.get_categories' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/categories.json')) before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/categories'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'categories'}.to_json, headers: {}) end it 'test categories' do @@ -285,21 +232,15 @@ describe '.get_relationships' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/relationships.json')) before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/relationships'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'relationships'}.to_json, headers: {}) end it 'test relationships' do @@ -313,21 +254,15 @@ describe '.name_translation' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/name_translation.json')), encoding: 'utf-8' before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/name-translation'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'name-translation'}.to_json, headers: {}) end it 'test name translation' do @@ -346,21 +281,15 @@ describe '.name_similarity' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/name_similarity.json')), encoding: 'utf-8' before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/name-similarity'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'name-similarity'}.to_json, headers: {}) end it 'test name similarity' do @@ -388,21 +317,15 @@ describe '.get_tokens' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/tokens.json')), encoding: 'utf-8' before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/tokens'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'tokens'}.to_json, headers: {}) end it 'test tokens' do @@ -416,21 +339,15 @@ describe '.get_sentences' do request_file = File.read File.expand_path(File.join(File.dirname(__FILE__), '../mock-data/request/sentences.json')) before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:post, 'https://api.rosette.com/rest/v1/sentences'). with(body: request_file, headers: {'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). + 'X-Rosetteapi-Key' => '0123456789', + 'X-Rosetteapi-Binding' => 'ruby', + 'X-Rosetteapi-Binding-Version' => '1.0.2'}). to_return(status: 200, body: {'test': 'sentences'}.to_json, headers: {}) end it 'test sentences' do @@ -446,14 +363,6 @@ describe '.info' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:get, 'https://api.rosette.com/rest/v1/info'). with(headers: {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', @@ -469,14 +378,6 @@ describe '.ping' do before do - stub_request(:post, 'https://api.rosette.com/rest/v1/info?clientVersion=1.0.2'). - with(body: "\"{\\\"body\\\": \\\"version check\\\"}\"", - headers: {'Accept' => 'application/json', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Ruby', - 'X-Rosetteapi-Key' => '0123456789'}). - to_return(status: 200, body: {'versionChecked': true}.to_json, headers: {}) stub_request(:get, 'https://api.rosette.com/rest/v1/ping'). with(headers: {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', @@ -489,4 +390,6 @@ expect(response).instance_of? Hash end end + + end