Class: RIQ::RIQObject Abstract
- Inherits:
-
Object
- Object
- RIQ::RIQObject
- Defined in:
- lib/riq/riq_obj.rb
Overview
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#modified_date ⇒ Object
readonly
Returns the value of attribute modified_date.
Class Method Summary collapse
-
.node(id = nil) ⇒ String
Endpoint.
Instance Method Summary collapse
-
#data ⇒ Hash
All relevant stored data.
-
#delete ⇒ Object
Deletes the object.
-
#initialize(id = nil) ⇒ RIQObject
constructor
Self.
-
#node ⇒ String
Endpoint.
-
#payload ⇒ String
The JSON representation of #data.
-
#save(options = nil) ⇒ Object
Creates or updates the object.
Constructor Details
#initialize(id = nil) ⇒ RIQObject
Returns Self.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/riq/riq_obj.rb', line 13 def initialize(id = nil) @client = RIQ.client @id = id unless @id.nil? # data hash if @id.is_a? Hash # this looks dumb, could name variables better data = @id else data = @client.get(node) end init(data.symbolize) else init end self end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/riq/riq_obj.rb', line 8 def id @id end |
#modified_date ⇒ Object (readonly)
Returns the value of attribute modified_date.
9 10 11 |
# File 'lib/riq/riq_obj.rb', line 9 def modified_date @modified_date end |
Class Method Details
.node(id = nil) ⇒ String
Returns endpoint.
39 40 41 |
# File 'lib/riq/riq_obj.rb', line 39 def self.node(id = nil) raise RIQError, 'This should be overwritten' end |
Instance Method Details
#data ⇒ Hash
Returns all relevant stored data.
44 45 46 |
# File 'lib/riq/riq_obj.rb', line 44 def data raise RIQError, 'This should be overwritten' end |
#delete ⇒ Object
Note:
This is IRREVERSIBLE
Deletes the object
75 76 77 |
# File 'lib/riq/riq_obj.rb', line 75 def delete @client.delete(node) end |
#node ⇒ String
Returns endpoint.
33 34 35 |
# File 'lib/riq/riq_obj.rb', line 33 def node raise RIQError, 'This should be overwritten' end |
#payload ⇒ String
Returns the JSON representation of #data.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/riq/riq_obj.rb', line 49 def payload pld = {} data.each do |k, v| if k['_'] pld[k.to_cam] = v else pld[k] = v end end pld.to_json end |
#save(options = nil) ⇒ Object
Creates or updates the object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/riq/riq_obj.rb', line 62 def save( = nil) pre_save if @id.nil? # create init(@client.post(node, payload, options: ).symbolize) else # update init(@client.put(node, payload, options: ).symbolize) end end |