From d946d7a379366b42343efa517dcab5512164974a Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Thu, 14 Dec 2017 16:57:47 +0100 Subject: [PATCH] Use duck typing to detect File-like objects --- lib/stripe/file_upload.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/stripe/file_upload.rb b/lib/stripe/file_upload.rb index f2bd43b4e..983548a40 100644 --- a/lib/stripe/file_upload.rb +++ b/lib/stripe/file_upload.rb @@ -1,5 +1,3 @@ -require "tempfile" - module Stripe class FileUpload < APIResource extend Stripe::APIOperations::Create @@ -20,9 +18,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