Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/telesign/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion telesign.gemspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
33 changes: 14 additions & 19 deletions test/test_rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,20 @@ 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,
rest_endpoint: 'http://localhost')

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
Expand Down Expand Up @@ -185,22 +182,20 @@ 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,
rest_endpoint: 'http://localhost')

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
Expand Down