Class: M2X::MQTT::Stream
Overview
Wrapper for AT&T M2X Data Streams API m2x.att.com/developer/documentation/v2/device
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#initialize(client, device, attributes) ⇒ Stream
constructor
A new instance of Stream.
- #path ⇒ Object
-
#post_values(values) ⇒ Object
Post multiple values to the stream.
-
#update!(params = {}) ⇒ Object
Update stream properties (if the stream does not exist it gets created).
-
#update_value(value, timestamp = nil) ⇒ Object
Update the current value of the stream.
Methods inherited from Resource
Constructor Details
#initialize(client, device, attributes) ⇒ Stream
Returns a new instance of Stream.
5 6 7 8 9 |
# File 'lib/m2x/mqtt/stream.rb', line 5 def initialize(client, device, attributes) @client = client @device = device @attributes = attributes end |
Instance Method Details
#path ⇒ Object
11 12 13 |
# File 'lib/m2x/mqtt/stream.rb', line 11 def path @path ||= "#{@device.path}/streams/#{ URI.encode(@attributes.fetch("name")) }" end |
#post_values(values) ⇒ Object
Post multiple values to the stream
The ‘values` parameter is an array with the following format:
[
{ "timestamp": <Time in ISO8601>, "value": x },
{ "timestamp": <Time in ISO8601>, "value": y },
[ ... ]
]
m2x.att.com/developer/documentation/v2/device#Post-Data-Stream-Values
48 49 50 51 52 |
# File 'lib/m2x/mqtt/stream.rb', line 48 def post_values(values) params = { values: values } @client.post("#{path}/values", params) end |
#update!(params = {}) ⇒ Object
Update stream properties (if the stream does not exist it gets created).
m2x.att.com/developer/documentation/v2/device#Create-Update-Data-Stream
19 20 21 22 23 |
# File 'lib/m2x/mqtt/stream.rb', line 19 def update!(params={}) @client.put(path, params) @attributes.merge!(params) end |
#update_value(value, timestamp = nil) ⇒ Object
Update the current value of the stream. The timestamp is optional. If ommited, the current server time will be used
m2x.att.com/developer/documentation/v2/device#Update-Data-Stream-Value
29 30 31 32 33 34 35 |
# File 'lib/m2x/mqtt/stream.rb', line 29 def update_value(value, =nil) params = { value: value } params[:timestamp] = if @client.put("#{path}/value", params) end |