stripe 5.2.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ec1d1414aafc87b63dca172263ecd4666467cda2ab39eaac1abdbd13e7cd90b
4
- data.tar.gz: 3adde22d80c8f867e34d2735dd0aea142f0b69e6cd2a84e13fe7c6a53655ee85
3
+ metadata.gz: d03cea94ef3cacc081d711f3f1fe3bb779791c77e35f4c087ee8c69ffecabb93
4
+ data.tar.gz: a3546067f4fe07f56ab18458691d5261f0a533760da07995dedbd3758259ec18
5
5
  SHA512:
6
- metadata.gz: e4086cfa6bc5281bf1e31e88a2435156d6928716d7022e319afe5845157571731ad260c3728c6bf021d593f11727fa6fdba06c26667d7d5774b6a29cfadf9829
7
- data.tar.gz: 4b6477d988e90607c8ad8c1d8a4a11e3f0afb3494948403d2b6b9e23cde4a6be0dcb9779100306c28449e6d7d24876043edcc2239ab00cdb1dc7fd88942b57de
6
+ metadata.gz: d821b782237ca17e82a770e6a8ec11d97732290af7f06aaae680d0830cc63b523b7e9d8831d96294f4b80a5facb42993bbddb4a27017542fafd3399b3a513aaf
7
+ data.tar.gz: 665f013eec87c9c1b9deac66cec3125a3d6e65920c1d2f45bb509c4b5371222817d6bbe53f7f05406d8f477da061c3d1c3a5e5d94b6047d0d56d3736cf3f710a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.3.0 - 2019-10-01
4
+ * [#853](https://github.com/stripe/stripe-ruby/pull/853) Support `Stripe-Should-Retry` header
5
+
3
6
  ## 5.2.0 - 2019-09-19
4
7
  * [#851](https://github.com/stripe/stripe-ruby/pull/851) Introduce system for garbage collecting connection managers
5
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.2.0
1
+ 5.3.0
@@ -6,7 +6,7 @@ module Stripe
6
6
  # that it's possible to do so from a static context (i.e. without a
7
7
  # pre-existing collection of subresources on the parent).
8
8
  #
9
- # For examle, a transfer gains the static methods for reversals so that the
9
+ # For example, a transfer gains the static methods for reversals so that the
10
10
  # methods `.create_reversal`, `.retrieve_reversal`, `.update_reversal`,
11
11
  # etc. all become available.
12
12
  module NestedResource
@@ -14,9 +14,11 @@ module Stripe
14
14
  resource_plural: nil)
15
15
  resource_plural ||= "#{resource}s"
16
16
  path ||= resource_plural
17
+
17
18
  raise ArgumentError, "operations array required" if operations.nil?
18
19
 
19
20
  resource_url_method = :"#{resource}s_url"
21
+
20
22
  define_singleton_method(resource_url_method) do |id, nested_id = nil|
21
23
  url = "#{resource_url}/#{CGI.escape(id)}/#{CGI.escape(path)}"
22
24
  url += "/#{CGI.escape(nested_id)}" unless nested_id.nil?
@@ -27,39 +29,39 @@ module Stripe
27
29
  case operation
28
30
  when :create
29
31
  define_singleton_method(:"create_#{resource}") \
30
- do |id, params = {}, opts = {}|
31
- url = send(resource_url_method, id)
32
- resp, opts = request(:post, url, params, opts)
33
- Util.convert_to_stripe_object(resp.data, opts)
34
- end
32
+ do |id, params = {}, opts = {}|
33
+ url = send(resource_url_method, id)
34
+ resp, opts = request(:post, url, params, opts)
35
+ Util.convert_to_stripe_object(resp.data, opts)
36
+ end
35
37
  when :retrieve
36
38
  define_singleton_method(:"retrieve_#{resource}") \
37
- do |id, nested_id, opts = {}|
38
- url = send(resource_url_method, id, nested_id)
39
- resp, opts = request(:get, url, {}, opts)
40
- Util.convert_to_stripe_object(resp.data, opts)
41
- end
39
+ do |id, nested_id, opts = {}|
40
+ url = send(resource_url_method, id, nested_id)
41
+ resp, opts = request(:get, url, {}, opts)
42
+ Util.convert_to_stripe_object(resp.data, opts)
43
+ end
42
44
  when :update
43
45
  define_singleton_method(:"update_#{resource}") \
44
- do |id, nested_id, params = {}, opts = {}|
45
- url = send(resource_url_method, id, nested_id)
46
- resp, opts = request(:post, url, params, opts)
47
- Util.convert_to_stripe_object(resp.data, opts)
48
- end
46
+ do |id, nested_id, params = {}, opts = {}|
47
+ url = send(resource_url_method, id, nested_id)
48
+ resp, opts = request(:post, url, params, opts)
49
+ Util.convert_to_stripe_object(resp.data, opts)
50
+ end
49
51
  when :delete
50
52
  define_singleton_method(:"delete_#{resource}") \
51
- do |id, nested_id, params = {}, opts = {}|
52
- url = send(resource_url_method, id, nested_id)
53
- resp, opts = request(:delete, url, params, opts)
54
- Util.convert_to_stripe_object(resp.data, opts)
55
- end
53
+ do |id, nested_id, params = {}, opts = {}|
54
+ url = send(resource_url_method, id, nested_id)
55
+ resp, opts = request(:delete, url, params, opts)
56
+ Util.convert_to_stripe_object(resp.data, opts)
57
+ end
56
58
  when :list
57
59
  define_singleton_method(:"list_#{resource_plural}") \
58
- do |id, params = {}, opts = {}|
59
- url = send(resource_url_method, id)
60
- resp, opts = request(:get, url, params, opts)
61
- Util.convert_to_stripe_object(resp.data, opts)
62
- end
60
+ do |id, params = {}, opts = {}|
61
+ url = send(resource_url_method, id)
62
+ resp, opts = request(:get, url, params, opts)
63
+ Util.convert_to_stripe_object(resp.data, opts)
64
+ end
63
65
  else
64
66
  raise ArgumentError, "Unknown operation: #{operation.inspect}"
65
67
  end
@@ -92,6 +92,12 @@ module Stripe
92
92
  return true if error.is_a?(SocketError)
93
93
 
94
94
  if error.is_a?(Stripe::StripeError)
95
+ # The API may ask us not to retry (e.g. if doing so would be a no-op),
96
+ # or advise us to retry (e.g. in cases of lock timeouts). Defer to
97
+ # those instructions if given.
98
+ return false if error.http_headers["stripe-should-retry"] == "false"
99
+ return true if error.http_headers["stripe-should-retry"] == "true"
100
+
95
101
  # 409 Conflict
96
102
  return true if error.http_status == 409
97
103
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stripe
4
- VERSION = "5.2.0"
4
+ VERSION = "5.3.0"
5
5
  end
@@ -171,6 +171,28 @@ module Stripe
171
171
  method: :post, num_retries: 0)
