Skip to content

Commit

Permalink
Merge pull request #49 from smartystreets/xan/fix-url-prefix-bug
Browse files Browse the repository at this point in the history
Fix url prefix bug from retries
  • Loading branch information
XanSmarty authored Mar 21, 2024
2 parents 58c0d3d + 1ebd713 commit 2617928
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def build_request(lookup)
request = Request.new

unless lookup.address_id.nil?
request.url_prefix = '/' + lookup.address_id
request.url_components = '/' + lookup.address_id
end

add_parameter(request, 'search', lookup.search)
Expand Down
3 changes: 2 additions & 1 deletion lib/smartystreets_ruby_sdk/request.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module SmartyStreets
class Request
attr_accessor :parameters, :payload, :url_prefix, :referer, :header, :content_type
attr_accessor :parameters, :payload, :url_components, :url_prefix, :referer, :header, :content_type

def initialize
@parameters = {}
@payload = nil
@url_prefix = nil
@url_components = nil
@referer = nil
@header = {}
@content_type = 'application/json'
Expand Down
4 changes: 2 additions & 2 deletions lib/smartystreets_ruby_sdk/url_prefix_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ def initialize(url_prefix, inner)
end

def send(request)
if request.url_prefix.nil?
if request.url_components.nil?
request.url_prefix = @url_prefix
else
request.url_prefix = @url_prefix + request.url_prefix
request.url_prefix = @url_prefix + request.url_components
end

@inner.send(request)
Expand Down
2 changes: 1 addition & 1 deletion lib/smartystreets_ruby_sdk/us_enrichment/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __send(lookup)

return if lookup.nil?

smarty_request.url_prefix = '/' + lookup.smarty_key + '/' + lookup.data_set + '/' + lookup.data_sub_set
smarty_request.url_components = '/' + lookup.smarty_key + '/' + lookup.data_set + '/' + lookup.data_sub_set

response = @sender.send(smarty_request)
results = @serializer.deserialize(response.payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_sending_fully_populated_lookup
assert_equal('7', sender.request.parameters['max_results'])
assert_equal('3', sender.request.parameters['include_only_locality'])
assert_equal('4', sender.request.parameters['include_only_postal_code'])
assert_equal('/5', sender.request.url_prefix)
assert_equal('/5', sender.request.url_components)

end

Expand Down
13 changes: 12 additions & 1 deletion test/smartystreets_ruby_sdk/test_url_prefix_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TestURLPrefixSender < Minitest::Test
def test_request_url_present
inner = MockSender.new(SmartyStreets::Response.new(nil, 123))
request = SmartyStreets::Request.new
request.url_prefix = '/jimbo'
request.url_components = '/jimbo'
sender = SmartyStreets::URLPrefixSender.new('http://mysite.com/lookup', inner)

sender.send(request)
Expand All @@ -23,4 +23,15 @@ def test_request_url_not_present

assert_equal('http://mysite.com/lookup', request.url_prefix)
end
def test_multiple_sends
inner = MockSender.new(SmartyStreets::Response.new(nil, 123))
request = SmartyStreets::Request.new
request.url_components = '/jimbo'
sender = SmartyStreets::URLPrefixSender.new('http://mysite.com/lookup', inner)

sender.send(request)
sender.send(request)

assert_equal('http://mysite.com/lookup/jimbo', request.url_prefix)
end
end
4 changes: 2 additions & 2 deletions test/smartystreets_ruby_sdk/us_enrichment/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def test_url_formatted_correctly
client = SmartyStreets::USEnrichment::Client.new(sender, FakeDeserializer.new(nil))

client.send_property_financial_lookup("xxx")
assert_equal("/xxx/property/financial", sender.request.url_prefix)
assert_equal("/xxx/property/financial", sender.request.url_components)

client.send_property_principal_lookup("123")
assert_equal("/123/property/principal", sender.request.url_prefix)
assert_equal("/123/property/principal", sender.request.url_components)
end
end

0 comments on commit 2617928

Please sign in to comment.