Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,34 +219,14 @@ def initialize
# will throw away the result of this encoder and build its body.
def encode(hash)
@cache.fetch(hash) do |k|
@cache[k] = Util.encode_parameters(replace_faraday_io(hash))
@cache[k] = Util.encode_parameters(hash)
end
end

# We should never need to do this so it's not implemented.
def decode(_str)
raise NotImplementedError, "#{self.class.name} does not implement #decode"
end

# Replaces instances of `Faraday::UploadIO` with a simple string
# representation so that they'll log a little better. Faraday won't use
# these parameters, so it's okay that we did this.
#
# Unfortunately the string representation still doesn't look very nice
# because we still URL-encode special symbols in the final value. It's
# possible we could stop doing this and just leave it to Faraday to do
# the right thing.
private def replace_faraday_io(value)
if value.is_a?(Array)
value.each_with_index { |v, i| value[i] = replace_faraday_io(v) }
elsif value.is_a?(Hash)
value.each { |k, v| value[k] = replace_faraday_io(v) }
elsif value.is_a?(Faraday::UploadIO)
"FILE:#{value.original_filename}"
else
value
end
end
end

def api_url(url = "", api_base = nil)
Expand Down
10 changes: 0 additions & 10 deletions test/stripe/stripe_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -794,16 +794,6 @@ class StripeClientTest < Test::Unit::TestCase
assert(!trace_payload["last_request_metrics"]["request_duration_ms"].nil?)
end
end

context "FaradayStripeEncoder" do
should "replace Faraday::UploadIO instances in parameters" do
encoder = StripeClient::FaradayStripeEncoder.new
encoded = encoder.encode(foo: [
{ file: Faraday::UploadIO.new(::File.new(__FILE__), nil) },
])
assert_equal "foo[0][file]=FILE%3Astripe_client_test.rb", encoded
end
end
end

class SystemProfilerTest < Test::Unit::TestCase
Expand Down