Class: Octobat::APIResource
Direct Known Subclasses
BalanceTransaction, Checkout, Coupon, CreditNote, CreditNoteNumberingSequence, Customer, Document, DocumentEmailTemplate, DocumentLanguage, DocumentTemplate, EmailsSetting, ExportsSetting, Invoice, InvoiceNumberingSequence, Item, PaymentRecipient, PaymentRecipientReference, PaymentSource, Payout, SingletonAPIResource, TaxEvidence, TaxEvidenceRequest, TaxRegionSetting, Transaction
Instance Attribute Summary
#api_key, #parent_obj
Class Method Summary
collapse
Instance Method Summary
collapse
#[], #[]=, #_dump, _load, #as_json, construct_from, #each, #initialize, #inspect, #keys, #refresh_from, #respond_to?, #to_hash, #to_json, #to_s, #values
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Octobat::OctobatObject
Class Method Details
.class_name ⇒ Object
3
4
5
|
# File 'lib/octobat/api_resource.rb', line 3
def self.class_name
self.name.split('::')[-1]
end
|
.retrieve(id, opts = {}) ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/octobat/api_resource.rb', line 26
def self.retrieve(id, opts={})
api_key, = Util.parse_opts(opts)
opts[:api_key] ||= @api_key
instance = self.new(id, opts)
instance.refresh
instance
end
|
.url ⇒ Object
7
8
9
10
11
12
|
# File 'lib/octobat/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 (Invoice, Customer, etc.)')
end
"/#{CGI.escape(class_name.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase)}s"
end
|
Instance Method Details
#refresh ⇒ Object
21
22
23
24
|
# File 'lib/octobat/api_resource.rb', line 21
def refresh
response, api_key = Octobat.request(:get, url, @api_key, @retrieve_options, @headers)
refresh_from(response, api_key)
end
|
#url ⇒ Object
14
15
16
17
18
19
|
# File 'lib/octobat/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
|