Class: M2X::MQTT
- Inherits:
-
Object
- Object
- M2X::MQTT
- Defined in:
- lib/m2x/mqtt.rb,
lib/m2x/mqtt/version.rb
Defined Under Namespace
Classes: Client, Device, Distribution, Resource, Stream
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #create_device(attributes) ⇒ Object
- #device(id) ⇒ Object
- #distribution(id) ⇒ Object
-
#initialize(api_key, options = {}) ⇒ MQTT
constructor
A new instance of MQTT.
-
#status ⇒ Object
Returns the status of the M2X system.
- #stream(device_id, name) ⇒ Object
- #time ⇒ Object
Constructor Details
#initialize(api_key, options = {}) ⇒ MQTT
Returns a new instance of MQTT.
12 13 14 15 |
# File 'lib/m2x/mqtt.rb', line 12 def initialize(api_key, ={}) @api_key = api_key @options = end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
10 11 12 |
# File 'lib/m2x/mqtt.rb', line 10 def client @client end |
Instance Method Details
#create_device(attributes) ⇒ Object
41 42 43 |
# File 'lib/m2x/mqtt.rb', line 41 def create_device(attributes) M2X::MQTT::Device.create!(client, attributes) end |
#device(id) ⇒ Object
37 38 39 |
# File 'lib/m2x/mqtt.rb', line 37 def device(id) M2X::MQTT::Device.new(client, "id" => id) end |
#distribution(id) ⇒ Object
45 46 47 |
# File 'lib/m2x/mqtt.rb', line 45 def distribution(id) M2X::MQTT::Distribution.new(client, "id" => id) end |
#status ⇒ Object
Returns the status of the M2X system.
The response to this endpoint is an object in which each of its attributes represents an M2X subsystem and its current status.
25 26 27 28 29 |
# File 'lib/m2x/mqtt.rb', line 25 def status client.subscribe client.get("/status") client.get_response end |
#stream(device_id, name) ⇒ Object
49 50 51 |
# File 'lib/m2x/mqtt.rb', line 49 def stream(device_id, name) M2X::MQTT::Stream.new(client, device(device_id), "name" => name) end |
#time ⇒ Object
31 32 33 34 35 |
# File 'lib/m2x/mqtt.rb', line 31 def time client.subscribe client.get("/time") client.get_response["body"] end |