class SensorStream::Device

Implementation of the device class

Attributes

description[R]

Each of the qualities of a device are immutable. The sensor stream API does not support changing device attributes.

device_name[R]

Each of the qualities of a device are immutable. The sensor stream API does not support changing device attributes.

id[R]

Each of the qualities of a device are immutable. The sensor stream API does not support changing device attributes.

key[RW]

It is possible to change the streams and assign a key later, however.

streams[RW]

It is possible to change the streams and assign a key later, however.

user_name[R]

Each of the qualities of a device are immutable. The sensor stream API does not support changing device attributes.

Public Class Methods

new(newID, newUserName, newDeviceName, newDescription, newStreams = [], newKey = "") click to toggle source

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

get_stream_by_id(id, key = "") click to toggle source
# 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_stream_by_name(name) click to toggle source

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_streams() click to toggle source

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
to_s() click to toggle source

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