5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/carrier_services/mtn.rb', line 5
def get_balance(msisdn,pin)
agent = Mechanize.new
agent.user_agent_alias = 'Mac Safari'
page = agent.get BALANCE_URL
login = page.form_with :name => "aspnetForm"
login.field_with(:name => /UserName/).value = msisdn
login.field_with(:name => /Password/).value = pin
login.add_field!('ctl00$ctl00$ctl09$g_22bbfcb4_42f7_422e_af7b_16e2d59216f4$ctl01$LoginView1$Login1$Login1$LoginButton', 'ctl00$Login1')
balance = login.submit
number_div = (balance.search('span').find_all { |node| node['id'] =~ /blMsisdn/}).first
balance_div = (balance.search('span').find_all { |node| node['id'] =~ /lblPurchaseLimit/}).first
bundle_type_div = (balance.search('span').find_all { |node| node['id'] =~ /lblBundleType/}).first
bundle_amount_div = (balance.search('span').find_all { |node| node['id'] =~ /lblBundleBalance/}).first
bundle_expire_div = (balance.search('span').find_all { |node| node['id'] =~ /lblBundleExpDate/}).first
{
:msisdn =>number_div.text,
:airtime =>balance_div.text,
:bundles => [
{
:type=>bundle_type_div.text,
:amount=>bundle_amount_div.text,
:expires=>bundle_expire_div.text
}
]
}
end
|