Class: Chargify2::Resource
- Inherits:
-
Object
- Object
- Chargify2::Resource
- Includes:
- HTTParty
- Defined in:
- lib/chargify2/resource.rb
Overview
Resource orchestrates the connection from the Client to the Chargify API Resources, available at the Resource URIs.
Resource implements CRUD operations on the Chargify API Resources: Resource.create, Resource.read, Resource.update, Resource.delete, and Resource.list.
Direct Known Subclasses
Class Method Summary collapse
- .path(resource_path = nil) ⇒ Object
- .read(id, query = {}, options = {}) ⇒ Object
-
.representation(klass = nil) ⇒ Object
Define the representation class for this resource.
Instance Method Summary collapse
-
#initialize(client) ⇒ Resource
constructor
A new instance of Resource.
- #read(id, query = {}, options = {}) ⇒ Object
Constructor Details
#initialize(client) ⇒ Resource
Returns a new instance of Resource.
29 30 31 32 33 |
# File 'lib/chargify2/resource.rb', line 29 def initialize(client) @client = client @base_uri = client.base_uri @auth = {:username => client.api_id, :password => client.api_password} end |
Class Method Details
.path(resource_path = nil) ⇒ Object
16 17 18 19 |
# File 'lib/chargify2/resource.rb', line 16 def self.path(resource_path = nil) return @path unless resource_path @path = resource_path end |
.read(id, query = {}, options = {}) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/chargify2/resource.rb', line 35 def self.read(id, query = {}, = {}) .merge!(:query => query.empty? ? nil : query) response = get("/#{path}/#{id}", ) response_hash = response[representation.to_s.downcase.split('::').last] || {} representation.new(response_hash.recursive_symbolize_keys) end |
.representation(klass = nil) ⇒ Object
Define the representation class for this resource
22 23 24 25 26 27 |
# File 'lib/chargify2/resource.rb', line 22 def self.representation(klass = nil) unless klass.nil? @@representation = klass end @@representation ||= nil end |
Instance Method Details
#read(id, query = {}, options = {}) ⇒ Object
43 44 45 |
# File 'lib/chargify2/resource.rb', line 43 def read(id, query = {}, = {}) self.class.read(id, query, ()) end |