helium-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +17 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +21 -0
- data/README.md +184 -0
- data/Rakefile +6 -0
- data/bin/console +16 -0
- data/bin/setup +8 -0
- data/helium-ruby.gemspec +43 -0
- data/lib/helium.rb +15 -0
- data/lib/helium/client.rb +45 -0
- data/lib/helium/client/http.rb +33 -0
- data/lib/helium/client/organizations.rb +22 -0
- data/lib/helium/client/sensors.rb +56 -0
- data/lib/helium/client/users.rb +11 -0
- data/lib/helium/data_point.rb +17 -0
- data/lib/helium/organization.rb +27 -0
- data/lib/helium/sensor.rb +32 -0
- data/lib/helium/timeseries.rb +27 -0
- data/lib/helium/user.rb +22 -0
- data/lib/helium/utils.rb +8 -0
- data/lib/helium/version.rb +3 -0
- metadata +238 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 652e7ae9d3dda85ecf853683b0e83a1abcd0746a
|
4
|
+
data.tar.gz: 38302545f4d2b850bc17afb890ba0efd16e6de92
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf23c7d0f425d9106b54337aba35006cd95ad4a8ac89eb3ef776a2780ba0f46dfba63d68866e651600187c56d6c07e64ac1f7a78b6a0947d66c76f9da826f4a3
|
7
|
+
data.tar.gz: ed941a33a010e4b567b39083ecca5a140a18bc9825632215135831cf66a956d8df63e6c4fe76efc24f00f32e8a5edd9cdf156b23b3fadd5d0037951740d5bdee
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
|
5
|
+
rvm:
|
6
|
+
- 2.3.1
|
7
|
+
|
8
|
+
before_install: gem install bundler -v 1.12.5
|
9
|
+
|
10
|
+
script: 'bundle exec rake'
|
11
|
+
|
12
|
+
notifications:
|
13
|
+
email:
|
14
|
+
recipients:
|
15
|
+
- allenan@helium.com
|
16
|
+
on_failure: change
|
17
|
+
on_success: never
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at allenan@helium.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Andrew Allen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
# helium-ruby
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/helium/helium-ruby.svg?branch=master)](https://travis-ci.org/helium/helium-ruby)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/helium/helium-ruby/badge.svg?branch=master)](https://coveralls.io/github/helium/helium-ruby?branch=master)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/helium/helium-ruby/badges/gpa.svg)](https://codeclimate.com/github/helium/helium-ruby)
|
6
|
+
|
7
|
+
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/).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'helium-ruby'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install helium-ruby
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Setup
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'helium'
|
31
|
+
|
32
|
+
client = Helium::Client.new(api_key: '<Your API Key>')
|
33
|
+
```
|
34
|
+
|
35
|
+
### Users
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
client.user
|
39
|
+
# => #<Helium::User:0x007fd58198d9e8 @id="dev-accounts@helium.co", @name="HeliumDevAccount Demo", @email="dev-accounts@helium.co", @created_at="2014-10-29T21:38:52Z", @updated_at="2015-08-06T18:21:32.186374Z">
|
40
|
+
```
|
41
|
+
|
42
|
+
### Organizations
|
43
|
+
|
44
|
+
#### Get the current organization
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
client.organization
|
48
|
+
# => #<Helium::Organization:0x007fd3d94b1b08 @client=<Helium::Client @debug=true>, @id="dev-accounts@helium.co", @name="dev-accounts@helium.co", @timezone="UTC", @created_at="2015-09-10T20:50:18.183896Z", @updated_at="2015-09-10T20:50:18.183896Z">
|
49
|
+
```
|
50
|
+
|
51
|
+
#### Get all users associated with the current organization
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
client.organization.users
|
55
|
+
# => [
|
56
|
+
# [0] #<Helium::User:0x007fd3d9449490 @client=<Helium::Client @debug=true>, @id="tom@helium.com", @name="Tom Santero", @email="tom@helium.com", @created_at="2015-01-21T16:39:31.397048Z", @updated_at="2015-02-12T20:42:22.674452Z">,
|
57
|
+
# [1] #<Helium::User:0x007fd3d94492d8 @client=<Helium::Client @debug=true>, @id="dev-accounts@helium.co", @name="HeliumDevAccount Demo", @email="dev-accounts@helium.co", @created_at="2014-10-29T21:38:52Z", @updated_at="2015-08-06T18:21:32.186374Z">
|
58
|
+
# ]
|
59
|
+
```
|
60
|
+
|
61
|
+
### Sensors
|
62
|
+
|
63
|
+
#### Get all Sensors
|
64
|
+
```ruby
|
65
|
+
client.sensors
|
66
|
+
# => [#<Helium::Sensor:0x007f89acdd1318 @id="08bab58b-d095-4c7c-912c-1f8024d91d95", @name="Marc's Isotope", @mac="6081f9fffe00019b", @ports=["t", "b"], @created_at="2015-08-06T17:28:11.614107Z", @updated_at="2016-05-30T22:36:50.810716Z">, ...]
|
67
|
+
```
|
68
|
+
|
69
|
+
#### Get a Sensor by id
|
70
|
+
```ruby
|
71
|
+
client.sensor("08bab58b-d095-4c7c-912c-1f8024d91d95")
|
72
|
+
# => #<Helium::Sensor:0x007f89acdb1b58 @id="08bab58b-d095-4c7c-912c-1f8024d91d95", @name="Marc's Isotope", @mac="6081f9fffe00019b", @ports=["t", "b"], @created_at="2015-08-06T17:28:11.614107Z", @updated_at="2016-05-30T22:36:50.810716Z">
|
73
|
+
```
|
74
|
+
|
75
|
+
### Timeseries
|
76
|
+
|
77
|
+
#### Get Timeseries data for a sensor
|
78
|
+
```ruby
|
79
|
+
sensor = client.sensor("08bab58b-d095-4c7c-912c-1f8024d91d95")
|
80
|
+
sensor.timeseries
|
81
|
+
# => #<Helium::Timeseries:0x007ff9dd92efa8 @data_points=[#<Helium::DataPoint:0x007ff9dd92ee18 @id="a4107e78-f15e-4c31-aab3-497bbfe3e33c", @timestamp="2015-08-11T18:50:04Z", @value=-40.125, @port="t">, ...
|
82
|
+
```
|
83
|
+
|
84
|
+
#### Working with data points
|
85
|
+
A `Helium::Timeseries` is a collection of `Helium::DataPoint`s which can be accessed by calling `.data_points`, or iterated over using the usual `Object#Enumerable` methods:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
sensor.timeseries.each do |data_point|
|
89
|
+
puts data_point.id
|
90
|
+
puts data_point.timestamp
|
91
|
+
puts data_point.value
|
92
|
+
puts data_point.port
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
#### Filtering Timeseries data
|
97
|
+
Timeseries data can be filtered by port type and start/end time:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
sensor.timeseries.collect(&:port).uniq
|
101
|
+
# => [
|
102
|
+
# [0] "b",
|
103
|
+
# [1] "l",
|
104
|
+
# [2] "h",
|
105
|
+
# [3] "p",
|
106
|
+
# [4] "t",
|
107
|
+
# [5] "_se",
|
108
|
+
# [6] "m"
|
109
|
+
# ]
|
110
|
+
|
111
|
+
sensor.timeseries(port: 't').collect(&:port).uniq
|
112
|
+
# => [
|
113
|
+
# [0] "t"
|
114
|
+
# ]
|
115
|
+
|
116
|
+
sensor.timeseries(start_time: DateTime.parse("2016-08-01"), end_time: DateTime.parse("2016-08-02")).collect(&:timestamp)
|
117
|
+
# => [
|
118
|
+
# [0] #<DateTime: 2016-08-01T23:55:29+00:00 ((2457602j,86129s,802000000n),+0s,2299161j)>,
|
119
|
+
# [1] #<DateTime: 2016-08-01T23:55:29+00:00 ((2457602j,86129s,61000000n),+0s,2299161j)>,
|
120
|
+
# [2] #<DateTime: 2016-08-01T23:55:29+00:00 ((2457602j,86129s,60000000n),+0s,2299161j)>,
|
121
|
+
# [3] #<DateTime: 2016-08-01T23:55:29+00:00 ((2457602j,86129s,59000000n),+0s,2299161j)>,
|
122
|
+
# [4] #<DateTime: 2016-08-01T23:54:45+00:00 ((2457602j,86085s,544000000n),+0s,2299161j)>,
|
123
|
+
```
|
124
|
+
|
125
|
+
#### Paging through Timeseries data
|
126
|
+
Timeseries data is paginated at the API level. By default, 1000 data points are returned. This amount can be increased up to 10,000:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
sensor.timeseries(size: 10_000).length
|
130
|
+
# => 10000
|
131
|
+
```
|
132
|
+
|
133
|
+
The data points are sorted from most recent, to least recent. The `.previous` method on a `Helium::Timeseries` object will return a new `Helium::Timeseries` object with the next page of Timeseries data:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
timeseries = sensor.timeseries
|
137
|
+
# => #<Helium::Timeseries:0x007ff9e10d2c48 @data_points=[#<Helium::DataPoint:0x007ff9e10d2568 @id="3595e562-c065-442e-a3af-c6f43ddb1500", @timestamp="2016-08-10T13:21:49.866Z", @value=27, @port="l">, ...
|
138
|
+
|
139
|
+
timeseries.previous
|
140
|
+
# => #<Helium::Timeseries:0x007ff9dc141008 @data_points=[#<Helium::DataPoint:0x007ff9dc140f68 @id="1e4062cf-361d-415e-8c05-cd04954424d1", @timestamp="2016-08-10T13:11:49.353Z", @value=99804.15, @port="p">, ...
|
141
|
+
```
|
142
|
+
|
143
|
+
If no previous data exists, the `.previous` method will return `false`.
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
sensor.timeseries.previous
|
147
|
+
# => false
|
148
|
+
```
|
149
|
+
|
150
|
+
|
151
|
+
## Development
|
152
|
+
|
153
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
154
|
+
|
155
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
156
|
+
|
157
|
+
### Roadmap
|
158
|
+
- [ ] Timeseries Aggregations
|
159
|
+
- [ ] POST/PUT/DELETE users, orgs, sensors, timeseries
|
160
|
+
- [ ] Ports
|
161
|
+
- [ ] Labels
|
162
|
+
- [ ] Elements
|
163
|
+
|
164
|
+
## Contributing
|
165
|
+
|
166
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/helium/helium-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
167
|
+
|
168
|
+
### Running specs with Guard
|
169
|
+
|
170
|
+
To receive system notifications of test status, install `terminal-notifier`:
|
171
|
+
```
|
172
|
+
$ brew install terminal-notifier
|
173
|
+
```
|
174
|
+
|
175
|
+
Then run Guard with:
|
176
|
+
```
|
177
|
+
$ bundle exec guard
|
178
|
+
```
|
179
|
+
|
180
|
+
When you modify any of the files in `lib/`, all specs will run. When you modify a spec file, just that file will be run. You can press `Enter` at the guard prompt to run all tests as well.
|
181
|
+
|
182
|
+
## License
|
183
|
+
|
184
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "helium"
|
5
|
+
|
6
|
+
class Object
|
7
|
+
API_KEY = ENV['HELIUM_API_KEY'].freeze
|
8
|
+
|
9
|
+
def client
|
10
|
+
return nil if API_KEY.nil?
|
11
|
+
@client ||= Helium::Client.new(api_key: API_KEY, debug: true)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
require "pry"
|
16
|
+
Pry.start
|
data/bin/setup
ADDED
data/helium-ruby.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'helium/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "helium-ruby"
|
8
|
+
spec.version = Helium::VERSION
|
9
|
+
spec.authors = ["Andrew Allen"]
|
10
|
+
spec.email = ["allenan@helium.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A Ruby gem for building applications with the Helium API}
|
13
|
+
spec.description = %q{A Ruby gem for building applications with the Helium API}
|
14
|
+
spec.homepage = "https://github.com/helium/helium-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency "typhoeus", "~> 1.1.0"
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
spec.add_development_dependency "vcr", "~> 3.0.3"
|
36
|
+
spec.add_development_dependency "coveralls", "~> 0.8.2"
|
37
|
+
spec.add_development_dependency "pry", "~> 0.10.4"
|
38
|
+
spec.add_development_dependency "awesome_print", "~> 1.7.0"
|
39
|
+
spec.add_development_dependency "guard", "~> 2.14.0"
|
40
|
+
spec.add_development_dependency "guard-rspec", "~> 4.7.3"
|
41
|
+
spec.add_development_dependency "terminal-notifier-guard", "~> 1.7.0"
|
42
|
+
spec.add_development_dependency "simplecov", "~> 0.12.0"
|
43
|
+
end
|
data/lib/helium.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
require 'json'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
require "helium/version"
|
6
|
+
require "helium/utils"
|
7
|
+
require "helium/client"
|
8
|
+
require "helium/user"
|
9
|
+
require "helium/organization"
|
10
|
+
require "helium/sensor"
|
11
|
+
require "helium/timeseries"
|
12
|
+
require "helium/data_point"
|
13
|
+
|
14
|
+
module Helium
|
15
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'helium/client/http'
|
2
|
+
require 'helium/client/users'
|
3
|
+
require 'helium/client/organizations'
|
4
|
+
require 'helium/client/sensors'
|
5
|
+
|
6
|
+
module Helium
|
7
|
+
class Client
|
8
|
+
include Helium::Utils
|
9
|
+
include Helium::Client::Http
|
10
|
+
include Helium::Client::Users
|
11
|
+
include Helium::Client::Organizations
|
12
|
+
include Helium::Client::Sensors
|
13
|
+
|
14
|
+
API_VERSION = 1
|
15
|
+
HOST = 'api.helium.com'
|
16
|
+
PROTOCOL = 'https'
|
17
|
+
|
18
|
+
BASE_HTTP_HEADERS = {
|
19
|
+
'Accept' => 'application/json',
|
20
|
+
'Content-Type' => 'application/json',
|
21
|
+
'User-Agent' => 'helium-ruby'
|
22
|
+
}
|
23
|
+
|
24
|
+
attr_accessor :api_key
|
25
|
+
|
26
|
+
def initialize(api_key:, debug: false)
|
27
|
+
@api_key = api_key
|
28
|
+
@debug = debug
|
29
|
+
end
|
30
|
+
|
31
|
+
def inspect
|
32
|
+
"<Helium::Client @debug=#{@debug}>"
|
33
|
+
end
|
34
|
+
|
35
|
+
def debug?
|
36
|
+
@debug == true
|
37
|
+
end
|
38
|
+
|
39
|
+
def http_headers
|
40
|
+
BASE_HTTP_HEADERS.merge({
|
41
|
+
'Authorization' => api_key
|
42
|
+
})
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Helium
|
2
|
+
class Client
|
3
|
+
module Http
|
4
|
+
def get(path = nil, url: nil, options: {})
|
5
|
+
path = path.gsub(/^\//, '') if path
|
6
|
+
url ||= "#{PROTOCOL}://#{HOST}/v#{API_VERSION}/#{path}"
|
7
|
+
|
8
|
+
request = Typhoeus::Request.new(url, {
|
9
|
+
params: options,
|
10
|
+
headers: http_headers
|
11
|
+
})
|
12
|
+
|
13
|
+
run(request)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def run(request)
|
19
|
+
request.run()
|
20
|
+
|
21
|
+
if debug?
|
22
|
+
puts "GET #{url} #{request.response.code} #{request.response.total_time}"
|
23
|
+
# puts request.response.body
|
24
|
+
end
|
25
|
+
|
26
|
+
# TODO error handling
|
27
|
+
# halt(request.response.code, "Helium Get Failed: #{request.response.code.to_s}") unless request.response.code.between?(200,399)\
|
28
|
+
|
29
|
+
return request.response
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Helium
|
2
|
+
class Client
|
3
|
+
module Organizations
|
4
|
+
def organization
|
5
|
+
response = get('/organization')
|
6
|
+
org_data = JSON.parse(response.body)["data"]
|
7
|
+
return Organization.new(client: self, params: org_data)
|
8
|
+
end
|
9
|
+
|
10
|
+
def organization_users
|
11
|
+
response = get('/organization/user')
|
12
|
+
users_data = JSON.parse(response.body)["data"]
|
13
|
+
|
14
|
+
users = users_data.map do |user_data|
|
15
|
+
User.new(client: self, params: user_data)
|
16
|
+
end
|
17
|
+
|
18
|
+
return users
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Helium
|
2
|
+
class Client
|
3
|
+
module Sensors
|
4
|
+
def sensors
|
5
|
+
response = get('/sensor')
|
6
|
+
sensors_data = JSON.parse(response.body)["data"]
|
7
|
+
|
8
|
+
sensors = sensors_data.map do |sensor_data|
|
9
|
+
Sensor.new(client: self, params: sensor_data)
|
10
|
+
end
|
11
|
+
|
12
|
+
return sensors
|
13
|
+
end
|
14
|
+
|
15
|
+
def sensor(id)
|
16
|
+
response = get("/sensor/#{id}")
|
17
|
+
sensor_data = JSON.parse(response.body)["data"]
|
18
|
+
|
19
|
+
return Sensor.new(client: self, params: sensor_data)
|
20
|
+
end
|
21
|
+
|
22
|
+
def sensor_timeseries(sensor, size: 1000, port: nil, start_time: nil, end_time: nil)
|
23
|
+
options = {
|
24
|
+
"page[size]" => size,
|
25
|
+
"filter[port]" => port,
|
26
|
+
"filter[start]" => datetime_to_iso(start_time),
|
27
|
+
"filter[end]" => datetime_to_iso(end_time)
|
28
|
+
}.delete_if { |key, value| value.to_s.empty? }
|
29
|
+
|
30
|
+
response = get("/sensor/#{sensor.id}/timeseries", options: options)
|
31
|
+
json_results = JSON.parse(response.body)
|
32
|
+
timeseries_data = json_results["data"]
|
33
|
+
timeseries_links = json_results["links"]
|
34
|
+
|
35
|
+
return Timeseries.new(
|
36
|
+
client: self,
|
37
|
+
params: timeseries_data,
|
38
|
+
links: timeseries_links
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def sensor_timeseries_by_link(url)
|
43
|
+
response = get(url: url)
|
44
|
+
json_results = JSON.parse(response.body)
|
45
|
+
timeseries_data = json_results["data"]
|
46
|
+
timeseries_links = json_results["links"]
|
47
|
+
|
48
|
+
return Timeseries.new(
|
49
|
+
client: self,
|
50
|
+
params: timeseries_data,
|
51
|
+
links: timeseries_links
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Helium
|
2
|
+
class DataPoint
|
3
|
+
attr_accessor :id, :timestamp, :value, :port
|
4
|
+
|
5
|
+
def initialize(client:, params:)
|
6
|
+
@client = client
|
7
|
+
@id = params["id"]
|
8
|
+
@timestamp = params["attributes"]["timestamp"]
|
9
|
+
@value = params["attributes"]["value"]
|
10
|
+
@port = params["attributes"]["port"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def timestamp
|
14
|
+
DateTime.parse(@timestamp)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Helium
|
2
|
+
class Organization
|
3
|
+
attr_accessor :id, :name, :timezone, :created_at, :updated_at
|
4
|
+
|
5
|
+
def initialize(client:, params:)
|
6
|
+
@client = client
|
7
|
+
@id = params["id"]
|
8
|
+
@name = params["attributes"]["name"]
|
9
|
+
@timezone = params["attributes"]["timezone"]
|
10
|
+
@created_at = params["meta"]["created"]
|
11
|
+
@updated_at = params["meta"]["updated"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def created_at
|
15
|
+
DateTime.parse(@created_at)
|
16
|
+
end
|
17
|
+
|
18
|
+
def updated_at
|
19
|
+
DateTime.parse(@updated_at)
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO refactor into relationships
|
23
|
+
def users
|
24
|
+
@client.organization_users
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Helium
|
2
|
+
class Sensor
|
3
|
+
attr_accessor :id, :name, :mac, :ports, :created_at, :updated_at
|
4
|
+
|
5
|
+
def initialize(client:, params:)
|
6
|
+
@client = client
|
7
|
+
@id = params["id"]
|
8
|
+
@name = params["attributes"]["name"]
|
9
|
+
@mac = params["meta"]["mac"]
|
10
|
+
@ports = params["meta"]["ports"]
|
11
|
+
@created_at = params["meta"]["created"]
|
12
|
+
@updated_at = params["meta"]["updated"]
|
13
|
+
end
|
14
|
+
|
15
|
+
def created_at
|
16
|
+
DateTime.parse(@created_at)
|
17
|
+
end
|
18
|
+
|
19
|
+
def updated_at
|
20
|
+
DateTime.parse(@updated_at)
|
21
|
+
end
|
22
|
+
|
23
|
+
def timeseries(size: 1000, port: nil, start_time: nil, end_time: nil)
|
24
|
+
@client.sensor_timeseries(self,
|
25
|
+
size: size,
|
26
|
+
port: port,
|
27
|
+
start_time: start_time,
|
28
|
+
end_time: end_time
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Helium
|
2
|
+
class Timeseries
|
3
|
+
include Enumerable
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
def_delegators :@data_points, :size, :length, :last
|
7
|
+
|
8
|
+
attr_accessor :data_points, :previous_link
|
9
|
+
|
10
|
+
def initialize(client:, params:, links:)
|
11
|
+
@client = client
|
12
|
+
@data_points = params.map { |data_point_params|
|
13
|
+
DataPoint.new(client: client, params: data_point_params)
|
14
|
+
}
|
15
|
+
@previous_link = links["prev"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def each(&block)
|
19
|
+
@data_points.each(&block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def previous
|
23
|
+
return false if @previous_link.nil?
|
24
|
+
@client.sensor_timeseries_by_link(@previous_link)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/helium/user.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Helium
|
2
|
+
class User
|
3
|
+
attr_accessor :id, :name, :email, :created_at, :updated_at
|
4
|
+
|
5
|
+
def initialize(client:, params:)
|
6
|
+
@client = client
|
7
|
+
@id = params["id"]
|
8
|
+
@name = params["attributes"]["name"]
|
9
|
+
@email = params["meta"]["email"]
|
10
|
+
@created_at = params["meta"]["created"]
|
11
|
+
@updated_at = params["meta"]["updated"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def created_at
|
15
|
+
DateTime.parse(@created_at)
|
16
|
+
end
|
17
|
+
|
18
|
+
def updated_at
|
19
|
+
DateTime.parse(@updated_at)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/helium/utils.rb
ADDED
metadata
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: helium-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Allen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: typhoeus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: vcr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.0.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.0.3
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.8.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.8.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.10.4
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.10.4
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: awesome_print
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.7.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.7.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.14.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.14.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: guard-rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 4.7.3
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 4.7.3
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: terminal-notifier-guard
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 1.7.0
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 1.7.0
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: simplecov
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 0.12.0
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 0.12.0
|
181
|
+
description: A Ruby gem for building applications with the Helium API
|
182
|
+
email:
|
183
|
+
- allenan@helium.com
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- ".gitignore"
|
189
|
+
- ".rspec"
|
190
|
+
- ".travis.yml"
|
191
|
+
- CODE_OF_CONDUCT.md
|
192
|
+
- Gemfile
|
193
|
+
- Guardfile
|
194
|
+
- LICENSE.txt
|
195
|
+
- README.md
|
196
|
+
- Rakefile
|
197
|
+
- bin/console
|
198
|
+
- bin/setup
|
199
|
+
- helium-ruby.gemspec
|
200
|
+
- lib/helium.rb
|
201
|
+
- lib/helium/client.rb
|
202
|
+
- lib/helium/client/http.rb
|
203
|
+
- lib/helium/client/organizations.rb
|
204
|
+
- lib/helium/client/sensors.rb
|
205
|
+
- lib/helium/client/users.rb
|
206
|
+
- lib/helium/data_point.rb
|
207
|
+
- lib/helium/organization.rb
|
208
|
+
- lib/helium/sensor.rb
|
209
|
+
- lib/helium/timeseries.rb
|
210
|
+
- lib/helium/user.rb
|
211
|
+
- lib/helium/utils.rb
|
212
|
+
- lib/helium/version.rb
|
213
|
+
homepage: https://github.com/helium/helium-ruby
|
214
|
+
licenses:
|
215
|
+
- MIT
|
216
|
+
metadata:
|
217
|
+
allowed_push_host: https://rubygems.org
|
218
|
+
post_install_message:
|
219
|
+
rdoc_options: []
|
220
|
+
require_paths:
|
221
|
+
- lib
|
222
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
223
|
+
requirements:
|
224
|
+
- - ">="
|
225
|
+
- !ruby/object:Gem::Version
|
226
|
+
version: '0'
|
227
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
228
|
+
requirements:
|
229
|
+
- - ">="
|
230
|
+
- !ruby/object:Gem::Version
|
231
|
+
version: '0'
|
232
|
+
requirements: []
|
233
|
+
rubyforge_project:
|
234
|
+
rubygems_version: 2.5.1
|
235
|
+
signing_key:
|
236
|
+
specification_version: 4
|
237
|
+
summary: A Ruby gem for building applications with the Helium API
|
238
|
+
test_files: []
|