helium-ruby 0.21.0 → 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -4
- data/docs/Helium.html +2 -2
- data/docs/Helium/Client.html +3 -3
- data/docs/Helium/Client/Configurations.html +1 -1
- data/docs/Helium/Client/DeviceConfigurations.html +1 -1
- data/docs/Helium/Client/Elements.html +1 -1
- data/docs/Helium/Client/Http.html +222 -39
- data/docs/Helium/Client/Labels.html +1 -1
- data/docs/Helium/Client/Organizations.html +1 -1
- data/docs/Helium/Client/Sensors.html +77 -5
- data/docs/Helium/Client/Users.html +1 -1
- data/docs/Helium/ClientError.html +1 -1
- data/docs/Helium/Collection.html +4 -4
- data/docs/Helium/Configuration.html +1 -1
- data/docs/Helium/Cursor.html +1 -1
- data/docs/Helium/DataPoint.html +1 -1
- data/docs/Helium/DeviceConfiguration.html +1 -1
- data/docs/Helium/Element.html +1 -1
- data/docs/Helium/Error.html +1 -1
- data/docs/Helium/InvalidApiKey.html +1 -1
- data/docs/Helium/Label.html +1 -1
- data/docs/Helium/Metadata.html +1 -1
- data/docs/Helium/Organization.html +1 -1
- data/docs/Helium/Resource.html +1 -1
- data/docs/Helium/Sensor.html +91 -15
- data/docs/Helium/Timeseries.html +1 -1
- data/docs/Helium/User.html +1 -1
- data/docs/Helium/Utils.html +1 -1
- data/docs/_index.html +1 -1
- data/docs/file.README.html +36 -4
- data/docs/index.html +36 -4
- data/docs/method_list.html +137 -113
- data/docs/top-level-namespace.html +1 -1
- data/lib/helium/client/http.rb +51 -9
- data/lib/helium/client/sensors.rb +14 -0
- data/lib/helium/collection.rb +2 -2
- data/lib/helium/sensor.rb +16 -0
- data/lib/helium/version.rb +1 -1
- metadata +2 -2
@@ -102,7 +102,7 @@
|
|
102
102
|
</div>
|
103
103
|
|
104
104
|
<div id="footer">
|
105
|
-
Generated on
|
105
|
+
Generated on Mon Feb 13 09:17:41 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>
|
data/lib/helium/client/http.rb
CHANGED
@@ -2,8 +2,6 @@ module Helium
|
|
2
2
|
class Client
|
3
3
|
module Http
|
4
4
|
BASE_HTTP_HEADERS = {
|
5
|
-
'Accept' => 'application/json',
|
6
|
-
'Content-Type' => 'application/json',
|
7
5
|
'User-Agent' => 'helium-ruby'
|
8
6
|
}
|
9
7
|
|
@@ -36,6 +34,32 @@ module Helium
|
|
36
34
|
response.code == 204
|
37
35
|
end
|
38
36
|
|
37
|
+
# Stream data from the provided path
|
38
|
+
# @param [String] path a relative path
|
39
|
+
# @option opts [Class] :klass a class to be initialized with received data
|
40
|
+
# @option opts [Hash] :params a hash of params to be used as query params
|
41
|
+
# @yield [Helium::Resource] accepts logic to perform on the initialized Helium::Resource class
|
42
|
+
def stream_from(path, opts = {}, &block)
|
43
|
+
klass = opts.fetch(:klass)
|
44
|
+
params = opts.fetch(:params, {})
|
45
|
+
request = generate_request(path, {
|
46
|
+
method: :get,
|
47
|
+
content_type: :stream,
|
48
|
+
params: params
|
49
|
+
})
|
50
|
+
|
51
|
+
request.on_body do |chunk|
|
52
|
+
if chunk =~ /data:/
|
53
|
+
json_string = chunk[chunk.index('{')..chunk.rindex('}')]
|
54
|
+
json_data = JSON.parse(json_string)["data"]
|
55
|
+
object = klass.new(client: self, params: json_data)
|
56
|
+
yield object
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
run_request(request)
|
61
|
+
end
|
62
|
+
|
39
63
|
def base_url
|
40
64
|
url = "#{PROTOCOL}://#{@api_host}"
|
41
65
|
url += "/#{@api_version}" if @api_version
|
@@ -53,12 +77,29 @@ module Helium
|
|
53
77
|
|
54
78
|
private
|
55
79
|
|
56
|
-
def http_headers
|
57
|
-
|
80
|
+
def http_headers(opts = {})
|
81
|
+
content_type = opts.fetch(:content_type, :json)
|
82
|
+
|
83
|
+
http_headers = BASE_HTTP_HEADERS
|
58
84
|
.merge(@headers)
|
59
85
|
.merge({
|
60
86
|
'Authorization' => api_key
|
61
87
|
})
|
88
|
+
|
89
|
+
case content_type
|
90
|
+
when :json
|
91
|
+
http_headers.merge!({
|
92
|
+
'Accept' => 'application/json',
|
93
|
+
'Content-Type' => 'application/json'
|
94
|
+
})
|
95
|
+
when :stream
|
96
|
+
http_headers.merge!({
|
97
|
+
'Accept' => 'text/event-stream',
|
98
|
+
'Content-Type' => 'text/event-stream'
|
99
|
+
})
|
100
|
+
end
|
101
|
+
|
102
|
+
return http_headers
|
62
103
|
end
|
63
104
|
|
64
105
|
def run(path, method, opts = {})
|
@@ -68,15 +109,16 @@ module Helium
|
|
68
109
|
end
|
69
110
|
|
70
111
|
def generate_request(path, opts = {})
|
71
|
-
method
|
72
|
-
|
73
|
-
|
74
|
-
|
112
|
+
method = opts.fetch(:method)
|
113
|
+
content_type = opts.fetch(:content_type, :json)
|
114
|
+
params = opts.fetch(:params, {})
|
115
|
+
body = opts.fetch(:body, {})
|
116
|
+
url = url_for(path)
|
75
117
|
|
76
118
|
Typhoeus::Request.new(url, {
|
77
119
|
method: method,
|
78
120
|
params: params,
|
79
|
-
headers: http_headers,
|
121
|
+
headers: http_headers(content_type: content_type),
|
80
122
|
ssl_verifypeer: @verify_peer,
|
81
123
|
body: JSON.generate(body)
|
82
124
|
})
|
@@ -45,6 +45,20 @@ module Helium
|
|
45
45
|
)
|
46
46
|
end
|
47
47
|
|
48
|
+
def sensor_live_timeseries(sensor, opts = {}, &block)
|
49
|
+
path = "/sensor/#{sensor.id}/timeseries/live"
|
50
|
+
|
51
|
+
params = {
|
52
|
+
"filter[port]" => opts.fetch(:port, nil),
|
53
|
+
"filter[start]" => datetime_to_iso(opts.fetch(:start_time, nil)),
|
54
|
+
"filter[end]" => datetime_to_iso(opts.fetch(:end_time, nil)),
|
55
|
+
"agg[type]" => opts.fetch(:aggtype),
|
56
|
+
"agg[size]" => opts.fetch(:aggsize)
|
57
|
+
}.delete_if { |_key, value| value.to_s.empty? }
|
58
|
+
|
59
|
+
stream_from(path, klass: Helium::DataPoint, params: params, &block)
|
60
|
+
end
|
61
|
+
|
48
62
|
def create_sensor(attributes)
|
49
63
|
Sensor.create(attributes, client: self)
|
50
64
|
end
|
data/lib/helium/collection.rb
CHANGED
@@ -23,7 +23,7 @@ module Helium
|
|
23
23
|
# Uses metadata filtering
|
24
24
|
# (https://docs.helium.com/api/v1/metadata/index.html#filtering)
|
25
25
|
# to search for a collection of resources matching the search parameters
|
26
|
-
# @param [Hash] a set of search criteria
|
26
|
+
# @param [Hash] criteria a set of search criteria
|
27
27
|
#
|
28
28
|
# @example Search for sensors by location
|
29
29
|
# client.sensors.where(location: 'Building B') #=> [Sensor, Sensor]
|
@@ -31,7 +31,7 @@ module Helium
|
|
31
31
|
# @example Search for multiple matching search parameters
|
32
32
|
# client.sensors.where(departments: ['it', 'engineering']) #=> [Sensor, Sensor]
|
33
33
|
#
|
34
|
-
# @return [Collection] a
|
34
|
+
# @return [Collection] a collection of resources matching the provided search criteria
|
35
35
|
def where(criteria)
|
36
36
|
add_filter_criteria(criteria)
|
37
37
|
self
|
data/lib/helium/sensor.rb
CHANGED
@@ -49,6 +49,22 @@ module Helium
|
|
49
49
|
)
|
50
50
|
end
|
51
51
|
|
52
|
+
def live_timeseries(opts = {}, &block)
|
53
|
+
port = opts.fetch(:port, nil)
|
54
|
+
start_time = opts.fetch(:start_time, nil)
|
55
|
+
end_time = opts.fetch(:end_time, nil)
|
56
|
+
aggtype = opts.fetch(:aggtype, nil)
|
57
|
+
aggsize = opts.fetch(:aggsize, nil)
|
58
|
+
|
59
|
+
@client.sensor_live_timeseries(self, {
|
60
|
+
port: port,
|
61
|
+
start_time: start_time,
|
62
|
+
end_time: end_time,
|
63
|
+
aggtype: aggtype,
|
64
|
+
aggsize: aggsize
|
65
|
+
}, &block)
|
66
|
+
end
|
67
|
+
|
52
68
|
# @return [DateTime, nil] when the resource was last seen
|
53
69
|
def last_seen
|
54
70
|
return nil if @last_seen.nil?
|
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.22.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-
|
12
|
+
date: 2017-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: typhoeus
|