class SensorStream::Device
Implementation of the device class
Attributes
Each of the qualities of a device are immutable. The sensor stream API does not support changing device attributes.
Each of the qualities of a device are immutable. The sensor stream API does not support changing device attributes.
Each of the qualities of a device are immutable. The sensor stream API does not support changing device attributes.
It is possible to change the streams and assign a key later, however.
It is possible to change the streams and assign a key later, however.
Each of the qualities of a device are immutable. The sensor stream API does not support changing device attributes.
Public Class Methods
Initialize a new SensorStream
device object
# File lib/SensorStream.rb, line 156 def initialize(newID, newUserName, newDeviceName, newDescription, newStreams = [], newKey = "") @id = newID @key = newKey @device_name = newDeviceName @user_name = newUserName @description = newDescription @streams = newStreams end
Public Instance Methods
# File lib/SensorStream.rb, line 207 def get_stream_by_id(id, key = "") if key.empty? resp = SensorStream.make_http_get("/api/GetStream/" + id, {}) else resp = SensorStream.make_http_get("/api/GetStream/" + id + "?key=" + key, {}) end if (resp.code != "200") puts "Unable to get a response from SensorStream: " + resp.code return nil else strms = [] json = JSON.parse(resp.body) puts json["Streams"].count.to_s + " streams found in device." json["Streams"].each do |streamDict| strms << Stream.new(self, streamDict["StreamID"], streamDict["StreamName"], streamDict["Description"], streamDict["DataStreams"]) end return strms[0]; if !key.empty? device.key = key end device.get_streams return device end return nil end
Get a stream by name
# File lib/SensorStream.rb, line 195 def get_stream_by_name(name) streams = self.get_streams stream = nil streams.each { |test_stream| if (test_stream.name == name) return test_stream end } return nil end
Get a list of all the streams for this device
# File lib/SensorStream.rb, line 173 def get_streams if key.empty? resp = SensorStream.make_http_get("/api/GetStreams/#{@id}", {}) else resp = SensorStream.make_http_get("/api/GetStreams/#{@id}?key=#{@key}", {}) end if (resp.code == "200") @streams = [] json = JSON.parse(resp.body) puts json["Streams"].count.to_s + " streams found in device." json["Streams"].each do |streamDict| @streams << Stream.new(self, streamDict["StreamID"], streamDict["StreamName"], streamDict["Description"], streamDict["DataStreams"]) end return @streams; else puts "Unable to get streams from server (#{resp.code})\n#{resp.body}" return nil end end
Create a useful (to a human) representation of the device for printing
# File lib/SensorStream.rb, line 166 def to_s string = "Name: #{@device_name} \n\tID: #{@id} \n\tUser: #{@user_name} \n\tDescription: #{@description} \n\tKey: #{@key}" streams.each { |stream| string += stream.to_s } return string end