powershop 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009 Nik Wakelin <nik@codetocustomer.com>
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.
data/README.textile ADDED
@@ -0,0 +1,79 @@
1
+ h1. Powershop OAuth Client
2
+
3
+ This is an Ruby OAuth Client library for the Powershop API (more details available at "Powershop":http://powershop.co.nz or on the "Google Group":http://groups.google.com/group/powershop-developers).
4
+
5
+ It borrows heavily from John Nunemaker's "Twitter Ruby Client":http://github.com/jnunemaker/twitter. Thanks!
6
+
7
+ h2. Authenticating With OAuth
8
+
9
+ (Note that there is an executable example in examples/powershop_example.rb. You can get more detail about OAuth itself at the "OAuth Site":http://oauth.net)
10
+
11
+ First, you'll need a Consumer Key/Secret pair from Powershop. You can obtain one by contacting developers@powershop.co.nz.
12
+
13
+ Then create a new client like so:
14
+
15
+ <pre><code>require 'powershop'
16
+ powershop_client = Powershop::Client.new(YOUR_OAUTH_CONSUMER_KEY, YOUR_OAUTH_CONSUMER_SECRET)
17
+ </code></pre>
18
+
19
+ You can get a Request Token like this:
20
+
21
+ <pre><code>request_token = powershop_client.request_token(:oauth_callback => "http://mysite.com/oauth/callback")
22
+ </code></pre>
23
+
24
+ NB: Powershop requires you specify an OAuth Callback URL for your request token. The library will default to "oob" (Out-Of-Band) if you don't specify a URL. Using "oob" means Powershop will provide your user with a verifier that they must manually copy and paste into your application (useful for Desktop applications or similar). Otherwise, the OAuth Callback URL is a URL your users will get redirected to along with an :oauth_verifier param once they've authenticated at Powershop.
25
+
26
+ Keep your Request Token/Secret pair around (the session is a good place in Rails) - as you'll need it later.
27
+
28
+ You'll then need to redirect your user to the authentication URL for the request token. In Rails, this looks something like:
29
+
30
+ <pre><code>redirect_to request_token.authorize_url
31
+ </code></pre>
32
+
33
+ Once they've authenticated at Powershop they'll get redirected to your callback with a verifier, and you can then exchange your Request Token for an Access Token like so:
34
+
35
+ <pre><code>powershop_client.authorize_from_request(request_token.token, request_token.secret, params[:oauth_verifier])
36
+ </code></pre>
37
+
38
+ (Assuming that params is a hash of GET parameters, similar to Rails)
39
+
40
+ You can then get an Access Token/Secret pair.
41
+
42
+ <pre><code>powershop_client.access_token</code></pre>
43
+
44
+ You should store this in your Database or somewhere similarly persistent - you can use it later to authenticate in a single step:
45
+
46
+ <pre><code>require 'powershop'
47
+ powershop_client = Powershop::Client.new(YOUR_OAUTH_CONSUMER_KEY, YOUR_OAUTH_CONSUMER_SECRET)
48
+ powershop_client.authorize_from_access(ACCESS_TOKEN, ACCESS_SECRET)
49
+ </code></pre>
50
+
51
+ h2. Using the Library
52
+
53
+ Most of the details of the library should be pretty self-explanatory. (If you're stuck, all the calls are tested in test/client_test.rb and Powershop provides a really useful PDF)
54
+
55
+ <pre><code>
56
+ # properties is the result of the "customer_details" API call, it returns an array of Powershop::Property objects
57
+ powershop_client.properties
58
+
59
+ # you can set the property to use for all subsequent calls (i.e automatically append the icp_number param)
60
+ powershop_client.set_property(powershop_client.properties.first)
61
+
62
+ # Note that you'll need to set the property for all the following calls
63
+
64
+ # get a list of all products available
65
+ powershop_client.products
66
+
67
+ # get some meter readings (the "end_date" parameter defaults to now)
68
+ powershop_client.meter_readings(:start_date => 2.weeks.ago)
69
+
70
+ # top up power
71
+ top_up_details = powershop_client.get_top_up
72
+
73
+ # then you should display these details to your user...
74
+ powershop_client.top_up!(:offer_key => top_up_details.offer_key)
75
+
76
+ # updating meter readings (use a hash of register number => reading pairs)
77
+ powershop_client.post_meter_readings({ "1000:1" => 40568, "1000:2" => 45638 })
78
+
79
+ </code></pre>
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the xero gateway.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+
3
+ require File.dirname(__FILE__) + '/../lib/powershop'
4
+ require 'pp'
5
+
6
+ # insert your consumer key/secret pair here
7
+ CONSUMER_KEY = "YOUR_CONSUMER_KEY"
8
+ CONSUMER_SECRET = "YOUR_CONSUMER_SECRET"
9
+
10
+ p = Powershop::Client.new(CONSUMER_KEY, CONSUMER_SECRET)
11
+
12
+ rt = p.request_token
13
+
14
+ `open #{rt.authorize_url}`
15
+
16
+ puts "Paste OAuth Verifier:"
17
+ verifier = gets.chomp
18
+
19
+ access_token, access_secret = p.authorize_from_request(rt.token, rt.secret, verifier)
20
+
21
+ puts "Your Access Token: #{access_token}"
22
+ puts "Your Access Secret: #{access_secret}"
23
+
24
+ puts
25
+ puts "Now let's make an API call..."
26
+
27
+ pp p.properties
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'powershop'
@@ -0,0 +1,123 @@
1
+ module Powershop
2
+ class Client
3
+
4
+ attr_accessor :oauth
5
+
6
+ def initialize(oauth_consumer_key, oauth_consumer_secret)
7
+ @oauth = OAuth.new(oauth_consumer_key, oauth_consumer_secret)
8
+
9
+ @current_property = nil
10
+ end
11
+
12
+ # so we can oauth straight through the Client
13
+ %w(request_token authorize_from_request authorize_from_access access_token).each do |method|
14
+ delegate method, :to => :oauth
15
+ end
16
+
17
+ # proxy all our requests with an error wrapper
18
+ %w(get post put delete).each do |http_method|
19
+ define_method(http_method) do |*args|
20
+ url, options = args
21
+ options ||= {}
22
+
23
+ options[:icp_number] ||= @current_property.icp_number if @current_property
24
+
25
+ parse(@oauth.send(http_method, "#{url}?#{to_query(options)}"))
26
+ end
27
+ end
28
+
29
+ def properties
30
+ result = self.get(api_url("customer"))
31
+
32
+ result.properties.collect do |p|
33
+ Property.new(self, p)
34
+ end
35
+ end
36
+
37
+ # choose which property (icp_number) to use for all calls requiring an icp_number
38
+ def set_property(property)
39
+ @current_property = property
40
+ end
41
+
42
+ def get_meter_readings(options = {})
43
+ options[:end_date] ||= Date.today
44
+
45
+ self.get(api_url("meter_readings"), options)
46
+ end
47
+
48
+ # 'readings' should be a hash of register_number => reading values
49
+ # e.g
50
+ # { "10073:1" => 5000, "10073:2" => 2000 }
51
+ def post_meter_readings(readings, options = {})
52
+
53
+ readings.each do |register_number, reading|
54
+ options["readings[#{register_number}]"] = reading
55
+ end
56
+
57
+ response = self.post(api_url("meter_readings"), options)
58
+
59
+ if response.result == "success"
60
+ true
61
+ else
62
+ raise reponse.message
63
+ end
64
+ end
65
+
66
+ def products(options = {})
67
+ self.get(api_url("products"), options)
68
+ end
69
+
70
+ def get_top_up(options = {})
71
+ self.get(api_url("top_up"), options)
72
+ end
73
+
74
+ def top_up!(options = {})
75
+ raise "You must specify an Offer Key" unless options[:offer_key]
76
+
77
+ self.post(api_url("top_up"), options)
78
+ end
79
+
80
+ private
81
+
82
+ # NB: For Powershop, the "js" format (usually reserved for executable Javascript)
83
+ # is used to denote JSON encoding (instead of the more familiar "json")
84
+ def api_url(endpoint)
85
+ "#{API_BASE_URL}/external_api/v1/#{endpoint}.js"
86
+ end
87
+
88
+ def parse(response)
89
+ check_errors(response)
90
+
91
+ result = ActiveSupport::JSON.decode(response.body)["result"]
92
+
93
+ if result.is_a?(Array)
94
+ result.map { |r| OpenStruct.new(r) }
95
+ else
96
+ OpenStruct.new(result)
97
+ end
98
+ end
99
+
100
+ def check_errors(response)
101
+ case response.code.to_i
102
+ when 400
103
+ raise PowershopError.new(response.body)
104
+ when 401
105
+ raise PowershopOAuthError.new(response.body)
106
+ when 503
107
+ raise RateLimitExceeded.new(response.body)
108
+ end
109
+ end
110
+
111
+ def to_query(options)
112
+ options.inject([]) do |collection, opt|
113
+ key, value = opt
114
+
115
+ value = value.strftime("%Y-%m-%d") if value.is_a?(Date) || value.is_a?(Time)
116
+
117
+ collection << "#{key}=#{value}"
118
+ collection
119
+ end * '&'
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,44 @@
1
+ module Powershop
2
+
3
+ # based on OAuth implementation for Twitter Gem,
4
+ # http://github.com/jnunemaker/twitter/
5
+ class OAuth
6
+
7
+ attr_accessor :consumer
8
+
9
+ %w(get post put delete).each do |http_method|
10
+ delegate http_method, :to => :access_token
11
+ end
12
+
13
+ def initialize(key, secret)
14
+ @consumer = ::OAuth::Consumer.new(key, secret,
15
+ :site => API_BASE_URL,
16
+ :request_token_path => "/external_api/oauth/request_token",
17
+ :authorize_path => "/external_api/oauth/authorize",
18
+ :access_token_path => "/external_api/oauth/access_token")
19
+ end
20
+
21
+ def request_token(options={})
22
+ # default to Out-Of-Band unless an oauth callback is specified
23
+ # NB: Powershop requires an OAuth callback, ref: [E908]
24
+ options[:oauth_callback] ||= "oob"
25
+
26
+ @request_token ||= consumer.get_request_token(options)
27
+ end
28
+
29
+ def authorize_from_request(rtoken, rsecret, verifier_or_pin)
30
+ request_token = ::OAuth::RequestToken.new(consumer, rtoken, rsecret)
31
+ access_token = request_token.get_access_token(:oauth_verifier => verifier_or_pin)
32
+ @atoken, @asecret = access_token.token, access_token.secret
33
+ end
34
+
35
+ def access_token
36
+ @access_token ||= ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
37
+ end
38
+
39
+ def authorize_from_access(atoken, asecret)
40
+ @atoken, @asecret = atoken, asecret
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,26 @@
1
+ module Powershop
2
+ class Property
3
+
4
+ ATTRIBUTES = %w(icp_number address start_date end_date unit_balance daily_consumption
5
+ last_account_review_at registers)
6
+
7
+ ATTRIBUTES.each { |r| attr_accessor r }
8
+
9
+ def initialize(client, hash)
10
+ @client = client
11
+
12
+ ATTRIBUTES.each do |r|
13
+ send("#{r}=", hash[r])
14
+ end
15
+ end
16
+
17
+ # Could override this in case a Hash doesn't suit for an address ;)
18
+ # def address=(address_hash)
19
+ # end
20
+
21
+ def registers=(register_array)
22
+ @registers = register_array.map { |r| Register.new(r) }
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ module Powershop
2
+ class Register
3
+
4
+ ATTRIBUTES = %w(register_number description dials hidden last_reading_at last_reading_value
5
+ last_reading_type estimated_reading_value)
6
+
7
+ ATTRIBUTES.each { |r| attr_accessor r }
8
+
9
+ def initialize(hash)
10
+ ATTRIBUTES.each do |r|
11
+ send("#{r}=", hash[r])
12
+ end
13
+ end
14
+
15
+ end
16
+ end
data/lib/powershop.rb ADDED
@@ -0,0 +1,27 @@
1
+
2
+ require "active_support"
3
+ require "ostruct"
4
+ require "cgi"
5
+
6
+ gem "oauth", ">= 0.3.1"
7
+ require "oauth"
8
+
9
+ directory = File.expand_path(File.dirname(__FILE__))
10
+
11
+ require File.join(directory, 'powershop', 'client')
12
+ require File.join(directory, 'powershop', 'oauth')
13
+ require File.join(directory, 'powershop', 'property')
14
+ require File.join(directory, 'powershop', 'register')
15
+
16
+ module Powershop
17
+
18
+ class RateLimitExceeded < StandardError; end
19
+ class PowershopError < StandardError; end
20
+ class PowershopOAuthError < StandardError; end
21
+
22
+ VERSION = "0.0.1"
23
+
24
+ # use test url
25
+ API_BASE_URL = "https://suppliertest.youdo.co.nz"
26
+
27
+ end
data/powershop.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "powershop"
3
+ s.version = "0.0.1"
4
+ s.date = "2009-12-26"
5
+ s.summary = "Allows Ruby applications to communicate with the Powershop API"
6
+ s.email = "nik@codetocustomer.com"
7
+ s.homepage = "http://github.com/codetocustomer/powershop"
8
+ s.description = "Allows Ruby applications to communicate with the Powershop API"
9
+ s.has_rdoc = false
10
+ s.authors = ["Nik Wakelin"]
11
+ s.add_dependency('oauth', '>= 0.3.1')
12
+ s.add_dependency('activesupport', '>= 2.3.5')
13
+ s.files = ["init.rb",
14
+ "LICENSE",
15
+ "Rakefile",
16
+ "README.textile",
17
+ "examples/powershop_example.rb",
18
+ "lib/powershop.rb",
19
+ "lib/powershop/client.rb",
20
+ "lib/powershop/oauth.rb",
21
+ "lib/powershop/property.rb",
22
+ "lib/powershop/register.rb",
23
+ "script/console",
24
+ "test/client_test.rb",
25
+ "test/test_helper.rb",
26
+ "test/responses/get_top_up.json",
27
+ "test/responses/icp_number_error.json",
28
+ "test/responses/meter_readings.json",
29
+ "test/responses/products.json",
30
+ "test/responses/properties.json",
31
+ "test/responses/success.json",
32
+ "powershop.gemspec"]
33
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/powershop.rb'}"
9
+ puts "Loading Powershop gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,140 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class ClientTest < Test::Unit::TestCase
4
+
5
+ STUB_API_CALLS = true
6
+
7
+ # specify a real consumer key/secret pair here to test against the actual API
8
+ CONSUMER_KEY = "YOUR_CONSUMER_KEY"
9
+ CONSUMER_SECRET = "YOUR_CONSUMER_SECRET"
10
+
11
+ # specify an access token/secret pair here to test against the actual API
12
+ ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"
13
+ ACCESS_SECRET = "YOUR_ACCESS_SECRET"
14
+
15
+ def setup
16
+ @powershop_client = Powershop::Client.new(CONSUMER_KEY, CONSUMER_SECRET)
17
+
18
+ if STUB_API_CALLS
19
+ Powershop::OAuth.any_instance.expects(:authorize_from_access).with { |x, y| x == ACCESS_TOKEN && y == ACCESS_SECRET }.returns(true)
20
+ end
21
+
22
+ @powershop_client.authorize_from_access(ACCESS_TOKEN, ACCESS_SECRET)
23
+
24
+ end
25
+
26
+ def test_properties
27
+ if STUB_API_CALLS
28
+ Powershop::OAuth.any_instance.expects(:get).with { |url| url =~ /customer/ }.returns(stub(:code => 200, :body => test_response("properties")))
29
+ end
30
+
31
+ assert properties = @powershop_client.properties
32
+
33
+ properties.each do |p|
34
+ assert p.is_a? Powershop::Property
35
+ assert p.registers.first.is_a? Powershop::Register
36
+ end
37
+
38
+ if STUB_API_CALLS
39
+ p = properties.first
40
+
41
+ assert_equal "0001427254UNF48", p.icp_number
42
+ assert_equal 120.1, p.daily_consumption
43
+ assert_equal -8261, p.unit_balance
44
+
45
+ r = p.registers.first
46
+
47
+ assert_equal "109479:1", r.register_number
48
+ assert_equal 5, r.dials
49
+ end
50
+ end
51
+
52
+ def test_get_meter_readings
53
+ if STUB_API_CALLS
54
+ Powershop::OAuth.any_instance.expects(:get).with { |url| url =~ /customer/ }.returns(stub(:code => 200, :body => test_response("properties")))
55
+ Powershop::OAuth.any_instance.expects(:get).with { |url| url =~ /meter_readings/ }.returns(stub(:code => 200, :body => test_response("meter_readings")))
56
+ end
57
+
58
+ @powershop_client.set_property(@powershop_client.properties.first)
59
+
60
+ assert readings = @powershop_client.get_meter_readings(:start_date => 2.weeks.ago)
61
+
62
+ if STUB_API_CALLS
63
+ assert_equal "customer", readings.first.reading_type
64
+ assert_equal "63918", readings.first.reading_value
65
+ end
66
+ end
67
+
68
+ def test_powershop_errors
69
+ if STUB_API_CALLS
70
+ Powershop::OAuth.any_instance.expects(:get).with { |url| url =~ /meter_readings/ }.returns(stub(:code => 400, :body => test_response("icp_number_error")))
71
+ end
72
+
73
+ assert_raises Powershop::PowershopError do
74
+ @powershop_client.get_meter_readings(:start_date => 2.weeks.ago)
75
+ end
76
+ end
77
+
78
+ def test_products
79
+ if STUB_API_CALLS
80
+ Powershop::OAuth.any_instance.expects(:get).with { |url| url =~ /customer/ }.returns(stub(:code => 200, :body => test_response("properties")))
81
+ Powershop::OAuth.any_instance.expects(:get).with { |url| url =~ /products/ }.returns(stub(:code => 200, :body => test_response("products")))
82
+ end
83
+
84
+ @powershop_client.set_property(@powershop_client.properties.first)
85
+
86
+ assert products = @powershop_client.products
87
+
88
+ if STUB_API_CALLS
89
+ flower_power_catchup = products.detect { |p| p.name == "$84.90 catch up pack" }
90
+
91
+ assert_equal "0.1772", flower_power_catchup.price_per_unit
92
+ assert_match /PowerKiwi/, flower_power_catchup.description
93
+ end
94
+ end
95
+
96
+ def test_post_meter_readings
97
+ if STUB_API_CALLS
98
+ Powershop::OAuth.any_instance.expects(:get).with { |url| url =~ /customer/ }.returns(stub(:code => 200, :body => test_response("properties")))
99
+ Powershop::OAuth.any_instance.expects(:post).with { |url| url =~ /meter_readings/ }.returns(stub(:code => 200, :body => test_response("success")))
100
+ end
101
+
102
+ property = @powershop_client.properties.first
103
+ @powershop_client.set_property(property)
104
+
105
+ new_readings = property.registers.inject({}) do |hash, r|
106
+ hash[r.register_number] = r.last_reading_value.to_i + 500
107
+ hash
108
+ end
109
+
110
+ assert @powershop_client.post_meter_readings(new_readings)
111
+ end
112
+
113
+ def test_topping_up
114
+ if STUB_API_CALLS
115
+ Powershop::OAuth.any_instance.expects(:get).with { |url| url =~ /customer/ }.returns(stub(:code => 200, :body => test_response("properties")))
116
+ Powershop::OAuth.any_instance.expects(:get).with { |url| url =~ /top_up/ }.returns(stub(:code => 200, :body => test_response("get_top_up")))
117
+ Powershop::OAuth.any_instance.expects(:post).with { |url| url =~ /top_up/ }.returns(stub(:code => 200, :body => test_response("success")))
118
+ end
119
+
120
+ @powershop_client.set_property(@powershop_client.properties.first)
121
+
122
+ assert top_up_details = @powershop_client.get_top_up
123
+
124
+ offer_key = top_up_details.offer_key
125
+ assert_not_nil offer_key
126
+
127
+ assert_raises RuntimeError, "You must specify an Offer Key" do
128
+ @powershop_client.top_up!
129
+ end
130
+
131
+ assert @powershop_client.top_up!(:offer_key => offer_key)
132
+ end
133
+
134
+ private
135
+
136
+ def test_response(name)
137
+ File.open(File.join(File.dirname(__FILE__), "responses", "#{name}.json"), "rb").read
138
+ end
139
+
140
+ end
@@ -0,0 +1 @@
1
+ {"version":"1.0","result":{"total_price":"1741.8","offer_key":"9c6a264d88d8a7ff3fb37c6da6f48b0457ecdcd01ba8e303c05e81329d89a37b","price_per_unit":"0.1785","product_name":"Flower Power Top Up","unit_balance":-9758}}
@@ -0,0 +1 @@
1
+ [E000] The icp_number parameter must be specified for this call
@@ -0,0 +1 @@
1
+ {"version":"1.0","result":[{"reading_type":"customer","read_at":"2009-12-25 00:13:04","register_number":"109479:1","reading_value":"63918"},{"reading_type":"customer","read_at":"2009-12-25 00:13:01","register_number":"109479:1","reading_value":"53918"},{"reading_type":"customer","read_at":"2009-12-25 00:12:58","register_number":"109479:1","reading_value":"53915"},{"reading_type":"customer","read_at":"2009-12-25 00:12:22","register_number":"109479:1","reading_value":"53915"}]}
@@ -0,0 +1 @@
1
+ {"version":"1.0","result":[{"type":"special","image_url":"https://suppliertest.youdo.co.nz/photos/fb829edd7c63506b05eec11ae6cee215.original","name":"$49.95 Value Pack","price_per_unit":"0.1765","description":"If you\u2019re serious about saving money on electricity, then our weekly Value Pack is what you\u2019re looking for. About a week\u2019s worth of power for the average user at price that\u2019s very hard to beat.\r\n\r\nWith the colder weather you'll be using a bit more power, so we've bumped up the size of the weekly value pack, but kept the same lean unit price.\r\n\r\nThere\u2019s no catch, but you are limited to one pack per customer per week, so if you want to save, you\u2019ll need to top up regularly. Go for it now and save.\r\n\r\nWho is Standard Power?\r\nStandard Power is backed by Powershop. It is the name we use for our budget house brand electricity because it is the same bulk standard electricity, just better deals."},{"type":"nominated","image_url":"https://suppliertest.youdo.co.nz/photos/b0541bfc10d8eddfd3a19b442aabb336.original","name":"Green Power Top Up","price_per_unit":"0.1983","description":"Do you choose your\u00a0electricity\u00a0company based on how they generate their power?\r\n\r\n\u003Cb\u003EUnfortunately the electrical power from the grid that you actually use in your home comes from a mix of sources that you cannot control. Only The Green Power Company buys carbon credits to help offset the greenhouse gas emissions from electricity generated on your behalf. \u003C/b\u003E\r\n\r\nThe sources of electricity on the grid range from the giant Manapouri and other hydro dams, geothermal power at Wairakei, through to gas and coal fired power, including the thermal power station at Huntly. Around one third of electricity in NZ is generated from fossil fueled thermal power stations. \u003Ca href=\"http://www.med.govt.nz/upload/63349/GHG%20Report.pdf\"\u003ESource MED\u003C/a\u003E Even the geothermal fields in Wairakei are not above reproach, as they result in so called fugitive greenhouse gas emissions. Every household in New Zealand that is on the grid relies on all of these power stations, although the mix of electricity source you use depends on where you live and changes through the seasons.\r\n\r\nEach of these power sources has a different contribution to New Zealand\u2019s carbon emissions, with established hydro dams showing essentially zero emissions and coal and gas fired plants the most. The MED release quarterly updates on the electricity generation emission factor and it is this emission factor we use in our calculations to determine the amount of carbon we need to offset for each unit of Green Power you purchase (see \u003Ca href=\"http://www.med.govt.nz/upload/67175/NZEQ_Sepetmber08_EditorsVersion.pdf\"\u003Ehttp://www.med.govt.nz/upload/67175/NZEQ_Sepetmber08_EditorsVersion.pdf\u003C/a\u003E). Currently, the emissions factor to determine the greenhouse gas equivalent of electricity derived emissions from generation is 0.18 (ktCO2e/GWh).\r\n\r\nThe greenhouse gas emissions per electricity unit are therefore 0.18kg/unit. For every Green Power unit you purchase The Green Power Company will purchase verified \u003Ca href=\"http://www.v-c-s.org/projects.html\"\u003Evoluntary carbon units\u003C/a\u003E to offset 0.18kg of carbon. As voluntary carbon units offset carbon by the tonne and individual household electricity emissions per month are likely to be in kilograms of carbon, we will aggregate the emissions from all our customers and reconcile them the month following to the nearest tonne. Aggregated emissions that are less than one tonne will be rolled over to the following month.\r\n\r\nThe verified voluntary carbon units purchased by us will be retired in our Voluntary Carbon Standard Registry account. You can check the PowerKiwi Limited (The Green Power Company) Registry account on the \u003Ca href=\"http://www.tz1market.com/registryview.php\"\u003ETZ1 Registry\u003C/a\u003E.\r\n\t \r\n\r\n\u003Cb\u003EAbout The Green Power Company\u003C/b\u003E\r\nThe Green Power Company product is offered through Powershop, which is web based, paper free, safe and far more fun than the traditional power companies. \r\n\r\n\u003Ca href=\"http://www.greenpowercompany.co.nz\"\u003EThe Green Power Company\u003C/a\u003E is a product from \u003Ca href=\"http://www.powerkiwi.co.nz\"\u003EPowerKiwi\u003C/a\u003E, an independent NZ owned company.\r\n\r\nTips:\r\n* Change your default product to Green Power by clicking on the yellow \u201cmake this my default product\u201d checkbox above. That way you\u2019ll always be sure to get the only power that truly accounts for emissions.\r\n* Find out when your meter reader is coming via text \u2013 use My Settings, Alerts\r\n* Save petrol by turning your engine off if you will be at a stop light for longer than 10 seconds. \u003Ca href=\"http://green.yahoo.com/blog/climate411/71/when-to-turn-off-your-engine.html\"\u003Esource Y! Green\u003C/a\u003E"},{"type":"special","image_url":"https://suppliertest.youdo.co.nz/photos/76293000267be60578e318f8bff807b2.original","name":"Crusaders Power Pack","price_per_unit":"0.2008","description":"The excitement and energy of Super 14 Rugby has now been transformed into \u2018Crusaders Power\u2019. If you are a one-eyed Crusaders supporter and your favourite colours are red and black - this $50.00 Crusaders Power Pack is for you. By purchasing this pack you can support your favourite Super 14 team. While the Super 14 playing season might have finished, you can still follow your favourite team members as they play for the All Blacks.\r\n\r\nEach Crusaders Power Pack is about a week's worth of electricity for an average user in winter. Don't drop the ball. Grab this red and black deal now."},{"type":"special","image_url":"https://suppliertest.youdo.co.nz/photos/8de0c3088ea9c8d03cec83b86d50197d.original","name":"Meridian 300","price_per_unit":"0.1789","description":"Choose the Meridian 300 special, and you can purchase up to 300 units of electricity at the great price shown (cents/unit). You\u2019re limited to one Meridian 300 purchase per week, so be in quick while the offer lasts.\r\n\r\nWind and water are nature\u2019s carbon free fuels, and Meridian uses them to generate electricity. We\u2019re committed to sustainability, and encourage you to be too.\r\n\r\n\u201cMeridian 300\u201d is carboNZero\u003Csup\u003EcertTM\u003C/sup\u003E certified electricity. All units of this product used, will be accounted for by Meridian under the rules of the Landcare Research carboNZero\u003Csup\u003EcertTM\u003C/sup\u003E programme. For more information about Meridian, or our carboNZero\u003Csup\u003EcertTM\u003C/sup\u003E certification, visit \u003Ca href=\"http://www.meridianenergy.co.nz\"\u003Ewww.meridianenergy.co.nz\u003C/a\u003E."},{"type":"special","image_url":"https://suppliertest.youdo.co.nz/photos/3e9499a622046211c7a12dfb197a6b39.original","name":"$84.90 catch up pack","price_per_unit":"0.1772","description":"Buy in bulk and save. With Flower Power $84.90 value pack you can quickly catch up on power you have used.\r\nRestricted to one per week and use any time before the \"use by\" date above. Make sure though that you use all of your bulk purchased electricity - as all bulk purchases are use it or lose it propositions. \r\n \r\n\r\nFlower Power \r\n\u003Ca href=\"http://www.flowerpowernz.co.nz\"\u003EFlower Power\u003C/a\u003E is owned by \u003Ca href=\"http://www.powerkiwi.co.nz\"\u003EPowerKiwi\u003C/a\u003E, an independent company. "},{"type":"nominated","image_url":"https://suppliertest.youdo.co.nz/photos/23badbfebc43c19a90471d15d088d896.original","name":"Top Up","price_per_unit":"0.1793","description":"Top Up is Standard Power's most versatile product - buy some now to use now, or set it as your default product and rest easy knowing you'll be on a good deal.\r\n\r\n\u003Cb\u003EWho is Standard Power?\u003C/b\u003E\r\nStandard Power is backed by Powershop. It is the name we use for our budget house brand electricity because it is the same \u003Ci\u003Ebulk standard\u003C/i\u003E electricity, just better deals.\r\n"},{"type":"nominated","image_url":"https://suppliertest.youdo.co.nz/photos/c28aa100f1c7ba8ceb8a27fe79235138.original","name":"Meridian","price_per_unit":"0.1819","description":"Wind and water are nature\u2019s carbon free fuels, and Meridian uses them to generate electricity. We\u2019re committed to sustainability, and encourage you to be too. \r\n\r\n\u201cMeridian\u201d is carboNZero\u003Csup\u003EcertTM\u003C/sup\u003E certified electricity. All units of this product used, will be accounted for by Meridian under the rules of the Landcare Research carboNZero\u003Csup\u003EcertTM\u003C/sup\u003E programme.\r\n\r\nFor more information about Meridian, or our carboNZero\u003Csup\u003EcertTM\u003C/sup\u003E certification, visit \u003Ca href=\"http://www.meridianenergy.co.nz\"\u003Ewww.meridianenergy.co.nz\u003C/a\u003E."},{"type":"nominated","image_url":"https://suppliertest.youdo.co.nz/photos/b0b3034e188ddadb267d2edb62ec5e96.original","name":"Tree Power Top Up","price_per_unit":"0.1983","description":"For each 30 units you buy Treepower will plant a tree through Trees for the Future. \r\n\r\nWe have contracted Trees for the Future to plant a tree for every 30 KWh of TreePower that is used. Trees for the Future has been working with communities in Central America, Asia and Africa since 1989, and we are proud to be able to contribute to their work. They work directly with rural communities in countries and locations that need serious help to restore ecological balance.\r\n\r\nPlanting the trees helps the communities in three ways - restoring degrading lands and farms, minimising erosion, and providing forage for animals. The process also involves training local people to care for their own environment. \r\n\r\nMeanwhile Trees for the Future estimates that each tree will absorb about 50 lb (that's 22 kg) of carbon, though this is not certified, and it will vary depending on the type of tree and the location. If you want to offset the carbon emission impact of your electricity consumption then try our sister product Green Power. \r\n\r\nAbout Tree Power\r\nTree Power is a product from \u003Ca href=\"http://www.powerkiwi.co.nz\"\u003EPowerKiwi\u003C/a\u003E, an independent Kiwi owned company. We have a partnership contract in place with \u003Ca href=\"http://www.treesftf.org/\"\u003ETrees for the Future\u003C/a\u003E.\r\n \r\nWe have just launched Tree Power, but will report back on how many trees are planted as we progress."},{"type":"nominated","image_url":"https://suppliertest.youdo.co.nz/photos/a6406b84e4b2bcc6bd19f70953db7b1e.original","name":"Meridian Crimson","price_per_unit":"0.2044","description":"Choose Meridian Crimson and you play a part in protecting New Zealand's native trees. For every unit of Meridian Crimson electricity you buy, Meridian will donate 2 cents to The Project Crimson Trust - a charitable trust that protects and renews Pohutukawa and Rata trees throughout New Zealand. When you choose Crimson power, you're helping our Kiwi Christmas trees keep blooming brilliant red every summer.\r\n\r\n\u201cMeridian Crimson\u201d is carboNZero\u003Csup\u003EcertTM\u003C/sup\u003E certified electricity. All units of this product used, will be accounted for by Meridian under the rules of the Landcare Research carboNZero programme.\r\n\r\nFor more information about Meridian, or our carboNZero certification, visit \u003Ca href=\"http://www.meridianenergy.co.nz\"\u003Ewww.meridianenergy.co.nz\u003C/a\u003E.\r\n\r\nSee \u003Ca href=\"http://www.projectcrimson.org.nz\"\u003Ewww.projectcrimson.org.nz\u003C/a\u003E for more on the Trust\u2019s work.\r\n \r\n"},{"type":"nominated","image_url":"https://suppliertest.youdo.co.nz/photos/64df17a17766c0b8e85829ee56c1a4aa.original","name":"Flower Power Top Up","price_per_unit":"0.1785","description":"Welcome to \u003Cb\u003EFlower Power\u003C/b\u003E!\r\n\r\nPower companies have been keeping us in the dark. Buying power can actually be \u003Cb\u003Every simple, quick and fun.\u003C/b\u003E\r\n\r\nJoin the Flower Power revolution today and you'll still get electricity from the same source, use the same meter and receive the same professional backup if things go wrong. \r\n\r\n* Take control, and buy electricity on your own terms\r\n* Save money and impress your friends!\r\n* 100% safe, online and paper free\r\n\r\nJoin the Flower Power revolution, and top up with \u003Ca href=\"http://www.flowerpowernz.co.nz/\"\u003EFlower Power\u003C/a\u003E. \r\n\r\n\u003Cb\u003EAbout Flower Power\u003C/b\u003E\r\n\u003Ca href=\"http://www.flowerpowernz.co.nz/\"\u003EFlower Power\u003C/a\u003E is a product from \u003Ca href=\"http://www.powerkiwi.co.nz/\"\u003EPowerKiwi\u003C/a\u003E, an independent NZ owned company."}]}
@@ -0,0 +1 @@
1
+ {"version":"1.0","result":{"properties":[{"last_account_review_at":"2009-10-22 12:00:00","registers":[{"estimated_reading_value":"63922","dials":5,"register_number":"109479:1","last_reading_at":"2009-12-25 00:13:04","description":null,"last_reading_value":"63918","hidden":0,"last_reading_type":"customer"}],"end_date":"","start_date":"2009-02-24","icp_number":"0001427254UNF48","daily_consumption":120.1,"unit_balance":-8261,"address":{"region":null,"street_number":"1","district":"WELLINGTON","street_name":"test_address","flat_number":"12","suburb":"TE ARO"}}]}}
@@ -0,0 +1 @@
1
+ {"version":"1.0","result":{"result":"success"}}
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'stringio'
3
+ require 'test/unit'
4
+ require File.dirname(__FILE__) + '/../lib/powershop'
5
+
6
+ require 'mocha'
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: powershop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nik Wakelin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-26 00:00:00 +13:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: oauth
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.5
34
+ version:
35
+ description: Allows Ruby applications to communicate with the Powershop API
36
+ email: nik@codetocustomer.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - init.rb
45
+ - LICENSE
46
+ - Rakefile
47
+ - README.textile
48
+ - examples/powershop_example.rb
49
+ - lib/powershop.rb
50
+ - lib/powershop/client.rb
51
+ - lib/powershop/oauth.rb
52
+ - lib/powershop/property.rb
53
+ - lib/powershop/register.rb
54
+ - script/console
55
+ - test/client_test.rb
56
+ - test/test_helper.rb
57
+ - test/responses/get_top_up.json
58
+ - test/responses/icp_number_error.json
59
+ - test/responses/meter_readings.json
60
+ - test/responses/products.json
61
+ - test/responses/properties.json
62
+ - test/responses/success.json
63
+ - powershop.gemspec
64
+ has_rdoc: true
65
+ homepage: http://github.com/codetocustomer/powershop
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.5
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Allows Ruby applications to communicate with the Powershop API
92
+ test_files: []
93
+