smartystreets_ruby_sdk 7.2.1 → 7.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56b7843bee25e0bea8668ed813993642aa247daa98eccd615e6d20d6fab1207b
4
- data.tar.gz: ae6176580f1b7afffe2b94f7e6eb6c31fd539d6c9099177c61dc2fb95cfea3da
3
+ metadata.gz: f3583fc90ecd6ea6b74e60c274560f4ccaca60ac3f87f0affb05d19875ea0db6
4
+ data.tar.gz: 5acee3177c57105e3057e417fcf53fe75b25f9a877e8329bef8d04808c132eec
5
5
  SHA512:
6
- metadata.gz: 3de4fe9934225c46a7ad970e8062f2e5af69237a7976f15879ffeec9048b60f8a9a3ec31dfcb4cf36799673ce5a5269b135edc7204b8e159d6912f59eb60c80f
7
- data.tar.gz: b6f808ffd6f4a79c0936c3683d94403425fd9232b0f05e00a9843ad2cb61dbe77fdd5411f79d6ad8e0c9c8a69a5c0edba278fb416ed77176dc411be05fda05c7
6
+ metadata.gz: 7f366e31a8ff91ecae194eac3d190f4c6875d295fcf6f7b1cc7551d31c7c930f3a4d670031c871d0fec1060f66bf194f61d3c14fe6f230ad60b23f1c1929d98d
7
+ data.tar.gz: ab15c7452caabe0a5493bb6dd30d1ad08690f6b5101dbf963bf7c2d685f32ca0cb6684aa47adbf26b9521102e8700af59e31a00a7a62a859cbbed6221436a6c0
@@ -13,6 +13,7 @@ module SmartyStreets
13
13
  # Sends a Lookup object to the International Street API and stores the result in the Lookup's result field.
14
14
  # Deprecated, please use send_lookup instead.
15
15
  def send(lookup)
16
+ raise ArgumentError, 'lookup cannot be nil' if lookup.nil?
16
17
  lookup.ensure_enough_info
17
18
  request = build_request(lookup)
18
19
 
@@ -26,6 +27,7 @@ module SmartyStreets
26
27
 
27
28
  # Sends a Lookup object to the International Street API and stores the result in the Lookup's result field.
28
29
  def send_lookup(lookup)
30
+ raise ArgumentError, 'lookup cannot be nil' if lookup.nil?
29
31
  lookup.ensure_enough_info
30
32
  request = build_request(lookup)
31
33
 
@@ -71,18 +71,8 @@ module SmartyStreets
71
71
  end
72
72
 
73
73
  def ensure_enough_info
74
- raise UnprocessableEntityError, 'Country field is required.' if missing_country
75
-
76
- return true if has_freeform
77
-
78
- raise UnprocessableEntityError, 'Either freeform or address1 is required.' if missing_address1
79
-
80
- return true if has_postal_code
81
-
82
- if missing_locality_or_administrative_area
83
- raise UnprocessableEntityError, 'Insufficient information:'\
84
- 'One or more required fields were not set on the lookup.'
85
- end
74
+ raise UnprocessableEntityError, 'Country field is required.' if field_is_missing(@country)
75
+ raise UnprocessableEntityError, 'Either freeform or address1 is required.' if field_is_missing(@freeform) && field_is_missing(@address1)
86
76
  end
87
77
  end
88
78
  end
@@ -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
- break if STATUS_TO_RETRY.include?(response.status_code.to_i) == false
20
-
21
- if response.status_code.to_i == STATUS_TOO_MANY_REQUESTS
22
- seconds_to_backoff = 10
23
- if response.header.nil? == false
24
- if Integer(response.header["Retry-After"], exception: false)
25
- seconds_to_backoff = response.header["Retry-After"].to_i
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
- rate_limit_backoff(seconds_to_backoff)
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 backoff(attempt)
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("There was an error processing the request. Retrying in #{backoff_duration} seconds...")
60
+ @logger.log("#{message} Retrying in #{backoff_duration} seconds...")
42
61
  @sleeper.sleep(backoff_duration)
43
62
  end
44
63
 
@@ -1,3 +1,3 @@
1
1
  module SmartyStreets
2
- VERSION = '7.2.1' # DO NOT EDIT (this is updated by a build job when a new release is published)
2
+ VERSION = '7.2.3' # DO NOT EDIT (this is updated by a build job when a new release is published)
3
3
  end
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.2.1
4
+ version: 7.2.3
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-06 00:00:00.000000000 Z
11
+ date: 2026-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler