stripe-ruby/lib/stripe/file_upload.rb
2017-12-14 19:54:47 +01:00

34 lines
941 B
Ruby

module Stripe
class FileUpload < APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
OBJECT_NAME = "file_upload".freeze
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`-like object with an
# `UploadIO` object if we're given one.
if params[:file] && params[:file].respond_to?(:path) && params[:file].respond_to?(:read)
params[:file] = Faraday::UploadIO.new(params[:file], nil)
end
opts = {
content_type: "multipart/form-data",
}.merge(Util.normalize_opts(opts))
super
end
end
end