helium-ruby 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/helium.rb +2 -0
- data/lib/helium/client.rb +5 -0
- data/lib/helium/client/configurations.rb +31 -0
- data/lib/helium/client/device_configurations.rb +64 -0
- data/lib/helium/client/elements.rb +8 -0
- data/lib/helium/client/sensors.rb +8 -0
- data/lib/helium/configuration.rb +15 -0
- data/lib/helium/device_configuration.rb +23 -0
- data/lib/helium/element.rb +4 -0
- data/lib/helium/error.rb +6 -1
- data/lib/helium/resource.rb +5 -2
- data/lib/helium/sensor.rb +4 -0
- data/lib/helium/utils.rb +4 -0
- data/lib/helium/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b91648a288c3daa41d4c26265856513591b67986
|
4
|
+
data.tar.gz: d739e7f23b26dee61722fd96eb709e56f64c2af9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bc90567717d28ea616d5b6399c1865756ecced3c92b47a2c4034118e1158d72316977511cadaffa3cdf2a05c0d100eff52ac5622866630b818739617932c302
|
7
|
+
data.tar.gz: c8455d1442c8fe00503d57c36f5a62ac3cb57ed31deb8792e9ff7a6cb3b4cb332728677b36f1bf003bda8799e0f92ce7cdefa93c034644ed3c96f6149e6c0d3b
|
data/lib/helium.rb
CHANGED
data/lib/helium/client.rb
CHANGED
@@ -4,6 +4,8 @@ require 'helium/client/organizations'
|
|
4
4
|
require 'helium/client/sensors'
|
5
5
|
require 'helium/client/labels'
|
6
6
|
require 'helium/client/elements'
|
7
|
+
require 'helium/client/configurations'
|
8
|
+
require 'helium/client/device_configurations'
|
7
9
|
|
8
10
|
module Helium
|
9
11
|
class Client
|
@@ -14,6 +16,9 @@ module Helium
|
|
14
16
|
include Helium::Client::Sensors
|
15
17
|
include Helium::Client::Labels
|
16
18
|
include Helium::Client::Elements
|
19
|
+
include Helium::Client::Configurations
|
20
|
+
include Helium::Client::DeviceConfigurations
|
21
|
+
|
17
22
|
|
18
23
|
API_VERSION = 1
|
19
24
|
HOST = 'api.helium.com'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Helium
|
2
|
+
class Client
|
3
|
+
module Configurations
|
4
|
+
|
5
|
+
def configurations
|
6
|
+
Configuration.all(client: self)
|
7
|
+
end
|
8
|
+
|
9
|
+
def configuration(id)
|
10
|
+
Configuration.find(id, client: self)
|
11
|
+
end
|
12
|
+
|
13
|
+
def config_device_configurations(id)
|
14
|
+
path = "/configuration/#{id}/device-configuration"
|
15
|
+
response = get(path)
|
16
|
+
device_confs_data = JSON.parse(response.body)["data"]
|
17
|
+
|
18
|
+
device_confs = device_confs_data.map do |dc|
|
19
|
+
DeviceConfiguration.new(client: self, params: dc)
|
20
|
+
end
|
21
|
+
|
22
|
+
return device_confs
|
23
|
+
end
|
24
|
+
|
25
|
+
# Configurations are immutable, so no updates are available
|
26
|
+
def create_configuration(attributes)
|
27
|
+
Configuration.create(attributes, client: self)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Helium
|
2
|
+
class Client
|
3
|
+
module DeviceConfigurations
|
4
|
+
|
5
|
+
def device_configurations
|
6
|
+
DeviceConfiguration.all(client: self)
|
7
|
+
end
|
8
|
+
|
9
|
+
def device_configuration(id)
|
10
|
+
DeviceConfiguration.find(id, client: self)
|
11
|
+
end
|
12
|
+
|
13
|
+
def device_configuration_configuration(device_config)
|
14
|
+
path = "/device-configuration/#{device_config.id}/configuration"
|
15
|
+
response = get(path)
|
16
|
+
configj = JSON.parse(response.body)["data"]
|
17
|
+
config = Configuration.new(client: self, params: configj)
|
18
|
+
return config
|
19
|
+
end
|
20
|
+
|
21
|
+
def device_configuration_device(device_config)
|
22
|
+
path = "/device-configuration/#{device_config.id}/device"
|
23
|
+
response = get(path)
|
24
|
+
configj = JSON.parse(response.body)["data"]
|
25
|
+
|
26
|
+
if configj.dig("type") == "sensor"
|
27
|
+
device = Sensor.new(client: self, params: configj)
|
28
|
+
elsif configj.dig("type") == "element"
|
29
|
+
device = Element.new(client: self, params: configj)
|
30
|
+
end
|
31
|
+
|
32
|
+
return device
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_device_configuration(device, configuration)
|
36
|
+
path = "/device-configuration"
|
37
|
+
|
38
|
+
body = {
|
39
|
+
data: {
|
40
|
+
type: "device-configuration",
|
41
|
+
relationships: {
|
42
|
+
configuration: {
|
43
|
+
data: {
|
44
|
+
id: configuration.id,
|
45
|
+
type: configuration.type
|
46
|
+
}
|
47
|
+
},
|
48
|
+
device: {
|
49
|
+
data: {
|
50
|
+
id: device.id,
|
51
|
+
type: device.type
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
response = post(path, body: body)
|
59
|
+
dc = JSON.parse(response.body)["data"]
|
60
|
+
return DeviceConfiguration.new(client: self, params: dc)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -21,6 +21,14 @@ module Helium
|
|
21
21
|
return sensors
|
22
22
|
end
|
23
23
|
|
24
|
+
def element_device_configuration(element)
|
25
|
+
path = "/element/#{element.id}/device-configuration"
|
26
|
+
response = get(path)
|
27
|
+
dc_data = JSON.parse(response.body)["data"]
|
28
|
+
# dc_data is an array, but there will only be one for one
|
29
|
+
return DeviceConfiguration.new(client: self, params: dc_data[0])
|
30
|
+
end
|
31
|
+
|
24
32
|
def element_timeseries(element, opts = {})
|
25
33
|
path = "/element/#{element.id}/timeseries"
|
26
34
|
|
@@ -30,6 +30,14 @@ module Helium
|
|
30
30
|
return labels
|
31
31
|
end
|
32
32
|
|
33
|
+
def sensor_device_configuration(sensor)
|
34
|
+
path = "/sensor/#{sensor.id}/device-configuration"
|
35
|
+
response = get(path)
|
36
|
+
dc_data = JSON.parse(response.body)["data"]
|
37
|
+
# dc_data is an array, but there will only be one for one
|
38
|
+
return DeviceConfiguration.new(client: self, params: dc_data[0])
|
39
|
+
end
|
40
|
+
|
33
41
|
def sensor_timeseries(sensor, opts = {})
|
34
42
|
path = "/sensor/#{sensor.id}/timeseries"
|
35
43
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Helium
|
2
|
+
class Configuration < Resource
|
3
|
+
attr_reader :settings
|
4
|
+
|
5
|
+
def initialize(opts = {})
|
6
|
+
super(opts)
|
7
|
+
@settings = @params.dig('attributes')
|
8
|
+
end
|
9
|
+
|
10
|
+
def device_configurations
|
11
|
+
@client.config_device_configurations(self.id)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Helium
|
2
|
+
class DeviceConfiguration < Resource
|
3
|
+
attr_reader :loaded
|
4
|
+
|
5
|
+
def initialize(opts = {})
|
6
|
+
super(opts)
|
7
|
+
@loaded = @params.dig('meta', 'loaded')
|
8
|
+
end
|
9
|
+
|
10
|
+
def device
|
11
|
+
@client.device_configuration_device(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
def configuration
|
15
|
+
@client.device_configuration_configuration(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def as_json
|
19
|
+
super.merge({ loaded: loaded })
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/helium/element.rb
CHANGED
data/lib/helium/error.rb
CHANGED
@@ -9,7 +9,12 @@ module Helium
|
|
9
9
|
# @return [Helium::Error]
|
10
10
|
def self.from_response(response)
|
11
11
|
status = response.code
|
12
|
-
message
|
12
|
+
# Default the error message in the case of no error body
|
13
|
+
message = if response.body && response.body.length >= 2
|
14
|
+
JSON.parse(response.body)["errors"].first["detail"]
|
15
|
+
else
|
16
|
+
"Unknown error with code: #{response.code}"
|
17
|
+
end
|
13
18
|
|
14
19
|
klass = case status
|
15
20
|
when 401 then Helium::InvalidApiKey
|
data/lib/helium/resource.rb
CHANGED
@@ -2,6 +2,7 @@ module Helium
|
|
2
2
|
# Abstract base class for Helium Resources returned by the API
|
3
3
|
class Resource
|
4
4
|
attr_reader :id, :type, :params
|
5
|
+
include Helium::Utils
|
5
6
|
|
6
7
|
def initialize(opts = {})
|
7
8
|
@client = opts.fetch(:client)
|
@@ -14,6 +15,8 @@ module Helium
|
|
14
15
|
end
|
15
16
|
|
16
17
|
class << self
|
18
|
+
include Helium::Utils
|
19
|
+
|
17
20
|
# NOTE seems a bit out of place to be doing client work here, but it
|
18
21
|
# makes sense for the Eigenclass to be responsible for constructing
|
19
22
|
# instances of its inheriting class.
|
@@ -76,7 +79,7 @@ module Helium
|
|
76
79
|
private
|
77
80
|
|
78
81
|
def resource_name
|
79
|
-
self.name.split('::').last
|
82
|
+
kebab_case(self.name.split('::').last)
|
80
83
|
end
|
81
84
|
end # << self
|
82
85
|
|
@@ -161,7 +164,7 @@ module Helium
|
|
161
164
|
private
|
162
165
|
|
163
166
|
def resource_name
|
164
|
-
self.class.name.split('::').last
|
167
|
+
kebab_case(self.class.name.split('::').last)
|
165
168
|
end
|
166
169
|
end
|
167
170
|
end
|
data/lib/helium/sensor.rb
CHANGED
data/lib/helium/utils.rb
CHANGED
data/lib/helium/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: helium-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Allen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-11-
|
12
|
+
date: 2016-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: typhoeus
|
@@ -283,14 +283,18 @@ files:
|
|
283
283
|
- helium-ruby.gemspec
|
284
284
|
- lib/helium.rb
|
285
285
|
- lib/helium/client.rb
|
286
|
+
- lib/helium/client/configurations.rb
|
287
|
+
- lib/helium/client/device_configurations.rb
|
286
288
|
- lib/helium/client/elements.rb
|
287
289
|
- lib/helium/client/http.rb
|
288
290
|
- lib/helium/client/labels.rb
|
289
291
|
- lib/helium/client/organizations.rb
|
290
292
|
- lib/helium/client/sensors.rb
|
291
293
|
- lib/helium/client/users.rb
|
294
|
+
- lib/helium/configuration.rb
|
292
295
|
- lib/helium/cursor.rb
|
293
296
|
- lib/helium/data_point.rb
|
297
|
+
- lib/helium/device_configuration.rb
|
294
298
|
- lib/helium/element.rb
|
295
299
|
- lib/helium/error.rb
|
296
300
|
- lib/helium/label.rb
|