helium-ruby 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a6daafb411fdb428681d8ec0afadf04316eee11
4
- data.tar.gz: 3d051f6d3e8c470b29dc1bc738bf317b10229255
3
+ metadata.gz: 30c4a15c82d31767bf2f28abc9cd6435594fae73
4
+ data.tar.gz: 7e4c7c626c8da7fd6a4f02880a26564dbc6bc873
5
5
  SHA512:
6
- metadata.gz: 0fc04b7f6627428cfa36c159338f70971ec87d150e2a480b3f021d42920277526651bca7b69f41d0add057294e2703350429eb02f4aa9141da7178e3d72dcb98
7
- data.tar.gz: 95d515f2105a68912d8521b3db0d0697ba8191694edb9c83a04c776c7c3393a060543b30f87017a785eaafe4e4720d4be3424f98c56517d400e33ac47523ec2e
6
+ metadata.gz: 7a18ac3aefcddf109ad0c5ea352aaf7b10e944b7464a8eaab27e61a6e1730437350c54842ed21822a4a7686eb4ca915357e4f1d0935eb5e70b70f8ffdf7693b5
7
+ data.tar.gz: c16197c1d1a371cabe17da76baad9f766b937add2f9985a199ecce720a717f3cb1b761426decc50fc577cea75550a43b5e852d91353cf6fbad16bfaf8c65e04b
data/README.md CHANGED
@@ -8,14 +8,14 @@
8
8
  A Ruby gem for building applications with the Helium API. [Helium](https://www.helium.com/) is an integrated platform of smart sensors, communication, edge and cloud compute that enables numerous sensing applications. For more information about the underlying REST API, check out [the Helium docs](https://docs.helium.com/).
9
9
 
10
10
 
11
- ## Helium Documentation and Community Support
11
+ ## Helium Documentation and Community Support
12
12
 
13
13
 
14
- * **helium-ruby docs** - Documentation for the gem's source can be found [here](https://helium.github.io/helium-ruby/):
14
+ * **helium-ruby docs** - Documentation for the gem's source can be found [here](https://helium.github.io/helium-ruby/):
15
15
 
16
- * **Helium Docs** Complete documenation for all parts of Helium can be found at [docs.helium.com](https://docs/helium.com).
16
+ * **Helium Docs** Complete documenation for all parts of Helium can be found at [docs.helium.com](https://docs/helium.com).
17
17
 
18
- * **chat.helium.com** - If you have questions or ideas about how to use this code - or any part of Helium - head over the [chat.helium.com](https://chat.helium.com). We're standing by to help.
18
+ * **chat.helium.com** - If you have questions or ideas about how to use this code - or any part of Helium - head over the [chat.helium.com](http://chat.helium.com). We're standing by to help.
19
19
 
20
20
 
21
21
  ## Installation
@@ -185,6 +185,15 @@ data_points.first.avg
185
185
 
186
186
  A full list of aggregation types and sizes can be found here: https://docs.helium.com/docs/timeseries#aggregations.
187
187
 
188
+ #### Creating Timeseries data
189
+
190
+ Data points can be written to a sensor's timeseries data.
191
+
192
+ ```ruby
193
+ sensor.timeseries.create(port: "power level", value: "over 9000", timestamp: DateTime.now)
194
+ # => #<Helium::DataPoint:0x007f88634b9e50 @params={"attributes"=>{"value"=>"over 9000", "timestamp"=>"2016-09-26T23:19:01Z", "port"=>"power level"}, "relationships"=>{"sensor"=>{"data"=>{"id"=>"071488bb-3050-4849-8984-ca9e683cfc91", "type"=>"sensor"}}}, "id"=>"fd557521-8f59-457f-a75e-d0ce2c58dc1a", "meta"=>{"created"=>"2016-09-26T23:19:06.695036Z"}, "type"=>"data-point"}, @id="fd557521-8f59-457f-a75e-d0ce2c58dc1a", @type="data-point", @created_at="2016-09-26T23:19:06.695036Z", @updated_at=nil, @timestamp="2016-09-26T23:19:01Z", @value="over 9000", @port="power level">
195
+ ```
196
+
188
197
  ### Elements
189
198
 
190
199
  #### Get all Elements
@@ -206,6 +215,15 @@ element.update(name: "A New Name")
206
215
  # => #<Helium::Element:0x007faf732c2548 @id="1b686e82-bd4a-4aac-9d7b-9bdbe1e9a7de", @name="A New Name", @mac="6081f9fffe00033f", @created_at="2015-08-12T23:19:34.175932Z", @updated_at="2015-08-12T23:19:34.174828Z", @versions=nil>
207
216
  ```
208
217
 
218
+ #### Creating Timeseries data
219
+
220
+ Data points can be written to an element's timeseries data.
221
+
222
+ ```ruby
223
+ element.timeseries.create(port: "power level", value: "over 9000", timestamp: DateTime.now)
224
+ # => #<Helium::DataPoint:0x007f88634b9e50 @params={"attributes"=>{"value"=>"over 9000", "timestamp"=>"2016-09-26T23:19:01Z", "port"=>"power level"}, "relationships"=>{"sensor"=>{"data"=>{"id"=>"071488bb-3050-4849-8984-ca9e683cfc91", "type"=>"sensor"}}}, "id"=>"fd557521-8f59-457f-a75e-d0ce2c58dc1a", "meta"=>{"created"=>"2016-09-26T23:19:06.695036Z"}, "type"=>"data-point"}, @id="fd557521-8f59-457f-a75e-d0ce2c58dc1a", @type="data-point", @created_at="2016-09-26T23:19:06.695036Z", @updated_at=nil, @timestamp="2016-09-26T23:19:01Z", @value="over 9000", @port="power level">
225
+ ```
226
+
209
227
  ### Labels
210
228
 
211
229
  Sensors can be grouped together under a named label.
data/lib/helium.rb CHANGED
@@ -12,6 +12,7 @@ require "helium/user"
12
12
  require "helium/organization"
13
13
  require "helium/sensor"
14
14
  require "helium/label"
15
+ require "helium/timeseries"
15
16
  require "helium/data_point"
16
17
  require "helium/element"
17
18
 
@@ -33,7 +33,11 @@ module Helium
33
33
  "agg[size]" => opts.fetch(:aggsize)
34
34
  }.delete_if { |_key, value| value.to_s.empty? }
35
35
 
36
- paginated_get(path, klass: Helium::DataPoint, params: params)
36
+ paginated_get(path,
37
+ klass: Helium::DataPoint,
38
+ cursor_klass: Helium::Timeseries,
39
+ params: params
40
+ )
37
41
  end
38
42
  end
39
43
  end
@@ -13,9 +13,10 @@ module Helium
13
13
 
14
14
  def paginated_get(path, opts = {})
15
15
  klass = opts.fetch(:klass)
16
+ cursor_klass = opts.fetch(:cursor_klass, Helium::Cursor)
16
17
  params = opts.fetch(:params, {})
17
18
 
18
- Cursor.new(client: self, path: path, klass: klass, params: params)
19
+ cursor_klass.new(client: self, path: path, klass: klass, params: params)
19
20
  end
20
21
 
21
22
  def post(path, opts = {})
@@ -21,7 +21,11 @@ module Helium
21
21
  "agg[size]" => opts.fetch(:aggsize)
22
22
  }.delete_if { |_key, value| value.to_s.empty? }
23
23
 
24
- paginated_get(path, klass: Helium::DataPoint, params: params)
24
+ paginated_get(path,
25
+ klass: Helium::DataPoint,
26
+ cursor_klass: Helium::Timeseries,
27
+ params: params
28
+ )
25
29
  end
26
30
 
27
31
  def create_sensor(attributes)
@@ -1,25 +1,31 @@
1
1
  module Helium
2
2
  class Element < Resource
3
- attr_reader :name, :mac, :versions
3
+ attr_reader :name, :mac, :last_seen
4
4
 
5
5
  def initialize(opts = {})
6
6
  super(opts)
7
7
 
8
- @name = @params.dig("attributes", "name")
9
- @mac = @params.dig("meta", "mac")
10
- @versions = @params.dig("meta", "versions")
8
+ @name = @params.dig("attributes", "name")
9
+ @mac = @params.dig("meta", "mac")
10
+ @last_seen = @params.dig('meta', 'last-seen')
11
11
  end
12
12
 
13
13
  def sensors
14
14
  @client.element_sensors(self)
15
15
  end
16
16
 
17
+ # @return [DateTime, nil] when the resource was last seen
18
+ def last_seen
19
+ return nil if @last_seen.nil?
20
+ @_last_seen ||= DateTime.parse(@last_seen)
21
+ end
22
+
17
23
  # TODO can probably generalize this a bit more
18
24
  def as_json
19
25
  super.merge({
20
26
  name: name,
21
27
  mac: mac,
22
- versions: versions
28
+ last_seen: last_seen
23
29
  })
24
30
  end
25
31
 
data/lib/helium/sensor.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Helium
2
2
  class Sensor < Resource
3
- attr_reader :name, :mac, :ports, :last_seen, :firmware
3
+ attr_reader :name, :mac, :ports, :last_seen
4
4
 
5
5
  def initialize(opts = {})
6
6
  super(opts)
@@ -9,7 +9,6 @@ module Helium
9
9
  @mac = @params.dig('meta', 'mac')
10
10
  @ports = @params.dig('meta', 'ports')
11
11
  @last_seen = @params.dig('meta', 'last-seen')
12
- @firmware = @params.dig('meta', 'versions', 'sensor')
13
12
  end
14
13
 
15
14
  def self.all_path
@@ -57,7 +56,6 @@ module Helium
57
56
  mac: mac,
58
57
  ports: ports,
59
58
  last_seen: last_seen,
60
- firmware: firmware,
61
59
  labels: labels
62
60
  })
63
61
  end
@@ -0,0 +1,33 @@
1
+ module Helium
2
+ class Timeseries < Cursor
3
+ include Helium::Utils
4
+
5
+ # Creates a new data point on this timeseries
6
+ # @option opts [String] :port A port for the data point
7
+ # @option opts [String] :value A value for the data point
8
+ # @option opts [DateTime] :timestamp A timestamp for the data point. If not provided, it will default to the current time.
9
+ # @return [DataPoint]
10
+ def create(opts = {})
11
+ port = opts.fetch(:port)
12
+ value = opts.fetch(:value)
13
+ timestamp = opts.fetch(:timestamp, DateTime.now)
14
+
15
+ body = {
16
+ data: {
17
+ attributes: {
18
+ port: port,
19
+ value: value,
20
+ timestamp: datetime_to_iso(timestamp)
21
+ },
22
+ type: 'data-point'
23
+ }
24
+ }
25
+
26
+ response = @client.post(@path, body: body)
27
+ resource_data = JSON.parse(response.body)["data"]
28
+
29
+ return DataPoint.new(client: self, params: resource_data)
30
+ end
31
+
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module Helium
2
- VERSION = "0.9.0"
2
+ VERSION = "0.10.0"
3
3
  end
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.9.0
4
+ version: 0.10.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-09-08 00:00:00.000000000 Z
12
+ date: 2016-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typhoeus
@@ -297,6 +297,7 @@ files:
297
297
  - lib/helium/organization.rb
298
298
  - lib/helium/resource.rb
299
299
  - lib/helium/sensor.rb
300
+ - lib/helium/timeseries.rb
300
301
  - lib/helium/user.rb
301
302
  - lib/helium/utils.rb
302
303
  - lib/helium/version.rb