From 426b758f0f9821b42ffdde54d838b6bf6832af48 Mon Sep 17 00:00:00 2001 From: Robert Ramsay Date: Fri, 7 Jun 2019 05:50:06 -0500 Subject: [PATCH] Fix handling of URI query params. Bump telesign sdk version to 2.2.3. --- lib/telesign/rest.rb | 6 +++--- telesign.gemspec | 2 +- test/test_rest.rb | 33 ++++++++++++++------------------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/lib/telesign/rest.rb b/lib/telesign/rest.rb index 77bb912..562b07f 100644 --- a/lib/telesign/rest.rb +++ b/lib/telesign/rest.rb @@ -7,7 +7,7 @@ require 'net/http/persistent' module Telesign - SDK_VERSION = '2.2.2' + SDK_VERSION = '2.2.3' # The TeleSign RestClient is a generic HTTP REST client that can be extended to make requests against any of # TeleSign's REST API endpoints. @@ -192,10 +192,9 @@ def execute(method_function, method_name, resource, **params) resource_uri = URI.parse("#{@rest_endpoint}#{resource}") - request = method_function.new(resource_uri.request_uri) - encoded_fields = '' if %w[POST PUT].include? method_name + request = method_function.new(resource_uri.request_uri) if content_type == "application/x-www-form-urlencoded" unless params.empty? encoded_fields = URI.encode_www_form(params, Encoding::UTF_8) @@ -208,6 +207,7 @@ def execute(method_function, method_name, resource, **params) end else resource_uri.query = URI.encode_www_form(params, Encoding::UTF_8) + request = method_function.new(resource_uri.request_uri) end headers = RestClient.generate_telesign_headers(@customer_id, diff --git a/telesign.gemspec b/telesign.gemspec index 16fea16..f2b5cc6 100644 --- a/telesign.gemspec +++ b/telesign.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'telesign' - s.version = '2.2.2' + s.version = '2.2.3' s.licenses = ['MIT'] s.date = '2017-05-25' s.summary = 'TeleSign Ruby SDK' diff --git a/test/test_rest.rb b/test/test_rest.rb index 554010f..a64bd0b 100644 --- a/test/test_rest.rb +++ b/test/test_rest.rb @@ -140,7 +140,7 @@ def test_rest_client_get test_resource = '/test/resource' test_params = {:'test' => "123_\u03ff_test"} - stub_request(:get, 'localhost/test/resource').to_return(body: '{}') + stub_request(:get, 'localhost/test/resource?test=123_%CF%BF_test').to_return(body: '{}') client = Telesign::RestClient.new(@customer_id, @api_key, @@ -148,15 +148,12 @@ def test_rest_client_get client.get(test_resource, **test_params) - - assert_requested :get, 'http://localhost/test/resource' - # webmock doesn't seem to track query params...? - # assert_requested :get, 'http://localhost/test/resource', query: {'test' => '123_%CF%BF_test'} - assert_requested :get, 'http://localhost/test/resource', body: '' - assert_not_requested :get, 'http://localhost/test/resource', headers: {'Content-Type' => /.*\S.*/} - assert_requested :get, 'http://localhost/test/resource', headers: {'x-ts-auth-method' => 'HMAC-SHA256'} - assert_requested :get, 'http://localhost/test/resource', headers: {'x-ts-nonce' => /.*\S.*/} - assert_requested :get, 'http://localhost/test/resource', headers: {'Date' => /.*\S.*/} + assert_requested :get, 'http://localhost/test/resource?test=123_%CF%BF_test' + assert_requested :get, 'http://localhost/test/resource?test=123_%CF%BF_test', body: '' + assert_not_requested :get, 'http://localhost/test/resource?test=123_%CF%BF_test', headers: {'Content-Type' => /.*\S.*/} + assert_requested :get, 'http://localhost/test/resource?test=123_%CF%BF_test', headers: {'x-ts-auth-method' => 'HMAC-SHA256'} + assert_requested :get, 'http://localhost/test/resource?test=123_%CF%BF_test', headers: {'x-ts-nonce' => /.*\S.*/} + assert_requested :get, 'http://localhost/test/resource?test=123_%CF%BF_test', headers: {'Date' => /.*\S.*/} end def test_rest_client_put @@ -185,7 +182,7 @@ def test_rest_client_delete test_resource = '/test/resource' test_params = {:'test' => "123_\u03ff_test"} - stub_request(:delete, 'localhost/test/resource').to_return(body: '{}') + stub_request(:delete, 'localhost/test/resource?test=123_%CF%BF_test').to_return(body: '{}') client = Telesign::RestClient.new(@customer_id, @api_key, @@ -193,14 +190,12 @@ def test_rest_client_delete client.delete(test_resource, **test_params) - assert_requested :delete, 'http://localhost/test/resource' - # webmock doesn't seem to track query params...? - # assert_requested :get, 'http://localhost/test/resource', query: {'test' => '123_%CF%BF_test'} - assert_requested :delete, 'http://localhost/test/resource', body: '' - assert_not_requested :delete, 'http://localhost/test/resource', headers: {'Content-Type' => /.*\S.*/} - assert_requested :delete, 'http://localhost/test/resource', headers: {'x-ts-auth-method' => 'HMAC-SHA256'} - assert_requested :delete, 'http://localhost/test/resource', headers: {'x-ts-nonce' => /.*\S.*/} - assert_requested :delete, 'http://localhost/test/resource', headers: {'Date' => /.*\S.*/} + assert_requested :delete, 'http://localhost/test/resource?test=123_%CF%BF_test' + assert_requested :delete, 'http://localhost/test/resource?test=123_%CF%BF_test', body: '' + assert_not_requested :delete, 'http://localhost/test/resource?test=123_%CF%BF_test', headers: {'Content-Type' => /.*\S.*/} + assert_requested :delete, 'http://localhost/test/resource?test=123_%CF%BF_test', headers: {'x-ts-auth-method' => 'HMAC-SHA256'} + assert_requested :delete, 'http://localhost/test/resource?test=123_%CF%BF_test', headers: {'x-ts-nonce' => /.*\S.*/} + assert_requested :delete, 'http://localhost/test/resource?test=123_%CF%BF_test', headers: {'Date' => /.*\S.*/} end def test_phoneid