helium-ruby 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/README.md +3 -3
- data/docs/Helium.html +4 -4
- data/docs/Helium/Client.html +9 -9
- data/docs/Helium/Client/Elements.html +8 -110
- data/docs/Helium/Client/Http.html +31 -33
- data/docs/Helium/Client/Labels.html +38 -218
- data/docs/Helium/Client/Organizations.html +1 -1
- data/docs/Helium/Client/Sensors.html +30 -214
- data/docs/Helium/Client/Users.html +1 -1
- data/docs/Helium/ClientError.html +153 -0
- data/docs/Helium/Cursor.html +8 -8
- data/docs/Helium/DataPoint.html +9 -9
- data/docs/Helium/Element.html +16 -79
- data/docs/Helium/Error.html +267 -0
- data/docs/Helium/InvalidApiKey.html +157 -0
- data/docs/Helium/Label.html +29 -133
- data/docs/Helium/Organization.html +8 -8
- data/docs/Helium/Resource.html +717 -43
- data/docs/Helium/Sensor.html +31 -132
- data/docs/Helium/User.html +8 -8
- data/docs/Helium/Utils.html +1 -1
- data/docs/_index.html +33 -4
- data/docs/class_list.html +1 -1
- data/docs/file.README.html +4 -4
- data/docs/index.html +4 -4
- data/docs/method_list.html +112 -144
- data/docs/top-level-namespace.html +1 -1
- data/lib/helium.rb +1 -0
- data/lib/helium/client.rb +3 -3
- data/lib/helium/client/elements.rb +10 -27
- data/lib/helium/client/http.rb +38 -19
- data/lib/helium/client/labels.rb +7 -53
- data/lib/helium/client/sensors.rb +5 -54
- data/lib/helium/cursor.rb +6 -6
- data/lib/helium/data_point.rb +5 -5
- data/lib/helium/element.rb +7 -8
- data/lib/helium/error.rb +28 -0
- data/lib/helium/label.rb +3 -11
- data/lib/helium/organization.rb +4 -4
- data/lib/helium/resource.rb +103 -5
- data/lib/helium/sensor.rb +13 -15
- data/lib/helium/user.rb +4 -4
- data/lib/helium/version.rb +1 -1
- metadata +6 -2
data/lib/helium/organization.rb
CHANGED
@@ -2,11 +2,11 @@ module Helium
|
|
2
2
|
class Organization < Resource
|
3
3
|
attr_reader :name, :timezone
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
super(
|
5
|
+
def initialize(opts = {})
|
6
|
+
super(opts)
|
7
7
|
|
8
|
-
@name = params.dig('attributes', 'name')
|
9
|
-
@timezone = params.dig('attributes', 'timezone')
|
8
|
+
@name = @params.dig('attributes', 'name')
|
9
|
+
@timezone = @params.dig('attributes', 'timezone')
|
10
10
|
end
|
11
11
|
|
12
12
|
# TODO refactor into relationships
|
data/lib/helium/resource.rb
CHANGED
@@ -3,11 +3,103 @@ module Helium
|
|
3
3
|
class Resource
|
4
4
|
attr_reader :id
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@client
|
8
|
-
@
|
9
|
-
|
10
|
-
@
|
6
|
+
def initialize(opts = {})
|
7
|
+
@client = opts.fetch(:client)
|
8
|
+
@params = opts.fetch(:params)
|
9
|
+
|
10
|
+
@id = @params["id"]
|
11
|
+
@created_at = @params.dig('meta', 'created')
|
12
|
+
@updated_at = @params.dig('meta', 'updated')
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
# NOTE seems a bit out of place to be doing client work here, but it
|
17
|
+
# makes sense for the Eigenclass to be responsable for constructing
|
18
|
+
# instances of its inheriting class.
|
19
|
+
|
20
|
+
# Returns all resources
|
21
|
+
# @option opts [Client] :client A Helium::Client
|
22
|
+
# @return [Array<Resource>] an Array of all of the inheriting Resource
|
23
|
+
def all(opts = {})
|
24
|
+
client = opts.fetch(:client)
|
25
|
+
|
26
|
+
response = client.get("/#{resource_name}")
|
27
|
+
resources_data = JSON.parse(response.body)["data"]
|
28
|
+
|
29
|
+
resources = resources_data.map do |resource_data|
|
30
|
+
self.new(client: client, params: resource_data)
|
31
|
+
end
|
32
|
+
|
33
|
+
return resources
|
34
|
+
end
|
35
|
+
|
36
|
+
# Finds a single Resource by id
|
37
|
+
# @param id [String] An id to find the Resource
|
38
|
+
# @option opts [Client] :client A Helium::Client
|
39
|
+
# @return [Resource]
|
40
|
+
def find(id, opts = {})
|
41
|
+
client = opts.fetch(:client)
|
42
|
+
|
43
|
+
response = client.get("/#{resource_name}/#{id}")
|
44
|
+
resource_data = JSON.parse(response.body)["data"]
|
45
|
+
|
46
|
+
return self.new(client: client, params: resource_data)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Creates a new resource with given attributes
|
50
|
+
# @param attributes [Hash] The attributes for the new Resource
|
51
|
+
# @option opts [Client] :client A Helium::Client
|
52
|
+
# @return [Resource]
|
53
|
+
def create(attributes, opts = {})
|
54
|
+
client = opts.fetch(:client)
|
55
|
+
|
56
|
+
path = "/#{resource_name}"
|
57
|
+
|
58
|
+
body = {
|
59
|
+
data: {
|
60
|
+
attributes: attributes,
|
61
|
+
type: resource_name
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
response = client.post(path, body: body)
|
66
|
+
resource_data = JSON.parse(response.body)["data"]
|
67
|
+
|
68
|
+
return self.new(client: client, params: resource_data)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def resource_name
|
74
|
+
self.name.split('::').last.downcase
|
75
|
+
end
|
76
|
+
end # << self
|
77
|
+
|
78
|
+
# Updates a Resource
|
79
|
+
# @param attributes [Hash] The attributes to update
|
80
|
+
# @return [Resource] The updated resource
|
81
|
+
def update(attributes)
|
82
|
+
path = "/#{resource_name}/#{self.id}"
|
83
|
+
|
84
|
+
body = {
|
85
|
+
data: {
|
86
|
+
attributes: attributes,
|
87
|
+
id: self.id,
|
88
|
+
type: resource_name
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
response = @client.patch(path, body: body)
|
93
|
+
resource_data = JSON.parse(response.body)["data"]
|
94
|
+
|
95
|
+
return self.class.new(client: self, params: resource_data)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Deletes the Resource
|
99
|
+
# @return [Boolean] Whether the operation was successful
|
100
|
+
def destroy
|
101
|
+
path = "/#{resource_name}/#{self.id}"
|
102
|
+
@client.delete(path)
|
11
103
|
end
|
12
104
|
|
13
105
|
# Override equality to use id for comparisons
|
@@ -54,5 +146,11 @@ module Helium
|
|
54
146
|
def to_json(*options)
|
55
147
|
as_json.to_json(*options)
|
56
148
|
end
|
149
|
+
|
150
|
+
private
|
151
|
+
|
152
|
+
def resource_name
|
153
|
+
self.class.name.split('::').last.downcase
|
154
|
+
end
|
57
155
|
end
|
58
156
|
end
|
data/lib/helium/sensor.rb
CHANGED
@@ -2,15 +2,22 @@ module Helium
|
|
2
2
|
class Sensor < Resource
|
3
3
|
attr_reader :name, :mac, :ports
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
super(
|
5
|
+
def initialize(opts = {})
|
6
|
+
super(opts)
|
7
7
|
|
8
|
-
@name = params.dig('attributes', 'name')
|
9
|
-
@mac = params.dig('meta', 'mac')
|
10
|
-
@ports = params.dig('meta', 'ports')
|
8
|
+
@name = @params.dig('attributes', 'name')
|
9
|
+
@mac = @params.dig('meta', 'mac')
|
10
|
+
@ports = @params.dig('meta', 'ports')
|
11
11
|
end
|
12
12
|
|
13
|
-
def timeseries(
|
13
|
+
def timeseries(opts = {})
|
14
|
+
size = opts.fetch(:size, 1000)
|
15
|
+
port = opts.fetch(:port, nil)
|
16
|
+
start_time = opts.fetch(:start_time, nil)
|
17
|
+
end_time = opts.fetch(:end_time, nil)
|
18
|
+
aggtype = opts.fetch(:aggtype, nil)
|
19
|
+
aggsize = opts.fetch(:aggsize, nil)
|
20
|
+
|
14
21
|
@client.sensor_timeseries(self,
|
15
22
|
size: size,
|
16
23
|
port: port,
|
@@ -21,15 +28,6 @@ module Helium
|
|
21
28
|
)
|
22
29
|
end
|
23
30
|
|
24
|
-
# TODO CRUD methods will be generalized into the Resource object
|
25
|
-
def update(name:)
|
26
|
-
@client.update_sensor(self, name: name)
|
27
|
-
end
|
28
|
-
|
29
|
-
def destroy
|
30
|
-
@client.delete_sensor(self)
|
31
|
-
end
|
32
|
-
|
33
31
|
# TODO can probably generalize this a bit more
|
34
32
|
def as_json
|
35
33
|
super.merge({
|
data/lib/helium/user.rb
CHANGED
@@ -2,11 +2,11 @@ module Helium
|
|
2
2
|
class User < Resource
|
3
3
|
attr_reader :name, :email
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
super(
|
5
|
+
def initialize(opts = {})
|
6
|
+
super(opts)
|
7
7
|
|
8
|
-
@name = params.dig('attributes', 'name')
|
9
|
-
@email = params.dig('meta', 'email')
|
8
|
+
@name = @params.dig('attributes', 'name')
|
9
|
+
@email = @params.dig('meta', 'email')
|
10
10
|
end
|
11
11
|
|
12
12
|
# TODO can probably generalize this a bit more
|
data/lib/helium/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: helium-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Allen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -252,9 +252,12 @@ files:
|
|
252
252
|
- docs/Helium/Client/Organizations.html
|
253
253
|
- docs/Helium/Client/Sensors.html
|
254
254
|
- docs/Helium/Client/Users.html
|
255
|
+
- docs/Helium/ClientError.html
|
255
256
|
- docs/Helium/Cursor.html
|
256
257
|
- docs/Helium/DataPoint.html
|
257
258
|
- docs/Helium/Element.html
|
259
|
+
- docs/Helium/Error.html
|
260
|
+
- docs/Helium/InvalidApiKey.html
|
258
261
|
- docs/Helium/Label.html
|
259
262
|
- docs/Helium/Organization.html
|
260
263
|
- docs/Helium/Resource.html
|
@@ -287,6 +290,7 @@ files:
|
|
287
290
|
- lib/helium/cursor.rb
|
288
291
|
- lib/helium/data_point.rb
|
289
292
|
- lib/helium/element.rb
|
293
|
+
- lib/helium/error.rb
|
290
294
|
- lib/helium/label.rb
|
291
295
|
- lib/helium/organization.rb
|
292
296
|
- lib/helium/resource.rb
|