Class: BillerBotResource::Resource
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- BillerBotResource::Resource
- Defined in:
- lib/biller_bot_resource/resource.rb
Direct Known Subclasses
Account, Invoice, Invoice::Status, LineItem, Location, Organization, Product, Product::Context, User
Class Method Summary collapse
- .config ⇒ Object
-
.configure {|config| ... } ⇒ Object
Allow the resource to be configured via block style.
- .instantiate_collection(collection, prefix_options = {}) ⇒ Object
-
.query_string(options) ⇒ Object
Append the auth token to all of our queries.
Instance Method Summary collapse
- #cache_key ⇒ Object
-
#initialize(attributes = {}, persisted = false) ⇒ Resource
constructor
A new instance of Resource.
- #save(*args) ⇒ Object
Constructor Details
#initialize(attributes = {}, persisted = false) ⇒ Resource
Returns a new instance of Resource.
44 45 46 47 |
# File 'lib/biller_bot_resource/resource.rb', line 44 def initialize(attributes = {}, persisted = false) attributes = enrich_attributes(attributes) super(attributes, persisted) end |
Class Method Details
.config ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/biller_bot_resource/resource.rb', line 16 def self.config if defined?(@config) @config elsif superclass != ActiveResource::Base && superclass.respond_to?(:config) && !superclass.config.nil? superclass.config else @config = BillerBotResource::Configuration.new @config end end |
.configure {|config| ... } ⇒ Object
Allow the resource to be configured via block style.
8 9 10 11 12 13 14 |
# File 'lib/biller_bot_resource/resource.rb', line 8 def self.configure yield config self.site = config.site self.logger = config.logger if config.logger self.timeout = config.timeout end |
.instantiate_collection(collection, prefix_options = {}) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/biller_bot_resource/resource.rb', line 36 def self.instantiate_collection(collection, = {}) return super if collection.is_a? Array remote_collection = [] remote_collection.concat super(collection["results"], ) # TODO: Add additional keys to the remote collection remote_collection end |
.query_string(options) ⇒ Object
Append the auth token to all of our queries. The easiest way to do this is to override the query string method and inject it.
30 31 32 33 34 |
# File 'lib/biller_bot_resource/resource.rb', line 30 def self.query_string() ||= {} [:auth_token] = config.api_key super() end |
Instance Method Details
#cache_key ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/biller_bot_resource/resource.rb', line 55 def cache_key case when new_record? "#{self.class.name}/new" when = @attributes[:updated_at] = .utc.to_s(:number) "#{self.class.name}/#{id}-#{}" else "#{self.class.name}/#{id}" end end |
#save(*args) ⇒ Object
49 50 51 52 53 |
# File 'lib/biller_bot_resource/resource.rb', line 49 def save(*args) @attributes.delete :created_at @attributes.delete :updated_at super end |