amon 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/amon/device.rb +11 -5
- data/lib/amon/reading.rb +21 -11
- data/lib/amon/session.rb +17 -7
- data/lib/amon/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -3,7 +3,7 @@ Ruby Client for the AMEE AMON API
|
|
3
3
|
|
4
4
|
This is a Ruby client library for the [AMEE](http://www.amee.com/) <abbr title="AMEE Monitoring Object Notation">AMON</abbr> <abbr title="Application Programming Interface">API</abbr>. _More details and links to be inserted once information about the API is publicly available_.
|
5
5
|
|
6
|
-
This is version 0.
|
6
|
+
This is version 0.7.0 and is built to support AMON V3: https://github.com/AMEE/amon
|
7
7
|
|
8
8
|
## Installation ##
|
9
9
|
|
data/lib/amon/device.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
module AMON
|
2
|
-
# An AMON device, containing any number of {Reading readings}, and
|
2
|
+
# An AMON device, containing any number of {Reading readings}, and
|
3
|
+
# {Measurement measurements} for those readings.
|
3
4
|
class Device < Document
|
4
5
|
# @return [String] The id of the device
|
5
6
|
field :id, :name => 'deviceId'
|
6
7
|
|
8
|
+
# @return [Time] The latest measurement start date, if provided
|
9
|
+
field :earliest_measurement, :name => 'earliestMeasurement', :as => Time
|
10
|
+
|
7
11
|
# @return [Time] The latest measurement start date, if provided
|
8
12
|
field :latest_measurement, :name => 'latestMeasurement', :as => Time
|
9
13
|
|
@@ -32,8 +36,8 @@ module AMON
|
|
32
36
|
@readings ||= json['readings'].map { |reading| Reading.new(self, reading) }
|
33
37
|
end
|
34
38
|
|
35
|
-
# @return [Hash<String => Reading>] A hash allowing {Device#readings} to
|
36
|
-
# {Reading#type}
|
39
|
+
# @return [Hash<String => Reading>] A hash allowing {Device#readings} to
|
40
|
+
# be retrieved by their {Reading#type}
|
37
41
|
def readings_by_type
|
38
42
|
readings.inject({}) do |readings_by_type, reading|
|
39
43
|
readings_by_type[reading.type] = reading
|
@@ -47,8 +51,10 @@ module AMON
|
|
47
51
|
session.measurements(entity_id, id, start_date, end_date, raw)
|
48
52
|
end
|
49
53
|
|
50
|
-
# @return [Hash<String => Measurement>] A hash allowing
|
51
|
-
#
|
54
|
+
# @return [Hash<String => Measurement>] A hash allowing
|
55
|
+
# {Device#measurements} to be
|
56
|
+
# retrieved by their
|
57
|
+
# {Measurement#name}
|
52
58
|
# @see Device#measurements
|
53
59
|
def measurements_by_name(entity_id, start_date, end_date, raw = false)
|
54
60
|
measurements(entity_id, start_date, end_date, raw).inject({}) do |measurements_by_name, measurement|
|
data/lib/amon/reading.rb
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
module AMON
|
2
|
-
|
3
|
-
#
|
2
|
+
|
3
|
+
# AMON readings are 'categories' of {Measurement measurements} which are
|
4
|
+
# taken by {Device devices}. For example, one reading may be 'electricalInput'
|
5
|
+
# with the unit 'kWh'.
|
4
6
|
class Reading < DocumentPart
|
5
|
-
|
7
|
+
|
8
|
+
# @return [String] The type of reading, which is unique within the parent
|
9
|
+
# {Device device}
|
6
10
|
field :type
|
7
11
|
|
8
12
|
# @return [String] An arbitrary name for the reading
|
9
13
|
field :name
|
10
14
|
|
11
|
-
# @return [String] The units this reading records
|
15
|
+
# @return [String] The units this reading records
|
16
|
+
# {Measurement measurements} in
|
12
17
|
field :unit
|
13
18
|
|
14
19
|
# @return [Numeric] The resolution of the reading
|
@@ -17,8 +22,9 @@ module AMON
|
|
17
22
|
# @return [Numeric] The accuracy of the reading
|
18
23
|
field :accuracy
|
19
24
|
|
20
|
-
# @return ["instant", "duration"] Whether this reading records measurement
|
21
|
-
# specific point in time ('instant'), or taken as an
|
25
|
+
# @return ["instant", "duration"] Whether this reading records measurement
|
26
|
+
# values taken at a specific point in time ('instant'), or taken as an
|
27
|
+
# average over a period of time ('duration')
|
22
28
|
field :period, :default => "instant"
|
23
29
|
|
24
30
|
# @attr_reader [Device device] The device which took this measurement
|
@@ -41,19 +47,23 @@ module AMON
|
|
41
47
|
!instantaneous?
|
42
48
|
end
|
43
49
|
|
44
|
-
# One reading is equal to another if the devices are equal and they are the
|
50
|
+
# One reading is equal to another if the devices are equal and they are the
|
51
|
+
# same type
|
45
52
|
# @return [Boolean]
|
46
53
|
# @param [Reading] other The other reading to compare with.
|
47
54
|
def ==(other)
|
48
55
|
device == other.device && type == other.type
|
49
56
|
end
|
50
57
|
|
51
|
-
# A unique id for the reading, composed of the {Device device} id, and the
|
52
|
-
# '<code>electricalInput</code>' reading for a device with
|
53
|
-
#
|
58
|
+
# A unique id for the reading, composed of the {Device device} id, and the
|
59
|
+
# {#type}. So an '<code>electricalInput</code>' reading for a device with
|
60
|
+
# id '<code>b7ddac00-9415-012d-b57e-001c23973687</code>' would have the
|
61
|
+
# id '<code>b7ddac00-9415-012d-b57e-001c23973687-electricalInput</code>'.
|
54
62
|
# @return [String] the id
|
55
63
|
def id
|
56
64
|
"#{device.id}-#{type}"
|
57
65
|
end
|
66
|
+
|
58
67
|
end
|
59
|
-
|
68
|
+
|
69
|
+
end
|
data/lib/amon/session.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'uri'
|
2
2
|
|
3
3
|
module AMON
|
4
|
+
|
4
5
|
# Session objects take care of making the actual HTTP requests to the AMON API
|
5
6
|
#
|
6
7
|
# ## Caching ##
|
@@ -21,6 +22,7 @@ module AMON
|
|
21
22
|
# at regular intervals. Alternatively, you can use {Session#clear_cache} and keep the same
|
22
23
|
# session.
|
23
24
|
class Session
|
25
|
+
|
24
26
|
# @return [Hash] The hash of configuration options to be used when making requests
|
25
27
|
attr_reader :options
|
26
28
|
|
@@ -58,7 +60,11 @@ module AMON
|
|
58
60
|
# @return [Device]
|
59
61
|
def device(entity_id, device_id)
|
60
62
|
cache(:devices, device_id) do
|
61
|
-
json = get(
|
63
|
+
json = get(
|
64
|
+
"/entities/#{ URI.escape(entity_id )}/devices/#{URI.escape(device_id)}" +
|
65
|
+
";earliest" +
|
66
|
+
";latest"
|
67
|
+
)['device']
|
62
68
|
Device.new(self, json)
|
63
69
|
end
|
64
70
|
end
|
@@ -74,12 +80,14 @@ module AMON
|
|
74
80
|
end
|
75
81
|
|
76
82
|
# Retrieves measurements from the API
|
83
|
+
#
|
77
84
|
# @param [String] entity_id The ID of the entity
|
78
|
-
# @param [String] device_id The ID of the device to get
|
79
|
-
# @param [Time] start_date
|
80
|
-
# @param [Time] end_date
|
81
|
-
# @param [Boolean] raw
|
82
|
-
# contain a lot of data), or
|
85
|
+
# @param [String] device_id The ID of the device to get measurements from
|
86
|
+
# @param [Time] start_date The starting point for the measurements
|
87
|
+
# @param [Time] end_date The ending point for the measurements
|
88
|
+
# @param [Boolean] raw Whether to return raw measurements as submitted
|
89
|
+
# by the hardware (may contain a lot of data), or
|
90
|
+
# appropriate aggregations over the time period
|
83
91
|
def measurements(entity_id, device_id, start_date, end_date, raw = false)
|
84
92
|
cache(:measurements, [device_id, start_date, end_date, raw]) do
|
85
93
|
device = device(entity_id, device_id)
|
@@ -129,5 +137,7 @@ module AMON
|
|
129
137
|
}
|
130
138
|
)
|
131
139
|
end
|
140
|
+
|
132
141
|
end
|
133
|
-
|
142
|
+
|
143
|
+
end
|
data/lib/amon/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 7
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- AMEE
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-10-
|
18
|
+
date: 2012-10-17 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: json
|