Sha256: 76e1523f75f157ff11732fd25961a5438b223fd1d14f6fccdb40f163595c6a4d
Contents?: true
Size: 1.32 KB
Versions: 16
Compression:
Stored size: 1.32 KB
Contents
module Helium class Client module Labels def labels Label.all(client: self) end def label(id) Label.find(id, client: self) end def create_label(attributes) Label.create(attributes, client: self) end def label_sensors(label) path = "/label/#{label.id}/sensor" response = get(path) 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 def update_label_sensors(label, opts = {}) sensors = opts.fetch(:sensors, []) path = "/label/#{label.id}/relationships/sensor" sensors = Array(sensors) new_sensor_data = sensors.map do |sensor| { id: sensor.id, type: 'sensor' } end body = { data: new_sensor_data } response = patch(path, body: body) sensors_data = JSON.parse(response.body)["data"] # TODO: these come back deflated. need to either inflate at this point or # when needed sensors = sensors_data.map do |sensor_data| Sensor.new(client: self, params: sensor_data) end return sensors end end end end
Version data entries
16 entries across 16 versions & 1 rubygems