flukso4r 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of flukso4r might be problematic. Click here for more details.
- data/README.rdoc +22 -8
- data/VERSION +1 -1
- data/bin/flukso_archive_watts +2 -2
- data/bin/flukso_query +19 -8
- data/lib/flukso.rb +1 -1
- data/lib/flukso/api.rb +8 -6
- data/lib/flukso/http_auth.rb +2 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -9,20 +9,27 @@ webservice. Have a look at the bin/flukso_query script. It allows you to
|
|
9
9
|
query the Flukso API and retrieve the latest readings from your Flukso
|
10
10
|
meter. A simple call to retrieve the readings of the last day is:
|
11
11
|
|
12
|
-
flukso_query -t day -u watt -
|
12
|
+
$ flukso_query -t day -u watt -c <CONFIG_FILE>
|
13
13
|
|
14
|
-
In addition, the library includes
|
14
|
+
In addition, the library includes scripts that can be used to
|
15
15
|
archive your Flukso readings at the highest resolution. The values are
|
16
16
|
stored in an sqlite3 database.
|
17
17
|
|
18
|
-
|
19
|
-
liking:
|
18
|
+
== Installation
|
20
19
|
|
21
|
-
|
20
|
+
For most cases installation can be done using gems:
|
21
|
+
|
22
|
+
$ gem install flukso4r
|
23
|
+
|
24
|
+
After installation you need to copy the flukso4rrc template file to a
|
25
|
+
destination of your liking:
|
26
|
+
|
27
|
+
$ cp <GEM_LOCATION>/etc/flukso4rrc $HOME/.flukso4rrc
|
22
28
|
|
23
29
|
Then, edit the file and specify the database file and your API key.
|
24
|
-
Please note that the library uses
|
25
|
-
|
30
|
+
Please note that the library uses the value in BASE_URL for
|
31
|
+
communicating with the webservice. Please use HTTPS
|
32
|
+
so that your API key is not sent unencrypted over the net.
|
26
33
|
|
27
34
|
Then, create an empty database:
|
28
35
|
|
@@ -33,7 +40,14 @@ After the DB has been created, you can add new data with the command
|
|
33
40
|
$ flukso_archive_watts -c <CONFIG_FILE>
|
34
41
|
|
35
42
|
This command will download all values of the last hour and add the new
|
36
|
-
ones to the database. It is intended to be run as a cronjob.
|
43
|
+
ones to the database. It is intended to be run as a cronjob. You can
|
44
|
+
then export the data with
|
45
|
+
|
46
|
+
$ flukso_export_db -c <CONFIG_FILE>
|
47
|
+
|
48
|
+
All commands support additional options which are displayed with the
|
49
|
+
parameter "-h". For verbose output, use "-v" in addition to your other
|
50
|
+
commandline switches.
|
37
51
|
|
38
52
|
The code in lib is a cheap knockoff of the twitter ruby gem - many
|
39
53
|
thanks to John Nunemaker! You can find the twitter ruby gem here:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
data/bin/flukso_archive_watts
CHANGED
@@ -93,9 +93,9 @@ if not File.exists?(dbfile)
|
|
93
93
|
exit(-2);
|
94
94
|
end
|
95
95
|
|
96
|
-
|
96
|
+
BASE_URL=$CONFIG['BASE_URL']
|
97
97
|
auth=Flukso::TokenAuth.new($CONFIG["ACCESS_TOKEN"]);
|
98
|
-
api=Flukso::API.new(auth);
|
98
|
+
api=Flukso::API.new(auth, BASE_URL);
|
99
99
|
query=Flukso::QueryReadings.new($CONFIG["SENSOR_ID"], :hour, :watt)
|
100
100
|
begin
|
101
101
|
readings=query.execute(api);
|
data/bin/flukso_query
CHANGED
@@ -55,11 +55,8 @@ class Optparser
|
|
55
55
|
opts.on("-u", "--unit VALUE", "The unit you want to query. Valid queries are: {watt, kwh, eur, aud}") do |unit|
|
56
56
|
options.unit = unit
|
57
57
|
end
|
58
|
-
opts.on("-
|
59
|
-
options.
|
60
|
-
end
|
61
|
-
opts.on("-a", "--access-token VALUE", "Your access token.") do |access_token|
|
62
|
-
options.access_token = access_token
|
58
|
+
opts.on("-c", "--config FILE", "The file where the configuration lives.") do |file|
|
59
|
+
options.config_file = file
|
63
60
|
end
|
64
61
|
# Boolean switch.
|
65
62
|
opts.on("-v", "--verbose", "Run verbosely") do |v|
|
@@ -110,16 +107,30 @@ else begin
|
|
110
107
|
exit(-2);
|
111
108
|
end
|
112
109
|
end
|
113
|
-
|
114
|
-
|
110
|
+
if options.config_file == nil
|
111
|
+
puts "Please provide a configuration file... (-h for details)."
|
112
|
+
exit(-1);
|
113
|
+
end
|
114
|
+
if not File.exists?(options.config_file)
|
115
|
+
puts " Configuration file #{options.config_file} not found - exiting."
|
116
|
+
exit(-3);
|
117
|
+
else
|
118
|
+
$CONFIG=YAML.load_file(options.config_file);
|
119
|
+
puts "Using this configuration:" if $verbose
|
120
|
+
puts "#{$CONFIG}" if $verbose
|
121
|
+
end
|
115
122
|
|
123
|
+
sensor_id = $CONFIG['SENSOR_ID']
|
124
|
+
access_token = $CONFIG['ACCESS_TOKEN']
|
125
|
+
BASE_URL=$CONFIG['BASE_URL']
|
116
126
|
auth=Flukso::TokenAuth.new(access_token);
|
117
|
-
api=Flukso::API.new(auth);
|
127
|
+
api=Flukso::API.new(auth, BASE_URL);
|
118
128
|
query=Flukso::QueryReadings.new(sensor_id, range, unit)
|
119
129
|
begin
|
120
130
|
readings=query.execute(api);
|
121
131
|
rescue Exception => e
|
122
132
|
puts "Query failed: #{e}"
|
133
|
+
puts "Used #{BASE_URL} as BASE_URL"
|
123
134
|
exit(-10);
|
124
135
|
end
|
125
136
|
|
data/lib/flukso.rb
CHANGED
@@ -44,7 +44,7 @@ module Flukso
|
|
44
44
|
class InformFlukso < StandardError; end
|
45
45
|
class NotFound < StandardError; end
|
46
46
|
# Use only the encrypted endpoint.
|
47
|
-
BASE_SENSOR_URL = "https://api.flukso.net/sensor"
|
47
|
+
#BASE_SENSOR_URL = "https://api.flukso.net/sensor"
|
48
48
|
API_VERSION="1.0"
|
49
49
|
end
|
50
50
|
|
data/lib/flukso/api.rb
CHANGED
@@ -36,7 +36,8 @@ module Flukso
|
|
36
36
|
if api.class != Flukso::API
|
37
37
|
raise Flukso::General, "Cannot execute query: API object invalid"
|
38
38
|
end
|
39
|
-
query_url="
|
39
|
+
query_url="/#{@sensor_id}?interval=#{@timerange}&unit=#{@unit}";
|
40
|
+
#query_url="#{Flukso::BASE_SENSOR_URL}/#{@sensor_id}?interval=#{@timerange}&unit=#{@unit}";
|
40
41
|
puts "Using query url #{query_url}" if $verbose
|
41
42
|
response = api.perform_get(query_url)
|
42
43
|
return wrap_response(response);
|
@@ -59,24 +60,25 @@ module Flukso
|
|
59
60
|
|
60
61
|
attr_reader :client
|
61
62
|
|
62
|
-
def initialize(client)
|
63
|
+
def initialize(client, base_url)
|
63
64
|
@client = client
|
65
|
+
@base_url = base_url
|
64
66
|
end
|
65
67
|
|
66
68
|
def perform_get(path, options={})
|
67
|
-
Flukso::Request.get(self, path, options )
|
69
|
+
Flukso::Request.get(self, @base_url+path, options )
|
68
70
|
end
|
69
71
|
|
70
72
|
def perform_post(path, options={})
|
71
|
-
Flukso::Request.post(self, path, add_version_header(options))
|
73
|
+
Flukso::Request.post(self, @base_url+path, add_version_header(options))
|
72
74
|
end
|
73
75
|
|
74
76
|
def perform_put(path, options={})
|
75
|
-
Flukso::Request.put(self, path, add_version_header(options))
|
77
|
+
Flukso::Request.put(self, @base_url+path, add_version_header(options))
|
76
78
|
end
|
77
79
|
|
78
80
|
def perform_delete(path, options={})
|
79
|
-
Flukso::Request.delete(self, path, add_version_header(options))
|
81
|
+
Flukso::Request.delete(self, @base_url+path, add_version_header(options))
|
80
82
|
end
|
81
83
|
|
82
84
|
end
|
data/lib/flukso/http_auth.rb
CHANGED
@@ -27,10 +27,10 @@ module Flukso
|
|
27
27
|
|
28
28
|
attr_reader :options
|
29
29
|
|
30
|
-
def initialize(access_token)
|
30
|
+
def initialize(access_token)#, base_url)
|
31
31
|
@access_token = access_token
|
32
32
|
#@options = {:ssl => true}.merge(options)
|
33
|
-
self.class.base_uri "#{
|
33
|
+
#self.class.base_uri "#{base_url}"
|
34
34
|
end
|
35
35
|
|
36
36
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flukso4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathias Dalheimer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-31 00:00:00 +02:00
|
13
13
|
default_executable: flukso_query
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|