Class: Stripe::SingletonAPIResource

Inherits:
APIResource show all
Defined in:
lib/stripe/singleton_api_resource.rb

Direct Known Subclasses

Balance, Tax::Settings

Constant Summary

Constants inherited from APIResource

APIResource::OBJECT_NAME

Constants inherited from StripeObject

Stripe::StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary

Attributes inherited from APIResource

#save_with_parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from APIResource

class_name, custom_method, object_name, #refresh, #request_stripe_object, 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, #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

.resource_urlObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/stripe/singleton_api_resource.rb', line 5

def self.resource_url
  if self == SingletonAPIResource
    raise NotImplementedError,
          "SingletonAPIResource is an abstract class. You should " \
          "perform actions on its subclasses (Balance, etc.)"
  end
  # Namespaces are separated in object names with periods (.) and in URLs
  # with forward slashes (/), so replace the former with the latter.
  "/v1/#{object_name.downcase.tr('.', '/')}"
end

.retrieve(params_or_opts = {}, definitely_opts = nil) ⇒ Object



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

def self.retrieve(params_or_opts = {}, definitely_opts = nil)
  opts = nil
  params = nil
  if definitely_opts.nil?
    unrecognized_key = params_or_opts.keys.find { |k| !Util::OPTS_USER_SPECIFIED.include?(k) }
    if unrecognized_key
      raise ArgumentError,
            "Unrecognized request option: #{unrecognized_key}. Did you mean to specify this as retrieve params? " \
            "If so, you must explicitly pass an opts hash as a second argument. " \
            "For example: .retrieve({#{unrecognized_key}: 'foo'}, {})"
    end

    opts = params_or_opts
  else
    opts = definitely_opts
    params = params_or_opts
  end

  instance = new(params, Util.normalize_opts(opts))
  instance.refresh
  instance
end

Instance Method Details

#resource_urlObject



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

def resource_url
  self.class.resource_url
end