Class: Neurio
Instance Method Summary collapse
-
#default_sensor_id ⇒ String
Look up the ID of the first (and usually only) sensor associated with this account.
-
#initialize(options) ⇒ Neurio
constructor
Construct a new Neurio API instance.
-
#last(sensor_id = default_sensor_id) ⇒ Neurio::Reading
Get the most recent sensor reading.
-
#live(last_timestamp = nil, sensor_id = default_sensor_id) ⇒ Array<Neurio::Reading>
Get recent sensor readings since last_timestamp.
Constructor Details
#initialize(options) ⇒ Neurio
Construct a new Neurio API instance
13 14 15 16 17 |
# File 'lib/neurio.rb', line 13 def initialize() @client_secret = [:client_secret] @client_id = [:client_id] raise ArgumentError.new("client_id and client_secret must be specified") unless @client_secret && @client_id end |
Instance Method Details
#default_sensor_id ⇒ String
Look up the ID of the first (and usually only) sensor associated with this account
34 35 36 |
# File 'lib/neurio.rb', line 34 def default_sensor_id user["locations"][0]["sensors"][0]["sensorId"] end |
#last(sensor_id = default_sensor_id) ⇒ Neurio::Reading
Get the most recent sensor reading
23 24 25 26 27 28 |
# File 'lib/neurio.rb', line 23 def last(sensor_id = default_sensor_id) headers = {"content_type" => "application/json", "authorization" => "Bearer #{token}"} query = {"sensorId" => sensor_id} response = self.class.get("/v1/samples/live/last", :headers => headers, :query => query) Reading.new(response, sensor_id) end |
#live(last_timestamp = nil, sensor_id = default_sensor_id) ⇒ Array<Neurio::Reading>
Get recent sensor readings since last_timestamp.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/neurio.rb', line 43 def live( = nil, sensor_id = default_sensor_id) headers = {"content_type" => "application/json", "authorization" => "Bearer #{token}"} query = {"sensorId" => sensor_id} if query["last"] = .iso8601(3) end response = self.class.get("/v1/samples/live", :headers => headers, :query => query) response.map{|x| Reading.new(x, sensor_id)} end |