Class: Stripe::FileService

Inherits:
StripeService show all
Defined in:
lib/stripe/services/file_service.rb

Defined Under Namespace

Classes: CreateParams, ListParams, RetrieveParams

Instance Method Summary collapse

Methods inherited from StripeService

#initialize, #request, #request_stream

Constructor Details

This class inherits a constructor from Stripe::StripeService

Instance Method Details

#create(params = {}, opts = {}) ⇒ Object

To upload a file to Stripe, you need to send a request of type multipart/form-data. Include the file you want to upload in the request, and the parameters for creating a file.

All of Stripe’s officially supported Client libraries support sending multipart/form-data.



111
112
113
114
115
116
117
118
119
# File 'lib/stripe/services/file_service.rb', line 111

def create(params = {}, opts = {})
  if params[:file] && !params[:file].is_a?(String) && !params[:file].respond_to?(:read)
    raise ArgumentError, "file must respond to `#read`"
  end

  opts = { content_type: MultipartEncoder::MULTIPART_FORM_DATA }.merge(Util.normalize_opts(opts))

  request(method: :post, path: "/v1/files", params: params, opts: opts, base_address: :files)
end

#list(params = {}, opts = {}) ⇒ Object

Returns a list of the files that your account has access to. Stripe sorts and returns the files by their creation dates, placing the most recently created files at the top.



122
123
124
# File 'lib/stripe/services/file_service.rb', line 122

def list(params = {}, opts = {})
  request(method: :get, path: "/v1/files", params: params, opts: opts, base_address: :api)
end

#retrieve(file, params = {}, opts = {}) ⇒ Object

Retrieves the details of an existing file object. After you supply a unique file ID, Stripe returns the corresponding file object. Learn how to [access file contents](stripe.com/docs/file-upload#download-file-contents).



127
128
129
130
131
132
133
134
135
# File 'lib/stripe/services/file_service.rb', line 127

def retrieve(file, params = {}, opts = {})
  request(
    method: :get,
    path: format("/v1/files/%<file>s", { file: CGI.escape(file) }),
    params: params,
    opts: opts,
    base_address: :api
  )
end