Module: Helium::Client::Sensors
- Included in:
- Helium::Client
- Defined in:
- lib/helium/client/sensors.rb
Instance Method Summary collapse
- #delete_sensor(sensor) ⇒ Object
- #new_sensor(name:) ⇒ Object
- #sensor(id) ⇒ Object
- #sensor_timeseries(sensor, opts = {}) ⇒ Object
- #sensors ⇒ Object
- #update_sensor(sensor, name:) ⇒ Object
Instance Method Details
#delete_sensor(sensor) ⇒ Object
74 75 76 77 |
# File 'lib/helium/client/sensors.rb', line 74 def delete_sensor(sensor) path = "/sensor/#{sensor.id}" delete(path) end |
#new_sensor(name:) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/helium/client/sensors.rb', line 37 def new_sensor(name:) path = "/sensor" body = { data: { attributes: { name: name }, type: "sensor" } } response = post(path, body: body) sensor_data = JSON.parse(response.body)["data"] return Sensor.new(client: self, params: sensor_data) end |
#sensor(id) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/helium/client/sensors.rb', line 15 def sensor(id) response = get("/sensor/#{id}") sensor_data = JSON.parse(response.body)["data"] return Sensor.new(client: self, params: sensor_data) end |
#sensor_timeseries(sensor, opts = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/helium/client/sensors.rb', line 22 def sensor_timeseries(sensor, opts = {}) path = "/sensor/#{sensor.id}/timeseries" params = { "page[size]" => opts.fetch(:size, nil), "filter[port]" => opts.fetch(:port, nil), "filter[start]" => datetime_to_iso(opts.fetch(:start_time, nil)), "filter[end]" => datetime_to_iso(opts.fetch(:end_time, nil)), "agg[type]" => opts.fetch(:aggtype), "agg[size]" => opts.fetch(:aggsize) }.delete_if { |key, value| value.to_s.empty? } paginated_get(path, klass: Helium::DataPoint, params: params) end |
#sensors ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/helium/client/sensors.rb', line 4 def sensors response = get('/sensor') sensors_data = JSON.parse(response.body)["data"] sensors = sensors_data.map do |sensor_data| Sensor.new(client: self, params: sensor_data) end return sensors end |
#update_sensor(sensor, name:) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/helium/client/sensors.rb', line 55 def update_sensor(sensor, name:) path = "/sensor/#{sensor.id}" body = { data: { attributes: { name: name }, id: sensor.id, type: "sensor" } } response = patch(path, body: body) sensor_data = JSON.parse(response.body)["data"] return Sensor.new(client: self, params: sensor_data) end |