Class: Powershop::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/powershop/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oauth_consumer_key, oauth_consumer_secret) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
# File 'lib/powershop/client.rb', line 6

def initialize(oauth_consumer_key, oauth_consumer_secret)
  @oauth = OAuth.new(oauth_consumer_key, oauth_consumer_secret)
  
  @current_property = nil
end

Instance Attribute Details

#oauthObject

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(options = {})
  options[:end_date]   ||= Date.today
  
  self.get(api_url("meter_readings"), options)
end

#get_top_up(options = {}) ⇒ Object



70
71
72
# File 'lib/powershop/client.rb', line 70

def get_top_up(options = {})
  self.get(api_url("top_up"), options)
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, options = {})

  readings.each do |register_number, reading|
    options["readings[#{register_number}]"] = reading 
  end
  
  response = self.post(api_url("meter_readings"), options)
  
  if response.result == "success"
    true
  else
    raise reponse.message
  end
end

#products(options = {}) ⇒ Object



66
67
68
# File 'lib/powershop/client.rb', line 66

def products(options = {})
  self.get(api_url("products"), options)
end

#propertiesObject



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!(options = {})
  raise "You must specify an Offer Key" unless options[:offer_key]
  
  self.post(api_url("top_up"), options)
end