Floppy-currentcostd 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -34,14 +34,12 @@ module CurrentCostDaemon
|
|
34
34
|
@account = config['carbondiet']['account_id']
|
35
35
|
@username = config['carbondiet']['username']
|
36
36
|
@password = config['carbondiet']['password']
|
37
|
-
@http = Net::HTTP.new('www.carbondiet.org')
|
38
|
-
@http.start
|
39
37
|
end
|
40
38
|
|
41
39
|
def update(reading)
|
42
40
|
# Carbon Diet is daily, so we only want to do something if there is
|
43
41
|
# history data, and only once a day, really. Say around 5am, why not.
|
44
|
-
|
42
|
+
if !reading.history.nil? && reading.hour == 5
|
45
43
|
# Create http post request
|
46
44
|
post = Net::HTTP::Post.new("/data_entry/electricity/#{@account}/currentcost")
|
47
45
|
post.basic_auth(@username, @password)
|
@@ -59,11 +57,14 @@ module CurrentCostDaemon
|
|
59
57
|
end
|
60
58
|
end
|
61
59
|
# Send data
|
62
|
-
|
60
|
+
http = Net::HTTP.new('www.carbondiet.org')
|
61
|
+
http.start
|
62
|
+
http.request(post)
|
63
63
|
end
|
64
64
|
rescue
|
65
65
|
puts "Something went wrong (carbondiet)!"
|
66
66
|
puts $!.inspect
|
67
|
+
nil
|
67
68
|
end
|
68
69
|
|
69
70
|
end
|
@@ -36,8 +36,6 @@ module CurrentCostDaemon
|
|
36
36
|
def initialize(config)
|
37
37
|
@feed = config['pachube']['feed_id']
|
38
38
|
@api_key = config['pachube']['api_key']
|
39
|
-
@http = Net::HTTP.new('www.pachube.com')
|
40
|
-
@http.start
|
41
39
|
end
|
42
40
|
|
43
41
|
def update(reading)
|
@@ -53,7 +51,9 @@ module CurrentCostDaemon
|
|
53
51
|
put = Net::HTTP::Put.new("/feeds/#{@feed}.xml")
|
54
52
|
put.body = eeml.to_eeml
|
55
53
|
put['X-PachubeApiKey'] = @api_key
|
56
|
-
|
54
|
+
http = Net::HTTP.new('www.pachube.com')
|
55
|
+
http.start
|
56
|
+
http.request(put)
|
57
57
|
rescue
|
58
58
|
puts "Something went wrong (pachube)!"
|
59
59
|
puts $!.inspect
|