Class: Stripe::APIResource

Inherits:
StripeObject show all
Defined in:
lib/stripe/api_resource.rb

Direct Known Subclasses

Charge, Coupon, Customer, Event, Invoice, InvoiceItem, Plan, SingletonAPIResource, Token, Transfer

Instance Attribute Summary

Attributes inherited from StripeObject

#api_key

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from StripeObject

#[], #[]=, #as_json, construct_from, #each, #initialize, #inspect, #keys, #refresh_from, #to_hash, #to_json, #to_s, #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

+ (Object) class_name



3
4
5
# File 'lib/stripe/api_resource.rb', line 3

def self.class_name
  self.name.split('::')[-1]
end

+ (Object) retrieve(id, api_key = nil)



27
28
29
30
31
# File 'lib/stripe/api_resource.rb', line 27

def self.retrieve(id, api_key=nil)
  instance = self.new(id, api_key)
  instance.refresh
  instance
end

+ (Object) url



7
8
9
10
11
12
# File 'lib/stripe/api_resource.rb', line 7

def self.url()
  if self == APIResource
    raise NotImplementedError.new('APIResource is an abstract class.  You should perform actions on its subclasses (Charge, Customer, etc.)')
  end
  "/v1/#{CGI.escape(class_name.downcase)}s"
end

Instance Method Details

- (Object) refresh



21
22
23
24
25
# File 'lib/stripe/api_resource.rb', line 21

def refresh
  response, api_key = Stripe.request(:get, url, @api_key, @retrieve_options)
  refresh_from(response, api_key)
  self
end

- (Object) url



14
15
16
17
18
19
# File 'lib/stripe/api_resource.rb', line 14

def url
  unless id = self['id']
    raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}", 'id')
  end
  "#{self.class.url}/#{CGI.escape(id)}"
end