Class: M2X::MQTT::Resource

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/m2x/mqtt/resource.rb

Overview

Wrapper for M2X::Client resources

Direct Known Subclasses

Command, Device, Distribution, Stream

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject (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

#inspectObject



17
18
19
# File 'lib/m2x/mqtt/resource.rb', line 17

def inspect
  "<#{self.class.name}: #{attributes.inspect}>"
end

#pathObject

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/m2x/mqtt/resource.rb', line 21

def path
  raise NotImplementedError
end

#refreshObject

Refresh the resource details and return self



35
36
37
38
# File 'lib/m2x/mqtt/resource.rb', line 35

def refresh
  view
  self
end

#viewObject

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