stripe 4.7.1 → 4.8.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/.rubocop_todo.yml +2 -2
- data/CHANGELOG.md +3 -0
- data/VERSION +1 -1
- data/lib/stripe/stripe_client.rb +50 -18
- data/lib/stripe/version.rb +1 -1
- data/test/stripe/stripe_client_test.rb +10 -0
- 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: 2f7c24b1f5de9f966aeec73391ac6153cb4c3b44f720c89839b163b3a2d46c4e
|
4
|
+
data.tar.gz: 79ec62aece03a2a98858749d1aaff4fc198b130dbd409a18fd7ba2903322d7c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53be26caee7e296440f78b10e83b87d7ab5e7346932a670b35a92be9bcba9e436812f47e32fc098db76edaada9acde75dcfdc8547d51769a2679609578d32ef5
|
7
|
+
data.tar.gz: f1787c95d33004299cf40f469e793ca8af8072b7243ece7addb581056250f15dba338d8f000b2116623075382b031e79c08d4645fb478d7a9d1df342c27683bd
|
data/.rubocop_todo.yml
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
# Offense count: 19
|
10
10
|
Metrics/AbcSize:
|
11
|
-
Max:
|
11
|
+
Max: 54
|
12
12
|
|
13
13
|
# Offense count: 27
|
14
14
|
# Configuration parameters: CountComments, ExcludedMethods.
|
@@ -18,7 +18,7 @@ Metrics/BlockLength:
|
|
18
18
|
# Offense count: 8
|
19
19
|
# Configuration parameters: CountComments.
|
20
20
|
Metrics/ClassLength:
|
21
|
-
Max:
|
21
|
+
Max: 670
|
22
22
|
|
23
23
|
# Offense count: 11
|
24
24
|
Metrics/CyclomaticComplexity:
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 4.8.0 - 2019-02-03
|
4
|
+
* [#741](https://github.com/stripe/stripe-ruby/pull/741) Use `FaradayStripeEncoder` to encode all parameter styles
|
5
|
+
|
3
6
|
## 4.7.1 - 2019-02-01
|
4
7
|
* [#740](https://github.com/stripe/stripe-ruby/pull/740) Fix query encoding for integer-indexed maps
|
5
8
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.
|
1
|
+
4.8.0
|
data/lib/stripe/stripe_client.rb
CHANGED
@@ -123,24 +123,17 @@ module Stripe
|
|
123
123
|
api_base: nil, api_key: nil, headers: {}, params: {})
|
124
124
|
api_base ||= Stripe.api_base
|
125
125
|
api_key ||= Stripe.api_key
|
126
|
+
params = Util.objects_to_ids(params)
|
126
127
|
|
127
128
|
check_api_key!(api_key)
|
128
129
|
|
129
|
-
params = Util.objects_to_ids(params)
|
130
|
-
url = api_url(path, api_base)
|
131
|
-
|
132
130
|
body = nil
|
133
131
|
query_params = nil
|
134
|
-
|
135
132
|
case method.to_s.downcase.to_sym
|
136
133
|
when :get, :head, :delete
|
137
134
|
query_params = params
|
138
135
|
else
|
139
|
-
body =
|
140
|
-
params
|
141
|
-
else
|
142
|
-
Util.encode_parameters(params)
|
143
|
-
end
|
136
|
+
body = params
|
144
137
|
end
|
145
138
|
|
146
139
|
# This works around an edge case where we end up with both query
|
@@ -162,6 +155,8 @@ module Stripe
|
|
162
155
|
|
163
156
|
headers = request_headers(api_key, method)
|
164
157
|
.update(Util.normalize_headers(headers))
|
158
|
+
params_encoder = FaradayStripeEncoder.new
|
159
|
+
url = api_url(path, api_base)
|
165
160
|
|
166
161
|
# stores information on the request we're about to make so that we don't
|
167
162
|
# have to pass as many parameters around for logging.
|
@@ -169,19 +164,19 @@ module Stripe
|
|
169
164
|
context.account = headers["Stripe-Account"]
|
170
165
|
context.api_key = api_key
|
171
166
|
context.api_version = headers["Stripe-Version"]
|
172
|
-
context.body = body
|
167
|
+
context.body = body ? params_encoder.encode(body) : nil
|
173
168
|
context.idempotency_key = headers["Idempotency-Key"]
|
174
169
|
context.method = method
|
175
170
|
context.path = path
|
176
|
-
context.query_params = query_params ?
|
171
|
+
context.query_params = query_params ? params_encoder.encode(query_params) : nil
|
177
172
|
|
173
|
+
# note that both request body and query params will be passed through
|
174
|
+
# `FaradayStripeEncoder`
|
178
175
|
http_resp = execute_request_with_rescues(api_base, context) do
|
179
176
|
conn.run_request(method, url, body, headers) do |req|
|
180
177
|
req.options.open_timeout = Stripe.open_timeout
|
181
|
-
req.options.params_encoder =
|
178
|
+
req.options.params_encoder = params_encoder
|
182
179
|
req.options.timeout = Stripe.read_timeout
|
183
|
-
|
184
|
-
# note that these will be passed through `FaradayStripeEncoder`
|
185
180
|
req.params = query_params unless query_params.nil?
|
186
181
|
end
|
187
182
|
end
|
@@ -205,16 +200,53 @@ module Stripe
|
|
205
200
|
# -- in particular when we send our integer-indexed maps (i.e. arrays),
|
206
201
|
# Faraday ends up stripping out the integer indexes.
|
207
202
|
#
|
208
|
-
# We work around the problem by implementing our own simplified
|
203
|
+
# We work around the problem by implementing our own simplified encoder and
|
209
204
|
# telling Faraday to use that.
|
205
|
+
#
|
206
|
+
# The class also performs simple caching so that we don't have to encode
|
207
|
+
# parameters twice for every request (once to build the request and once
|
208
|
+
# for logging).
|
209
|
+
#
|
210
|
+
# When initialized with `multipart: true`, the encoder just inspects the
|
211
|
+
# hash instead to get a decent representation for logging. In the case of a
|
212
|
+
# multipart request, Faraday won't use the result of this encoder.
|
210
213
|
class FaradayStripeEncoder
|
211
|
-
def
|
212
|
-
|
214
|
+
def initialize
|
215
|
+
@cache = {}
|
213
216
|
end
|
214
217
|
|
215
|
-
|
218
|
+
# This is quite subtle, but for a `multipart/form-data` request Faraday
|
219
|
+
# will throw away the result of this encoder and build its body.
|
220
|
+
def encode(hash)
|
221
|
+
@cache.fetch(hash) do |k|
|
222
|
+
@cache[k] = Util.encode_parameters(replace_faraday_io(hash))
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
# We should never need to do this so it's not implemented.
|
227
|
+
def decode(_str)
|
216
228
|
raise NotImplementedError, "#{self.class.name} does not implement #decode"
|
217
229
|
end
|
230
|
+
|
231
|
+
# Replaces instances of `Faraday::UploadIO` with a simple string
|
232
|
+
# representation so that they'll log a little better. Faraday won't use
|
233
|
+
# these parameters, so it's okay that we did this.
|
234
|
+
#
|
235
|
+
# Unfortunately the string representation still doesn't look very nice
|
236
|
+
# because we still URL-encode special symbols in the final value. It's
|
237
|
+
# possible we could stop doing this and just leave it to Faraday to do
|
238
|
+
# the right thing.
|
239
|
+
private def replace_faraday_io(value)
|
240
|
+
if value.is_a?(Array)
|
241
|
+
value.each_with_index { |v, i| value[i] = replace_faraday_io(v) }
|
242
|
+
elsif value.is_a?(Hash)
|
243
|
+
value.each { |k, v| value[k] = replace_faraday_io(v) }
|
244
|
+
elsif value.is_a?(Faraday::UploadIO)
|
245
|
+
"FILE:#{value.original_filename}"
|
246
|
+
else
|
247
|
+
value
|
248
|
+
end
|
249
|
+
end
|
218
250
|
end
|
219
251
|
|
220
252
|
def api_url(url = "", api_base = nil)
|
data/lib/stripe/version.rb
CHANGED
@@ -794,6 +794,16 @@ module Stripe
|
|
794
794
|
assert(!trace_payload["last_request_metrics"]["request_duration_ms"].nil?)
|
795
795
|
end
|
796
796
|
end
|
797
|
+
|
798
|
+
context "FaradayStripeEncoder" do
|
799
|
+
should "replace Faraday::UploadIO instances in parameters" do
|
800
|
+
encoder = StripeClient::FaradayStripeEncoder.new
|
801
|
+
encoded = encoder.encode(foo: [
|
802
|
+
{ file: Faraday::UploadIO.new(::File.new(__FILE__), nil) },
|
803
|
+
])
|
804
|
+
assert_equal "foo[0][file]=FILE%3Astripe_client_test.rb", encoded
|
805
|
+
end
|
806
|
+
end
|
797
807
|
end
|
798
808
|
|
799
809
|
class SystemProfilerTest < Test::Unit::TestCase
|
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: 4.
|
4
|
+
version: 4.8.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-02-
|
11
|
+
date: 2019-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|