smartystreets_ruby_sdk 7.2.2 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/international_autocomplete_example.rb +3 -1
- data/lib/smartystreets_ruby_sdk/international_autocomplete/client.rb +2 -0
- data/lib/smartystreets_ruby_sdk/international_autocomplete/lookup.rb +4 -2
- data/lib/smartystreets_ruby_sdk/retry_sender.rb +32 -13
- data/lib/smartystreets_ruby_sdk/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 28599b31e31c16d357e1eed5707e76db2cfa42160f84f56ded56293340d88415
|
|
4
|
+
data.tar.gz: 954e023ba758549b81d2b170ce083ce7f0d0df603d685ca82a0c2fba90e59c99
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c7cc4acddb8b5fb509747976c9081b42a1ba176307b0d62b7474096bbf55b3867541cb96076918cab5a7c9cbf8367e9d597b071a454ef23172bed50c8059bfa5
|
|
7
|
+
data.tar.gz: 682ff5422e6d6e57db6535af1a59aa6fab65ea03120404850330665005f06ff3fc8104cd95b697133dcd80d262278d3cc7fe5edfe85ca66367e0d6c9ed854748
|
|
@@ -28,13 +28,15 @@ class InternationalAutocompleteExample
|
|
|
28
28
|
lookup = Lookup.new('Louis')
|
|
29
29
|
lookup.country = "FRA"
|
|
30
30
|
lookup.locality = "Paris"
|
|
31
|
+
lookup.max_group_results = 5
|
|
32
|
+
lookup.geolocation = true
|
|
31
33
|
|
|
32
34
|
# lookup.add_custom_parameter('parameter', 'value')
|
|
33
35
|
|
|
34
36
|
suggestions = client.send(lookup) # The client will also return the suggestions directly
|
|
35
37
|
|
|
36
38
|
puts
|
|
37
|
-
puts '*** Result with some filters ***'
|
|
39
|
+
puts '*** Result with some filters (max_group_results=5, geolocation=on) ***'
|
|
38
40
|
puts
|
|
39
41
|
|
|
40
42
|
suggestions.each do |suggestion|
|
|
@@ -39,6 +39,8 @@ module SmartyStreets
|
|
|
39
39
|
add_parameter(request, 'search', lookup.search)
|
|
40
40
|
add_parameter(request, 'country', lookup.country)
|
|
41
41
|
add_parameter(request, 'max_results', lookup.max_results.to_s)
|
|
42
|
+
add_parameter(request, 'max_group_results', lookup.max_group_results.to_s)
|
|
43
|
+
add_parameter(request, 'geolocation', 'on') if lookup.geolocation
|
|
42
44
|
add_parameter(request, 'include_only_locality', lookup.locality)
|
|
43
45
|
add_parameter(request, 'include_only_postal_code', lookup.postal_code)
|
|
44
46
|
|
|
@@ -6,14 +6,16 @@ module SmartyStreets
|
|
|
6
6
|
# of the lookup after it comes back from the API.
|
|
7
7
|
class Lookup < JSONAble
|
|
8
8
|
|
|
9
|
-
attr_accessor :result, :search, :address_id, :country, :max_results, :locality, :postal_code, :custom_param_hash
|
|
9
|
+
attr_accessor :result, :search, :address_id, :country, :max_results, :max_group_results, :geolocation, :locality, :postal_code, :custom_param_hash
|
|
10
10
|
|
|
11
|
-
def initialize(search = nil, address_id = nil, country = nil, max_results = nil, locality = nil, postal_code = nil, custom_param_hash = nil)
|
|
11
|
+
def initialize(search = nil, address_id = nil, country = nil, max_results = nil, max_group_results = 100, geolocation = false, locality = nil, postal_code = nil, custom_param_hash = nil)
|
|
12
12
|
@result = []
|
|
13
13
|
@search = search
|
|
14
14
|
@address_id = address_id
|
|
15
15
|
@country = country
|
|
16
16
|
@max_results = max_results
|
|
17
|
+
@max_group_results = max_group_results
|
|
18
|
+
@geolocation = geolocation
|
|
17
19
|
@locality = locality
|
|
18
20
|
@postal_code = postal_code
|
|
19
21
|
@custom_param_hash = {}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'timeout'
|
|
3
|
+
|
|
1
4
|
module SmartyStreets
|
|
2
5
|
class RetrySender
|
|
3
6
|
MAX_BACKOFF_DURATION = 10
|
|
4
7
|
STATUS_TOO_MANY_REQUESTS = 429
|
|
5
8
|
STATUS_TO_RETRY = [408, 429, 500, 502, 503, 504]
|
|
9
|
+
TIMEOUT_ERRORS = [Net::OpenTimeout, Net::ReadTimeout, Timeout::Error, Errno::ETIMEDOUT]
|
|
6
10
|
|
|
7
11
|
def initialize(max_retries, inner, sleeper, logger)
|
|
8
12
|
@max_retries = max_retries
|
|
@@ -16,29 +20,44 @@ module SmartyStreets
|
|
|
16
20
|
|
|
17
21
|
(1..@max_retries).each do |i|
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if timeout_error?(response.error)
|
|
24
|
+
timeout_backoff(i, response.error)
|
|
25
|
+
response = @inner.send(request)
|
|
26
|
+
elsif !STATUS_TO_RETRY.include?(response.status_code.to_i)
|
|
27
|
+
break
|
|
28
|
+
else
|
|
29
|
+
if response.status_code.to_i == STATUS_TOO_MANY_REQUESTS
|
|
30
|
+
seconds_to_backoff = 10
|
|
31
|
+
unless response.header.nil?
|
|
32
|
+
if Integer(response.header["Retry-After"], exception: false)
|
|
33
|
+
seconds_to_backoff = response.header["Retry-After"].to_i
|
|
34
|
+
end
|
|
26
35
|
end
|
|
36
|
+
rate_limit_backoff(seconds_to_backoff)
|
|
37
|
+
else
|
|
38
|
+
backoff(i)
|
|
27
39
|
end
|
|
28
|
-
|
|
29
|
-
else
|
|
30
|
-
backoff(i)
|
|
40
|
+
response = @inner.send(request)
|
|
31
41
|
end
|
|
32
|
-
response = @inner.send(request)
|
|
33
42
|
end
|
|
34
43
|
|
|
35
44
|
response
|
|
36
45
|
end
|
|
37
46
|
|
|
38
|
-
def
|
|
47
|
+
def timeout_error?(error)
|
|
48
|
+
return false if error.nil?
|
|
49
|
+
|
|
50
|
+
TIMEOUT_ERRORS.any? { |klass| error.is_a?(klass) }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def timeout_backoff(attempt, error)
|
|
54
|
+
backoff(attempt, "Timeout error (#{error.class}).")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def backoff(attempt, message = 'There was an error processing the request.')
|
|
39
58
|
backoff_duration = [attempt, MAX_BACKOFF_DURATION].min
|
|
40
59
|
|
|
41
|
-
@logger.log("
|
|
60
|
+
@logger.log("#{message} Retrying in #{backoff_duration} seconds...")
|
|
42
61
|
@sleeper.sleep(backoff_duration)
|
|
43
62
|
end
|
|
44
63
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: smartystreets_ruby_sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 7.
|
|
4
|
+
version: 7.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SmartyStreets SDK Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-03-
|
|
11
|
+
date: 2026-03-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|