Class: M2X::MQTT
- Inherits:
-
Object
- Object
- M2X::MQTT
- Defined in:
- lib/m2x/mqtt.rb,
lib/m2x/mqtt/version.rb
Defined Under Namespace
Classes: Client, Command, Device, Distribution, Resource, Stream
Constant Summary collapse
- VERSION =
"0.3.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.
14 15 16 17 |
# File 'lib/m2x/mqtt.rb', line 14 def initialize(api_key, ={}) @api_key = api_key @options = end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
12 13 14 |
# File 'lib/m2x/mqtt.rb', line 12 def client @client end |
Instance Method Details
#create_device(attributes) ⇒ Object
43 44 45 |
# File 'lib/m2x/mqtt.rb', line 43 def create_device(attributes) M2X::MQTT::Device.create!(client, attributes) end |
#device(id) ⇒ Object
39 40 41 |
# File 'lib/m2x/mqtt.rb', line 39 def device(id) M2X::MQTT::Device.new(client, "id" => id) end |
#distribution(id) ⇒ Object
47 48 49 |
# File 'lib/m2x/mqtt.rb', line 47 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.
27 28 29 30 31 |
# File 'lib/m2x/mqtt.rb', line 27 def status client.subscribe client.get("/status") client.get_response end |
#stream(device_id, name) ⇒ Object
51 52 53 |
# File 'lib/m2x/mqtt.rb', line 51 def stream(device_id, name) M2X::MQTT::Stream.new(client, device(device_id), "name" => name) end |
#time ⇒ Object
33 34 35 36 37 |
# File 'lib/m2x/mqtt.rb', line 33 def time client.subscribe client.get("/time") client.get_response["body"] end |