neurio 0.0.1
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.
- checksums.yaml +7 -0
- data/lib/neurio.rb +64 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 488f5c1086893d8fea4198e70eb742941b49d565
|
4
|
+
data.tar.gz: a3af973e89fa390c9ac8d39d5dcfd39885041f75
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5f6db2b12cd6883537ff826214b54503022bba68e8831b4fedbd309ef4c7573d09f290ab01256cf9088ca255f01965e3a1d8caae6ecedd18a2c25c7626b7d13
|
7
|
+
data.tar.gz: 282eb981f7becbda6ee49010ef9db2e4c147b82a8f41981c489c160a7158368bda44e1b85ed10d10ce1c03dca5f2b610c747612625cc8107d405ec14e133e063
|
data/lib/neurio.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class Neurio
|
4
|
+
include HTTParty
|
5
|
+
base_uri "https://api.neur.io"
|
6
|
+
|
7
|
+
class Reading
|
8
|
+
attr_reader :consumption_power, :consumption_energy, :timestamp
|
9
|
+
def initialize(values)
|
10
|
+
@timestamp = DateTime.parse(values["timestamp"]).to_time
|
11
|
+
@consumption_power = values["consumptionPower"]
|
12
|
+
@consumption_energy = values["consumptionEnergy"]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def initialize(options)
|
18
|
+
@client_secret = options[:client_secret]
|
19
|
+
@client_id = options[:client_id]
|
20
|
+
raise ArgumentError.new("client_id and client_secret must be specified") unless @client_secret && @client_id
|
21
|
+
end
|
22
|
+
|
23
|
+
def last(sensor_id = default_sensor_id)
|
24
|
+
headers = {"content_type" => "application/json", "authorization" => "Bearer #{token}"}
|
25
|
+
query = {"sensorId" => sensor_id}
|
26
|
+
response = self.class.get("/v1/samples/live/last", :headers => headers, :query => query)
|
27
|
+
Reading.new(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
def user
|
31
|
+
unless @user
|
32
|
+
headers = {"content_type" => "application/json", "authorization" => "Bearer #{token}"}
|
33
|
+
@user = self.class.get("/v1/users/current", :headers => headers)
|
34
|
+
end
|
35
|
+
@user
|
36
|
+
end
|
37
|
+
|
38
|
+
def default_sensor_id
|
39
|
+
user["locations"][0]["sensors"][0]["sensorId"]
|
40
|
+
end
|
41
|
+
|
42
|
+
def live(last_timestamp = nil, sensor_id = default_sensor_id)
|
43
|
+
headers = {"content_type" => "application/json", "authorization" => "Bearer #{token}"}
|
44
|
+
query = {"sensorId" => sensor_id}
|
45
|
+
if last_timestamp
|
46
|
+
query["last"] = last_timestamp.iso8601(3)
|
47
|
+
end
|
48
|
+
|
49
|
+
response = self.class.get("/v1/samples/live", :headers => headers, :query => query)
|
50
|
+
response.map{|x| Reading.new(x)}
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def token
|
55
|
+
unless @token
|
56
|
+
options = {"grant_type" => "client_credentials", "client_id" => @client_id, "client_secret" => @client_secret}
|
57
|
+
response = self.class.post("/v1/oauth2/token", :body => options)
|
58
|
+
|
59
|
+
@token = response["access_token"]
|
60
|
+
end
|
61
|
+
@token
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: neurio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joe Francis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.13'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.13.5
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.13'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.13.5
|
33
|
+
description: API functionality for Neurio energy monitoring devices. See http://neur.io/
|
34
|
+
email: joe@lostapathy.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- lib/neurio.rb
|
40
|
+
homepage: http://rubygems.org/gems/neurio
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.4.5
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Neurio API
|
64
|
+
test_files: []
|