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

Version Path
helium-ruby-0.20.0 lib/helium/client/labels.rb
helium-ruby-0.19.0 lib/helium/client/labels.rb
helium-ruby-0.18.0 lib/helium/client/labels.rb
helium-ruby-0.17.0 lib/helium/client/labels.rb
helium-ruby-0.16.0 lib/helium/client/labels.rb
helium-ruby-0.15.0 lib/helium/client/labels.rb
helium-ruby-0.14.0 lib/helium/client/labels.rb
helium-ruby-0.13.0 lib/helium/client/labels.rb
helium-ruby-0.12.0 lib/helium/client/labels.rb
helium-ruby-0.11.0 lib/helium/client/labels.rb
helium-ruby-0.10.0 lib/helium/client/labels.rb
helium-ruby-0.9.0 lib/helium/client/labels.rb
helium-ruby-0.8.0 lib/helium/client/labels.rb
helium-ruby-0.7.0 lib/helium/client/labels.rb
helium-ruby-0.6.0 lib/helium/client/labels.rb
helium-ruby-0.5.0 lib/helium/client/labels.rb