helium-ruby 0.25.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/docs/Helium.html +2 -2
  3. data/docs/Helium/Client.html +2 -2
  4. data/docs/Helium/Client/Configurations.html +1 -1
  5. data/docs/Helium/Client/DeviceConfigurations.html +1 -1
  6. data/docs/Helium/Client/Elements.html +1 -1
  7. data/docs/Helium/Client/Http.html +5 -5
  8. data/docs/Helium/Client/Labels.html +1 -116
  9. data/docs/Helium/Client/Organizations.html +1 -1
  10. data/docs/Helium/Client/Sensors.html +1 -1
  11. data/docs/Helium/Client/Users.html +1 -1
  12. data/docs/Helium/ClientError.html +1 -1
  13. data/docs/Helium/Collection.html +199 -1
  14. data/docs/Helium/Configuration.html +1 -1
  15. data/docs/Helium/Cursor.html +1 -1
  16. data/docs/Helium/DataPoint.html +1 -1
  17. data/docs/Helium/DeviceConfiguration.html +1 -1
  18. data/docs/Helium/Element.html +419 -28
  19. data/docs/Helium/Error.html +1 -1
  20. data/docs/Helium/InvalidApiKey.html +1 -1
  21. data/docs/Helium/Label.html +285 -21
  22. data/docs/Helium/Metadata.html +1 -1
  23. data/docs/Helium/Organization.html +1 -1
  24. data/docs/Helium/Resource.html +2 -2
  25. data/docs/Helium/Sensor.html +308 -36
  26. data/docs/Helium/Timeseries.html +1 -1
  27. data/docs/Helium/User.html +1 -1
  28. data/docs/Helium/Utils.html +1 -1
  29. data/docs/_index.html +1 -1
  30. data/docs/file.README.html +1 -1
  31. data/docs/index.html +1 -1
  32. data/docs/method_list.html +287 -151
  33. data/docs/top-level-namespace.html +1 -1
  34. data/lib/helium.rb +1 -0
  35. data/lib/helium/client.rb +12 -10
  36. data/lib/helium/client/helium_scripts.rb +105 -0
  37. data/lib/helium/helium_script.rb +73 -0
  38. data/lib/helium/sensor.rb +6 -0
  39. data/lib/helium/version.rb +1 -1
  40. metadata +5 -3
@@ -102,7 +102,7 @@
102
102
  </div>
103
103
 
104
104
  <div id="footer">
105
- Generated on Mon Feb 13 09:17:41 2017 by
105
+ Generated on Wed Apr 5 13:55:53 2017 by
106
106
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
107
107
  0.9.5 (ruby-2.3.1).
108
108
  </div>
@@ -19,6 +19,7 @@ require "helium/data_point"
19
19
  require "helium/element"
20
20
  require "helium/configuration"
21
21
  require "helium/device_configuration"
22
+ require "helium/helium_script"
22
23
 
23
24
  module Helium
24
25
  end
@@ -1,23 +1,25 @@
1
+ require 'helium/client/configurations'
2
+ require 'helium/client/device_configurations'
3
+ require 'helium/client/elements'
4
+ require 'helium/client/helium_scripts'
1
5
  require 'helium/client/http'
2
- require 'helium/client/users'
6
+ require 'helium/client/labels'
3
7
  require 'helium/client/organizations'
4
8
  require 'helium/client/sensors'
5
- require 'helium/client/labels'
6
- require 'helium/client/elements'
7
- require 'helium/client/configurations'
8
- require 'helium/client/device_configurations'
9
+ require 'helium/client/users'
9
10
 
10
11
  module Helium
11
12
  class Client
12
13
  include Helium::Utils
14
+ include Helium::Client::Configurations
15
+ include Helium::Client::DeviceConfigurations
16
+ include Helium::Client::Elements
17
+ include Helium::Client::HeliumScripts
13
18
  include Helium::Client::Http
14
- include Helium::Client::Users
19
+ include Helium::Client::Labels
15
20
  include Helium::Client::Organizations
16
21
  include Helium::Client::Sensors
17
- include Helium::Client::Labels
18
- include Helium::Client::Elements
19
- include Helium::Client::Configurations
20
- include Helium::Client::DeviceConfigurations
22
+ include Helium::Client::Users
21
23
 
22
24
 
23
25
  API_VERSION = 'v1'
