Module: Helium::Client::Labels

Included in:
Helium::Client
Defined in:
lib/helium/client/labels.rb

Instance Method Summary collapse

Instance Method Details

#create_label(attributes) ⇒ Object



12
13
14
# File 'lib/helium/client/labels.rb', line 12

def create_label(attributes)
  Label.create(attributes, client: self)
end

#label(id) ⇒ Object



8
9
10
# File 'lib/helium/client/labels.rb', line 8

def label(id)
  Label.find(id, client: self)
end

#labelsObject



4
5
6
# File 'lib/helium/client/labels.rb', line 4

def labels
  Label.all(client: self)
end

#update_label_sensors(label, opts = {}) ⇒ Object

TODO incorporate this logic into Helium::Collection



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/helium/client/labels.rb', line 17

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