Class: Powershop::Client
- Inherits:
-
Object
- Object
- Powershop::Client
- Defined in:
- lib/powershop/client.rb
Instance Attribute Summary collapse
-
#oauth ⇒ Object
Returns the value of attribute oauth.
Instance Method Summary collapse
- #get_meter_readings(options = {}) ⇒ Object
- #get_top_up(options = {}) ⇒ Object
-
#initialize(oauth_consumer_key, oauth_consumer_secret) ⇒ Client
constructor
A new instance of Client.
-
#post_meter_readings(readings, options = {}) ⇒ Object
‘readings’ should be a hash of register_number => reading values e.g { “10073:1” => 5000, “10073:2” => 2000 }.
- #products(options = {}) ⇒ Object
- #properties ⇒ Object
-
#set_property(property) ⇒ Object
choose which property (icp_number) to use for all calls requiring an icp_number.
- #top_up!(options = {}) ⇒ Object
Constructor Details
Instance Attribute Details
#oauth ⇒ Object
Returns the value of attribute oauth.
4 5 6 |
# File 'lib/powershop/client.rb', line 4 def oauth @oauth end |
Instance Method Details
#get_meter_readings(options = {}) ⇒ Object
42 43 44 45 46 |
# File 'lib/powershop/client.rb', line 42 def get_meter_readings( = {}) [:end_date] ||= Date.today self.get(api_url("meter_readings"), ) end |
#get_top_up(options = {}) ⇒ Object
70 71 72 |
# File 'lib/powershop/client.rb', line 70 def get_top_up( = {}) self.get(api_url("top_up"), ) end |
#post_meter_readings(readings, options = {}) ⇒ Object
‘readings’ should be a hash of register_number => reading values
e.g
{ "10073:1" => 5000, "10073:2" => 2000 }
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/powershop/client.rb', line 51 def post_meter_readings(readings, = {}) readings.each do |register_number, reading| ["readings[#{register_number}]"] = reading end response = self.post(api_url("meter_readings"), ) if response.result == "success" true else raise reponse. end end |
#products(options = {}) ⇒ Object
66 67 68 |
# File 'lib/powershop/client.rb', line 66 def products( = {}) self.get(api_url("products"), ) end |
#properties ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/powershop/client.rb', line 29 def properties result = self.get(api_url("customer")) result.properties.collect do |p| Property.new(self, p) end end |
#set_property(property) ⇒ Object
choose which property (icp_number) to use for all calls requiring an icp_number
38 39 40 |
# File 'lib/powershop/client.rb', line 38 def set_property(property) @current_property = property end |
#top_up!(options = {}) ⇒ Object
74 75 76 77 78 |
# File 'lib/powershop/client.rb', line 74 def top_up!( = {}) raise "You must specify an Offer Key" unless [:offer_key] self.post(api_url("top_up"), ) end |