@@ -0,0 +1,105 @@
1
+ require 'base64'
2
+
3
+ module Helium
4
+ class Client
5
+ module HeliumScripts
6
+
7
+ def create_script(name, file_content)
8
+ contents = Base64.strict_encode64(file_content)
9
+ Script.create({ name: name , contents: contents }, client: self)
10
+ end
11
+
12
+ def scripts
13
+ Script.all(client: self)
14
+ end
15
+
16
+ def script(id)
17
+ Script.find(id, client: self)
18
+ end
19
+
20
+ def create_library(name, file_content)
21
+ contents = Base64.strict_encode64(file_content)
22
+ Library.create({ name: name , contents: contents }, client: self)
23
+ end
24
+
25
+ def libraries
26
+ Library.all(client: self)
27
+ end
28
+
29
+ def library(id)
30
+ Library.find(id, client: self)
31
+ end
32
+
33
+ def packages
34
+ Package.all(client: self)
35
+ end
36
+
37
+ def package(id)
38
+ Package.find(id, client: self)
39
+ end
40
+
41
+ def create_package(script, libraries = [], name = nil)
42
+ library_rels = Array(libraries).map do |lib|
43
+ { id: lib.id, type: 'library' }
44
+ end
45
+ body = {
46
+ data: {
47
+ attributes: {
48
+ name: name
49
+ },
50
+ type: 'package',
51
+ relationships: {
52
+ script: {
53
+ data: {
54
+ id: script.id,
55
+ type: 'script'
56
+ }
57
+ },
58
+ library: {
59
+ data: library_rels
60
+ }
61
+ }
62
+ }
63
+ }
64
+
65
+ response = post('/package', body: body)
66
+ resource_data = JSON.parse(response.body)["data"]
67
+ Package.new(client: self, params: resource_data)
68
+ end
69
+
70
+ def sensor_packages
71
+ SensorPackage.all(client: self)
72
+ end
73
+
74
+ def sensor_package(id)
75
+ SensorPackage.find(id, client: self)
76
+ end
77
+
78
+ def create_sensor_package(sensor, package)
79
+ body = {
80
+ data: {
81
+ type: 'sensor-package',
82
+ relationships: {
83
+ package: {
84
+ data: {
85
+ id: package.id,
86
+ type: 'package'
87
+ }
88
+ },
89
+ sensor: {
90
+ data: {
91
+ id: sensor.id,
92
+ type: 'sensor'
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+
99
+ response = post('/sensor-package', body: body)
100
+ resource_data = JSON.parse(response.body)["data"]
101
+ SensorPackage.new(client: self, params: resource_data)
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,73 @@
1
+ # The following classes are all closely related and thus included in the same file
2
+ module Helium
3
+ class Script < Resource
4
+ attr_reader :name
5
+
6
+ def initialize(opts = {})
7
+ super(opts)
8
+ @name = @params.dig('attributes', 'name')
9
+ @digest = @params.dig('meta', 'digest')
10
+ end
11
+
12
+ def content
13
+ @content ||= @client.get(resource_path+'/content',
14
+ content_type: 'application/octet-stream').body
15
+ end
16
+ end
17
+
18
+ class Library < Resource
19
+ attr_reader :name
20
+
21
+ def initialize(opts = {})
22
+ super(opts)
23
+ @name = @params.dig('attributes', 'name')
24
+ @digest = @params.dig('meta', 'digest')
25
+ end
26
+
27
+ def content
28
+ @content ||= @client.get(resource_path+'/content',
29
+ content_type: 'application/octet-stream').body
30
+ end
31
+ end
32
+
33
+ class Package < Resource
34
+ attr_reader :name
35
+
36
+ def initialize(opts = {})
37
+ super(opts)
38
+ @name = @params.dig('attributes', 'name')
39
+ end
40
+
41
+ # Script is immutable and can be cached
42
+ def script
43
+ @script ||= Script.initialize_from_path(path: "#{resource_path}/script",
44
+ client: @client)
45
+ end
46
+
47
+ # Libraries are immutable and can be cached
48
+ def libraries
49
+ @libs ||= Collection.new(klass: Library, client: @client,
50
+ belongs_to: self)
51
+ end
52
+ end
53
+
54
+ class SensorPackage < Resource
55
+ attr_reader :loaded
56
+
57
+ def initialize(opts = {})
58
+ super(opts)
59
+ @loaded = @params.dig('meta', 'loaded')
60
+ end
61
+
62
+ # Sensor is not immutable (name can change), and should not be cached
63
+ def sensor
64
+ Sensor.initialize_from_path(path: "#{resource_path}/sensor", client: @client)
65
+ end
66
+
67
+ # Package is immutable and can be cached
68
+ def package
69
+ @package ||= Package.initialize_from_path(path: "#{resource_path}/package",
70
+ client: @client)
71
+ end
72
+ end
73
+ end
@@ -116,5 +116,11 @@ module Helium
116
116
  end
117
117
  self
118
118
  end
119
+
120
+ # A sensor can be associated with at most 2 sensor-packages: the loaded
121
+ # package and package being loaded
122
+ def sensor_packages
123
+ Collection.new(klass: SensorPackage, client: @client, belongs_to: self)
124
+ end
119
125
  end
120
126
  end
@@ -1,3 +1,3 @@
1
1
  module Helium
2
- VERSION = "0.25.0"
2
+ VERSION = "0.26.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.25.0
4
+ version: 0.26.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: 2017-04-05 00:00:00.000000000 Z
12
+ date: 2017-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typhoeus
@@ -293,6 +293,7 @@ files:
293
293
  - lib/helium/client/configurations.rb
294
294
  - lib/helium/client/device_configurations.rb
295
295
  - lib/helium/client/elements.rb
296
+ - lib/helium/client/helium_scripts.rb
296
297
  - lib/helium/client/http.rb
297
298
  - lib/helium/client/labels.rb
298
299
  - lib/helium/client/organizations.rb
@@ -305,6 +306,7 @@ files:
305
306
  - lib/helium/device_configuration.rb
306
307
  - lib/helium/element.rb
307
308
  - lib/helium/error.rb
309
+ - lib/helium/helium_script.rb
308
310
  - lib/helium/label.rb
309
311
  - lib/helium/metadata.rb
310
312
  - lib/helium/organization.rb
@@ -335,7 +337,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
335
337
  version: '0'
336
338
  requirements: []
337
339
  rubyforge_project:
338
- rubygems_version: 2.5.1
340
+ rubygems_version: 2.6.11
339
341
  signing_key:
340
342
  specification_version: 4
341
343
  summary: A Ruby gem for building applications with the Helium API