Class: Stripe::File

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List
Defined in:
lib/stripe/resources/file.rb

Constant Summary collapse

OBJECT_NAME =
"file".freeze
OBJECT_NAME_ALT =

This resource can have two different object names. In latter API versions, only ‘file` is used, but since stripe-ruby may be used with any API version, we need to support deserializing the older `file_upload` object into the same class.

"file_upload".freeze

Instance Attribute Summary

Attributes inherited from APIResource

#save_with_parent

Class Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods inherited from APIResource

class_name, custom_method, #refresh, #resource_url, retrieve, save_nested_resource

Methods included from APIOperations::Request

included

Methods inherited from StripeObject

#==, #[], #[]=, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #refresh_from, serialize_params, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values

Constructor Details

This class inherits a constructor from Stripe::StripeObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject

Class Method Details

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/stripe/resources/file.rb', line 20

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].is_a?(String)
    unless params[:file].respond_to?(:read)
      raise ArgumentError, "file must respond to `#read`"
    end

    params[:file] = Faraday::UploadIO.new(params[:file], nil)
  end

  opts = {
    api_base: Stripe.uploads_base,
    content_type: "multipart/form-data",
  }.merge(Util.normalize_opts(opts))
  super
end

.resource_urlObject



16
17
18
# File 'lib/stripe/resources/file.rb', line 16

def self.resource_url
  "/v1/files"
end