Floppy-currentcostd 1.1 → 1.2

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.
@@ -17,4 +17,10 @@ pachube:
17
17
  # Enable this to run a web server which you can look at in a browser
18
18
  http:
19
19
  enabled: false
20
- port: 3500
20
+ port: 3500
21
+
22
+ # Enable this section to post data to www.carbondiet.org
23
+ carbondiet:
24
+ enabled: false
25
+ username: your_carbondiet_username_goes_here
26
+ password: your_carbondiet_password_goes_here
@@ -0,0 +1,70 @@
1
+ # Copyright (c) 2008 James Smith (www.floppy.org.uk)
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+ #
21
+ # http://www.opensource.org/licenses/mit-license.php
22
+
23
+ module CurrentCostDaemon
24
+
25
+ module Publishers
26
+
27
+ class CarbonDiet
28
+
29
+ def self.config_section
30
+ 'carbondiet'
31
+ end
32
+
33
+ def initialize(config)
34
+ @account = config['carbondiet']['account_id']
35
+ @username = config['carbondiet']['username']
36
+ @password = config['carbondiet']['password']
37
+ @http = Net::HTTP.new('www.carbondiet.org', 3000)
38
+ @http.start
39
+ end
40
+
41
+ def update(reading)
42
+ # Carbon Diet is daily, so we only want to do something if there is
43
+ # history data.
44
+ unless reading.history.nil?
45
+ # Create http post request
46
+ post = Net::HTTP::Post.new("/data_entry/electricity/#{@account}/currentcost")
47
+ post.basic_auth(@username, @password)
48
+ # Add XML document
49
+ xml = Builder::XmlMarkup.new
50
+ xml.instruct!
51
+ post.body = xml.data do
52
+ reading.history[:days].each_index do |i|
53
+ unless reading.history[:days][i].nil?
54
+ xml.entry do
55
+ xml.date Date.today - i
56
+ xml.value reading.history[:days][i]
57
+ end
58
+ end
59
+ end
60
+ end
61
+ # Send data
62
+ @http.request(post)
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Floppy-currentcostd
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.1"
4
+ version: "1.2"
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith
@@ -62,6 +62,7 @@ files:
62
62
  - lib/currentcostd/publishers/debug.rb
63
63
  - lib/currentcostd/publishers/pachube.rb
64
64
  - lib/currentcostd/publishers/http.rb
65
+ - lib/currentcostd/publishers/carbondiet.rb
65
66
  - config/currentcostd.example.yml
66
67
  - bin/currentcostd
67
68
  has_rdoc: false