Skip to content

Commit

Permalink
Use duck typing to detect File-like objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Dec 14, 2017
1 parent be8e4ff commit 630c260
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/stripe/file_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def self.request(method, url, params = {}, opts = {})

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] && [File, Tempfile].any? { |klass| params[:file].is_a?(klass) }
# 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

Expand Down

0 comments on commit 630c260

Please sign in to comment.