mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-06-02 00:00:35 -04:00
As described in #506, file uploads were broken on the way over to Faraday and unfortunately I didn't catch it because the file upload creation test wasn't using a matcher that was strict enough to really catch anything. Here we add the multipart middleware to our Faraday connection, add a compatibility layer to `FileUpload` so that we can support `File` like the rest-client based version always did (Faraday generally expects an `UploadIO` object), and then tighten up our tests so that we'd be able to catch future regressions. Fixes #506.
32 lines
844 B
Ruby
32 lines
844 B
Ruby
module Stripe
|
|
class FileUpload < APIResource
|
|
extend Stripe::APIOperations::Create
|
|
extend Stripe::APIOperations::List
|
|
|
|
def self.resource_url
|
|
"/v1/files"
|
|
end
|
|
|
|
def self.request(method, url, params={}, opts={})
|
|
opts = {
|
|
:api_base => Stripe::uploads_base
|
|
}.merge(Util.normalize_opts(opts))
|
|
super
|
|
end
|
|
|
|
def self.create(params={}, opts={})
|
|
# rest-client would accept a vanilla `File` for upload, but Faraday does
|
|
# not. Support the old API by wrapping a `File` with an `UploadIO` object
|
|
# if we're given one.
|
|
if params[:file] && params[:file].is_a?(File)
|
|
params[:file] = Faraday::UploadIO.new(params[:file], nil)
|
|
end
|
|
|
|
opts = {
|
|
:content_type => 'multipart/form-data',
|
|
}.merge(Util.normalize_opts(opts))
|
|
super
|
|
end
|
|
end
|
|
end
|