172
172
  end
173
173
 
174
+ should "retry when the `Stripe-Should-Retry` header is `true`" do
175
+ headers = StripeResponse::Headers.new(
176
+ "Stripe-Should-Retry" => ["true"]
177
+ )
178
+
179
+ # Note we send status 400 here, which would normally not be retried.
180
+ assert StripeClient.should_retry?(Stripe::StripeError.new(http_headers: headers,
181
+ http_status: 400),
182
+ method: :post, num_retries: 0)
183
+ end
184
+
185
+ should "not retry when the `Stripe-Should-Retry` header is `false`" do
186
+ headers = StripeResponse::Headers.new(
187
+ "Stripe-Should-Retry" => ["false"]
188
+ )
189
+
190
+ # Note we send status 409 here, which would normally be retried.
191
+ refute StripeClient.should_retry?(Stripe::StripeError.new(http_headers: headers,
192
+ http_status: 409),
193
+ method: :post, num_retries: 0)
194
+ end
195
+
174
196
  should "retry on a 409 Conflict" do
175
197
  assert StripeClient.should_retry?(Stripe::StripeError.new(http_status: 409),
176
198
  method: :post, num_retries: 0)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-20 00:00:00.000000000 Z
11
+ date: 2019-10-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Stripe is the easiest way to accept payments online. See https://stripe.com
14
14
  for details.