Class: JSON_ROA::Client::Resource
- Inherits:
-
Object
- Object
- JSON_ROA::Client::Resource
- Defined in:
- lib/json_roa/client/resource.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #collection ⇒ Object
- #data ⇒ Object
-
#initialize(conn, response = nil) ⇒ Resource
constructor
A new instance of Resource.
- #json_roa_data ⇒ Object
- #relation(key) ⇒ Object
- #self_relation ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(conn, response = nil) ⇒ Resource
Returns a new instance of Resource.
11 12 13 14 |
# File 'lib/json_roa/client/resource.rb', line 11 def initialize(conn, response = nil) @conn = conn @response = response || conn.get end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
9 10 11 |
# File 'lib/json_roa/client/resource.rb', line 9 def response @response end |
Instance Method Details
#collection ⇒ Object
34 35 36 |
# File 'lib/json_roa/client/resource.rb', line 34 def collection ::JSON_ROA::Client::Collection.new @conn, self end |
#data ⇒ Object
26 27 28 |
# File 'lib/json_roa/client/resource.rb', line 26 def data @response.body end |
#json_roa_data ⇒ Object
30 31 32 |
# File 'lib/json_roa/client/resource.rb', line 30 def json_roa_data @response.env.json_roa_data end |
#relation(key) ⇒ Object
16 17 18 19 |
# File 'lib/json_roa/client/resource.rb', line 16 def relation(key) relhash = json_roa_data['relations'][key] ::JSON_ROA::Client::Relation.new @conn, key, relhash end |
#self_relation ⇒ Object
21 22 23 24 |
# File 'lib/json_roa/client/resource.rb', line 21 def self_relation ::JSON_ROA::Client::Relation.new( \ @conn, 'self', json_roa_data['self_relation']) rescue nil end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/json_roa/client/resource.rb', line 38 def to_s "#{self.class.name}: #{data} #{json_roa_data}" end |