Class: GifterHub::ApiResource
- Inherits:
-
Object
- Object
- GifterHub::ApiResource
- Includes:
- Operations::Get
- Defined in:
- lib/gifter_hub/api_resource.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#id ⇒ Object
Returns the value of attribute id.
-
#opts ⇒ Object
Returns the value of attribute opts.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id = nil, opts = {}) ⇒ ApiResource
constructor
A new instance of ApiResource.
- #inspect ⇒ Object
- #refresh ⇒ Object
- #resource_url ⇒ Object
Methods included from Operations::Get
Constructor Details
#initialize(id = nil, opts = {}) ⇒ ApiResource
Returns a new instance of ApiResource.
6 7 8 9 10 11 |
# File 'lib/gifter_hub/api_resource.rb', line 6 def initialize(id=nil, opts={}) @id = id @opts = opts @values = {} @attributes = {} end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/gifter_hub/api_resource.rb', line 4 def attributes @attributes end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/gifter_hub/api_resource.rb', line 4 def id @id end |
#opts ⇒ Object
Returns the value of attribute opts.
4 5 6 |
# File 'lib/gifter_hub/api_resource.rb', line 4 def opts @opts end |
Class Method Details
.class_name ⇒ Object
13 14 15 |
# File 'lib/gifter_hub/api_resource.rb', line 13 def self.class_name self.name.split('::')[-1] end |
.get(id, opts = {}) ⇒ Object
24 25 26 27 28 |
# File 'lib/gifter_hub/api_resource.rb', line 24 def self.get(id, opts={}) instance = self.new(id, opts) instance.refresh instance end |
.resource_url ⇒ Object
17 18 19 20 21 22 |
# File 'lib/gifter_hub/api_resource.rb', line 17 def self.resource_url if self == ApiResource raise NotImplementedError end "/api/#{CGI.escape(class_name.tableize)}" end |
Instance Method Details
#inspect ⇒ Object
30 31 32 |
# File 'lib/gifter_hub/api_resource.rb', line 30 def inspect JSON.pretty_generate(attributes) end |
#refresh ⇒ Object
38 39 40 41 |
# File 'lib/gifter_hub/api_resource.rb', line 38 def refresh response = request(:get, resource_url, opts) initialize_from(response, opts) end |
#resource_url ⇒ Object
34 35 36 |
# File 'lib/gifter_hub/api_resource.rb', line 34 def resource_url "#{self.class.resource_url}/#{CGI.escape(id)}" end |