Class: M2X::MQTT

Inherits:
Object
  • Object
show all
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.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  @api_key = api_key
  @options = options
end

Instance Attribute Details

#clientObject

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



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

def create_device(attributes)
  M2X::MQTT::Device.create!(client, attributes)
end

#device(id) ⇒ Object



31
32
33
# File 'lib/m2x/mqtt.rb', line 31

def device(id)
  M2X::MQTT::Device.new(client, "id" => id)
end

#distribution(id) ⇒ Object



39
40
41
# File 'lib/m2x/mqtt.rb', line 39

def distribution(id)
  M2X::MQTT::Distribution.new(client, "id" => id)
end

#statusObject

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



43
44
45
# File 'lib/m2x/mqtt.rb', line 43

def stream(device_id, name)
  M2X::MQTT::Stream.new(client, device(device_id), "name" => name)
end