Class: Stripe::FileService

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

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.



9
10
11
12
13
14
15
16
17
# File 'lib/stripe/services/file_service.rb', line 9

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.



20
21
22
# File 'lib/stripe/services/file_service.rb', line 20

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).



25
26
27
28
29
30
31
32
33
# File 'lib/stripe/services/file_service.rb', line 25

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