Class: M2X::Client::Resource
- Inherits:
-
Object
- Object
- M2X::Client::Resource
- Extended by:
- Forwardable
- Defined in:
- lib/m2x/resource.rb
Overview
Wrapper for M2X::Client resources
Direct Known Subclasses
Collection, Device, Distribution, Job, Key, Stream
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#delete! ⇒ Object
Delete the resource.
-
#initialize(client, attributes) ⇒ Resource
constructor
A new instance of Resource.
- #inspect ⇒ Object
- #path ⇒ Object
-
#refresh ⇒ Object
Refresh the resource details and return self.
-
#update!(params) ⇒ Object
Update an existing resource details.
-
#view ⇒ Object
Return the resource details.
Constructor Details
#initialize(client, attributes) ⇒ Resource
Returns a new instance of Resource.
11 12 13 14 |
# File 'lib/m2x/resource.rb', line 11 def initialize(client, attributes) @client = client @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/m2x/resource.rb', line 7 def attributes @attributes end |
Instance Method Details
#delete! ⇒ Object
Delete the resource
35 36 37 |
# File 'lib/m2x/resource.rb', line 35 def delete! @client.delete(path) end |
#inspect ⇒ Object
39 40 41 |
# File 'lib/m2x/resource.rb', line 39 def inspect "<#{self.class.name}: #{attributes.inspect}>" end |
#path ⇒ Object
43 44 45 |
# File 'lib/m2x/resource.rb', line 43 def path raise NotImplementedError end |
#refresh ⇒ Object
Refresh the resource details and return self
24 25 26 27 |
# File 'lib/m2x/resource.rb', line 24 def refresh view self end |
#update!(params) ⇒ Object
Update an existing resource details
30 31 32 |
# File 'lib/m2x/resource.rb', line 30 def update!(params) @client.put(path, nil, params, "Content-Type" => "application/json") end |
#view ⇒ Object
Return the resource details
17 18 19 20 21 |
# File 'lib/m2x/resource.rb', line 17 def view res = @client.get(path) @attributes = res.json if res.success? end |