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

#label_sensors(label) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/helium/client/labels.rb', line 16

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

#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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/helium/client/labels.rb', line 28

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