dear_inventory 1.5.3 → 1.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e5cb2ffdff24260bcc6c5b578dc75a7f0f2c0162d842a6f00190bbfce621899
4
- data.tar.gz: 1288ddd4dcc8b506591ac94a1ccf7daa8042227fababdf3ce9e9be010a67a097
3
+ metadata.gz: f50f5fccdaf7007a7f7d80ebf08745d50b0cc7243a445cfc4c4a13d197533a79
4
+ data.tar.gz: 2713ad24418a84bcc12ace816ef59e21a48cdd40ebeed3dbff5b4999863c69f2
5
5
  SHA512:
6
- metadata.gz: 13369a2e2e7a1fbedcfc29b3b801ab0fa400f61ba0f35bac2417c0a5b52019f8569c0f33847639adb942151e3d678d7091a5ff1f26ce549ffaee17747d112952
7
- data.tar.gz: eae8c28613ccc920daa9a44497ae8417506883dea7c6c79ac979d0066c0b2cb3d18be614753d280ea294e359d0ca6ede59ac278d8f22426e1c7d9c1d5991f4ae
6
+ metadata.gz: d942ed12b4022323851b4a285ab1fc1cd8356c7a8a99528ae2050ddfc8237d91b5e9994224dbfc30185f0f7fab2a1fcc823802183ad53cc41bf2fb01169baed5
7
+ data.tar.gz: 87114e0054e9e3444cb8aa01d6315c5c9322dd0e2070e97938f60353e36d623ffbd32ae347d85556036b9ea5863f335792a2bc0e7872c2cb0d48ad035d24c69c
@@ -1,5 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DearInventory
4
- class APILimitError < DearInventory::Error; end
4
+ class APILimitError < DearInventory::RequestError
5
+ # Cin7 sends "60 Seconds" in Retry-After rather than the delta-seconds or
6
+ # HTTP-date that RFC 9110 allows, so only a leading integer can be trusted.
7
+ # X-RateLimit-Reset carries the same value as a bare integer
8
+ def retry_after
9
+ return if response.nil?
10
+
11
+ reset = response.headers["X-RateLimit-Reset"]
12
+ return reset.to_i unless reset.nil?
13
+
14
+ response.headers["Retry-After"].to_s[/\A\d+/]&.to_i
15
+ end
16
+ end
5
17
  end
@@ -56,7 +56,7 @@ module DearInventory
56
56
  raise if @retries >= MAX_RETRIES
57
57
 
58
58
  message_prefix = ERROR_MESSAGE_PREFIXES[error.class]
59
- retry_time = @retries * RETRY_DELAY
59
+ retry_time = retry_delay(error)
60
60
 
61
61
  DearInventory.config.logger.warn(
62
62
  "#{message_prefix} while fetching #{@parameters.uri}. " \
@@ -66,5 +66,12 @@ module DearInventory
66
66
  sleep(retry_time)
67
67
  call
68
68
  end
69
+
70
+ def retry_delay(error)
71
+ backoff = @retries * RETRY_DELAY
72
+ return backoff unless error.is_a?(DearInventory::APILimitError)
73
+
74
+ error.retry_after || backoff
75
+ end
69
76
  end
70
77
  end
@@ -136,11 +136,11 @@ module DearInventory
136
136
 
137
137
  # Cin7 reported the rate limit as a 503 until 2026. The message is still
138
138
  # checked for that status because a 503 is also a genuine outage
139
- raise DearInventory::APILimitError if http_status == 429
140
- raise DearInventory::APILimitError if http_status == 503 && error == API_LIMIT_ERROR
139
+ if http_status == 429 || (http_status == 503 && error == API_LIMIT_ERROR)
140
+ raise DearInventory::APILimitError.new(error, self)
141
+ end
141
142
 
142
- raise DearInventory::Error.
143
- new("Unknown error (#{http_status}): #{error}")
143
+ raise DearInventory::Error, "Unknown error (#{http_status}): #{error}"
144
144
  end
145
145
 
146
146
  def iterate_over_records(response, block)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DearInventory
4
- VERSION = "1.5.3"
4
+ VERSION = "1.6.0"
5
5
  end
@@ -6,12 +6,12 @@ require "dear_inventory/config"
6
6
  require "dear_inventory/environment"
7
7
 
8
8
  require "dear_inventory/error"
9
- require "dear_inventory/errors/api_limit"
10
9
  require "dear_inventory/errors/no_more_pages"
11
10
  require "dear_inventory/errors/not_paginated"
12
11
  require "dear_inventory/errors/validation"
13
12
 
14
13
  require "dear_inventory/errors/request"
14
+ require "dear_inventory/errors/api_limit"
15
15
  require "dear_inventory/errors/bad_request"
16
16
 
17
17
  require "dear_inventory/lib/endpoint_class"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dear_inventory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Rice