Module: Helium::Client::DeviceConfigurations

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

Instance Method Summary collapse

Instance Method Details

#create_device_configuration(device, configuration) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/helium/client/device_configurations.rb', line 35

def create_device_configuration(device, configuration)
  path = "/device-configuration"

  body = {
    data: {
      type: "device-configuration",
      relationships: {
        configuration: {
          data: {
            id: configuration.id,
            type: configuration.type
          }
        },
        device: {
          data: {
            id: device.id,
            type: device.type
          }
        }
      }
    }
  }

  response = post(path, body: body)
  dc = JSON.parse(response.body)["data"]
  return DeviceConfiguration.new(client: self, params: dc)
end

#device_configuration(id) ⇒ Object



9
10
11
# File 'lib/helium/client/device_configurations.rb', line 9

def device_configuration(id)
  DeviceConfiguration.find(id, client: self)
end

#device_configuration_configuration(device_config) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/helium/client/device_configurations.rb', line 13

def device_configuration_configuration(device_config)
  path = "/device-configuration/#{device_config.id}/configuration"
  response = get(path)
  configj = JSON.parse(response.body)["data"]
  config = Configuration.new(client: self, params: configj)
  return config
end

#device_configuration_device(device_config) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/helium/client/device_configurations.rb', line 21

def device_configuration_device(device_config)
  path = "/device-configuration/#{device_config.id}/device"
  response = get(path)
  configj = JSON.parse(response.body)["data"]

  if configj.dig("type") == "sensor"
    device = Sensor.new(client: self, params: configj)
  elsif configj.dig("type") == "element"
    device = Element.new(client: self, params: configj)
  end

  return device
end

#device_configurationsObject



5
6
7
# File 'lib/helium/client/device_configurations.rb', line 5

def device_configurations
  DeviceConfiguration.all(client: self)
end