Class: M2X::MQTT::Resource
- Inherits:
-
Object
- Object
- M2X::MQTT::Resource
- Extended by:
- Forwardable
- Defined in:
- lib/m2x/mqtt/resource.rb
Overview
Wrapper for M2X::Client resources
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#initialize(client, attributes) ⇒ Resource
constructor
A new instance of Resource.
- #inspect ⇒ Object
- #path ⇒ Object
-
#refresh ⇒ Object
Refresh the resource details and return self.
-
#view ⇒ Object
Return the resource details.
Constructor Details
#initialize(client, attributes) ⇒ Resource
Returns a new instance of Resource.
12 13 14 15 |
# File 'lib/m2x/mqtt/resource.rb', line 12 def initialize(client, attributes) @client = client @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/m2x/mqtt/resource.rb', line 8 def attributes @attributes end |
Instance Method Details
#inspect ⇒ Object
17 18 19 |
# File 'lib/m2x/mqtt/resource.rb', line 17 def inspect "<#{self.class.name}: #{attributes.inspect}>" end |
#path ⇒ Object
21 22 23 |
# File 'lib/m2x/mqtt/resource.rb', line 21 def path raise NotImplementedError end |
#refresh ⇒ Object
Refresh the resource details and return self
35 36 37 38 |
# File 'lib/m2x/mqtt/resource.rb', line 35 def refresh view self end |
#view ⇒ Object
Return the resource details
26 27 28 29 30 31 32 |
# File 'lib/m2x/mqtt/resource.rb', line 26 def view @client.get(path) res = @client.get_response @attributes = res["body"] if res["status"] < 300 && res["body"] end |