ispusage 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/ispusage/fetchers/au_exetel.rb +36 -0
- data/lib/ispusage/fetchers/au_tpg.rb +39 -0
- data/lib/ispusage/fetchers/fetcher.rb +8 -2
- data/lib/ispusage/fetchers.rb +2 -0
- data/lib/ispusage/usage_period.rb +1 -2
- data/lib/ispusage.rb +2 -0
- data/spec/fetchers/au_exetel_spec.rb +49 -0
- data/spec/fetchers/au_tpg_spec.rb +62 -0
- data/spec/fetchers/fetcher_spec.rb +12 -0
- data/spec/fixtures/au_exetel/login.html +70 -0
- data/spec/fixtures/au_exetel/usage.html +589 -0
- data/spec/fixtures/au_tpg/failure.html +285 -0
- data/spec/fixtures/au_tpg/login.html +145 -0
- data/spec/fixtures/au_tpg/usage.html +145 -0
- metadata +13 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'mechanize'
|
3
|
+
|
4
|
+
class IspUsage
|
5
|
+
class Fetchers
|
6
|
+
class AUExetel < Fetcher
|
7
|
+
def initialize(options)
|
8
|
+
super(options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def fetch_usage
|
12
|
+
agent = Mechanize.new
|
13
|
+
|
14
|
+
page = agent.get('http://www.exetel.com.au/index_alt.php')
|
15
|
+
form = page.form('loginform')
|
16
|
+
form.login_name = self.username
|
17
|
+
form.password = self.password
|
18
|
+
|
19
|
+
page = agent.submit(form, form.buttons.first)
|
20
|
+
|
21
|
+
page.search('.new_usage_content').each do |usage_div|
|
22
|
+
usage_period = UsagePeriod.new
|
23
|
+
matches = usage_div.text.match(/^(\d+\.\d+)\D+(\d+)/)
|
24
|
+
next if matches.nil?
|
25
|
+
usage_period.used = matches[1].to_f * 1000
|
26
|
+
usage_period.quota = matches[2].to_f * 1000
|
27
|
+
|
28
|
+
usage_periods << usage_period
|
29
|
+
end
|
30
|
+
|
31
|
+
usage_periods.first.label = 'Peak'
|
32
|
+
usage_periods.last.label = 'Off Peak'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'mechanize'
|
3
|
+
|
4
|
+
class IspUsage
|
5
|
+
class Fetchers
|
6
|
+
class AUTpg < Fetcher
|
7
|
+
def initialize(options)
|
8
|
+
super(options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def fetch_usage
|
12
|
+
agent = Mechanize.new
|
13
|
+
|
14
|
+
page = agent.get('https://cyberstore.tpg.com.au/your_account/')
|
15
|
+
form = page.form('form')
|
16
|
+
form.check_username = self.username
|
17
|
+
form.password = self.password
|
18
|
+
|
19
|
+
page = agent.submit(form, form.buttons.first)
|
20
|
+
if page.body =~ /Invalid username/
|
21
|
+
self.error = "Error: Invalid username or password"
|
22
|
+
return
|
23
|
+
end
|
24
|
+
|
25
|
+
page = agent.get('https://cyberstore.tpg.com.au/your_account/index.php?function=checkaccountusage')
|
26
|
+
|
27
|
+
usage_text = page.search('table.light_box table tr').text
|
28
|
+
peak = UsagePeriod.new(:label => 'Peak', :type => :balance)
|
29
|
+
usage_periods << peak
|
30
|
+
peak.used = usage_text.match(/\dPeak Downloads used: (\d+)/)[1].to_i
|
31
|
+
|
32
|
+
offpeak = UsagePeriod.new(:label => 'Off Peak', :type => :balance)
|
33
|
+
usage_periods << offpeak
|
34
|
+
offpeak.used = usage_text.match(/Off-Peak Downloads used: (\d+)/)[1].to_i
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -4,7 +4,7 @@ require 'json'
|
|
4
4
|
class IspUsage
|
5
5
|
class Fetchers
|
6
6
|
class Fetcher
|
7
|
-
attr_accessor :usage_periods, :username, :password, :options
|
7
|
+
attr_accessor :usage_periods, :username, :password, :options, :error
|
8
8
|
|
9
9
|
def initialize(options)
|
10
10
|
@username = options[:username]
|
@@ -14,11 +14,17 @@ class IspUsage
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_hash
|
17
|
-
{
|
17
|
+
hash = {
|
18
18
|
:isp => self.class.to_s.split('::').last,
|
19
19
|
:username => @username,
|
20
20
|
:usage_periods => self.usage_periods.map(&:to_hash)
|
21
21
|
}
|
22
|
+
|
23
|
+
unless error.nil?
|
24
|
+
hash[:error] = error
|
25
|
+
end
|
26
|
+
|
27
|
+
hash
|
22
28
|
end
|
23
29
|
|
24
30
|
def to_json
|
data/lib/ispusage/fetchers.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'ispusage/fetchers/fetcher'
|
2
2
|
require 'ispusage/fetchers/au_optus'
|
3
|
+
require 'ispusage/fetchers/au_exetel'
|
3
4
|
require 'ispusage/fetchers/au_three'
|
5
|
+
require 'ispusage/fetchers/au_tpg'
|
4
6
|
require 'ispusage/fetchers/iinet'
|
5
7
|
require 'ispusage/fetchers/internode'
|
6
8
|
require 'ispusage/fetchers/au_translink'
|
@@ -3,9 +3,8 @@ class IspUsage
|
|
3
3
|
attr_accessor :quota, :used, :label
|
4
4
|
attr_reader :type
|
5
5
|
def initialize(options = {})
|
6
|
-
self.label = 'No Label Set'
|
7
6
|
self.type = :meter
|
8
|
-
|
7
|
+
self.label = ''
|
9
8
|
auto_setters = [:quota, :used, :label, :type]
|
10
9
|
options.each do |key, value|
|
11
10
|
if auto_setters.include?(key)
|
data/lib/ispusage.rb
CHANGED
@@ -10,8 +10,10 @@ class IspUsage
|
|
10
10
|
ISPS = [
|
11
11
|
{:class => 'AUIinet', :name => 'iiNet'},
|
12
12
|
{:class => 'AUInternode', :name => 'Internode'},
|
13
|
+
{:class => 'AUExetel', :name => 'Exetel'},
|
13
14
|
{:class => 'AUOptus', :name => 'Optus'},
|
14
15
|
{:class => 'AUThree', :name => 'Three'},
|
16
|
+
{:class => 'AUTpg', :name => 'TPG'},
|
15
17
|
{:class => 'AUTranslink', :name => 'Translink'}
|
16
18
|
]
|
17
19
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe IspUsage::Fetchers::AUExetel do
|
4
|
+
it "should be included in the ISP list" do
|
5
|
+
IspUsage::ISPS.map{|i| i[:class]}.should include('AUExetel')
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "single usage period" do
|
9
|
+
before do
|
10
|
+
signon = File.read(File.dirname(__FILE__) + '/../fixtures/au_exetel/login.html')
|
11
|
+
FakeWeb.register_uri(:get, 'http://www.exetel.com.au/index_alt.php', :response => signon)
|
12
|
+
usage = File.read(File.dirname(__FILE__) + '/../fixtures/au_exetel/usage.html')
|
13
|
+
FakeWeb.register_uri(:post, 'https://www.exetel.com.au/login/redirect.php', :response => usage)
|
14
|
+
|
15
|
+
options = {:username => 'user', :password => 'password'}
|
16
|
+
@usage = IspUsage::Fetchers::AUExetel.new(options)
|
17
|
+
@usage.fetch_usage
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "peak usage" do
|
21
|
+
it "should return usage correctly" do
|
22
|
+
@usage.usage_periods.first.used.should == 13150
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return quota correctly" do
|
26
|
+
@usage.usage_periods.first.quota.should == 70000
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should set label to phone number" do
|
30
|
+
@usage.usage_periods.first.label.should == "Peak"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "off peak usage" do
|
35
|
+
it "should return usage correctly" do
|
36
|
+
@usage.usage_periods.last.used.should == 6920
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return quota correctly" do
|
40
|
+
@usage.usage_periods.last.quota.should == 60000
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should set label to phone number" do
|
44
|
+
@usage.usage_periods.last.label.should == "Off Peak"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe IspUsage::Fetchers::AUTpg do
|
4
|
+
it "should be included in the ISP list" do
|
5
|
+
IspUsage::ISPS.map{|i| i[:class]}.should include('AUTpg')
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "single usage period" do
|
9
|
+
before do
|
10
|
+
signon = File.read(File.dirname(__FILE__) + '/../fixtures/au_tpg/login.html')
|
11
|
+
FakeWeb.register_uri(:get, 'https://cyberstore.tpg.com.au/your_account/', :response => signon)
|
12
|
+
FakeWeb.register_uri(:post, 'https://cyberstore.tpg.com.au/your_account/index.php', :response => signon)
|
13
|
+
usage = File.read(File.dirname(__FILE__) + '/../fixtures/au_tpg/usage.html')
|
14
|
+
FakeWeb.register_uri(:get, 'https://cyberstore.tpg.com.au/your_account/index.php?function=checkaccountusage', :response => usage)
|
15
|
+
|
16
|
+
options = {:username => 'user', :password => 'password'}
|
17
|
+
@usage = IspUsage::Fetchers::AUTpg.new(options)
|
18
|
+
@usage.fetch_usage
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "peak usage" do
|
22
|
+
it "should return usage correctly" do
|
23
|
+
@usage.usage_periods.first.used.should == 921
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be a balance" do
|
27
|
+
@usage.usage_periods.first.type.should == :balance
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should set label to phone number" do
|
31
|
+
@usage.usage_periods.first.label.should == "Peak"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "off peak usage" do
|
36
|
+
it "should return usage correctly" do
|
37
|
+
@usage.usage_periods.last.used.should == 1402
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be a balance" do
|
41
|
+
@usage.usage_periods.last.type.should == :balance
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should set label to phone number" do
|
45
|
+
@usage.usage_periods.last.label.should == "Off Peak"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should handle a logon failure" do
|
52
|
+
signon = File.read(File.dirname(__FILE__) + '/../fixtures/au_tpg/login.html')
|
53
|
+
FakeWeb.register_uri(:get, 'https://cyberstore.tpg.com.au/your_account/', :response => signon)
|
54
|
+
failure = File.read(File.dirname(__FILE__) + '/../fixtures/au_tpg/failure.html')
|
55
|
+
FakeWeb.register_uri(:post, 'https://cyberstore.tpg.com.au/your_account/index.php', :response => failure)
|
56
|
+
|
57
|
+
options = {:username => 'user', :password => 'password'}
|
58
|
+
@usage = IspUsage::Fetchers::AUTpg.new(options)
|
59
|
+
@usage.fetch_usage
|
60
|
+
@usage.error.should == "Error: Invalid username or password"
|
61
|
+
end
|
62
|
+
end
|
@@ -10,4 +10,16 @@ describe IspUsage::Fetchers::Fetcher do
|
|
10
10
|
:username => 'bob'
|
11
11
|
}
|
12
12
|
end
|
13
|
+
|
14
|
+
it "should return an error" do
|
15
|
+
@usage = IspUsage::Fetchers::Fetcher.new(:username => 'bob', :password => 'xkcd')
|
16
|
+
@usage.error = "Invalid username/password"
|
17
|
+
|
18
|
+
@usage.to_hash.should == {
|
19
|
+
:isp => 'Fetcher',
|
20
|
+
:username => 'bob',
|
21
|
+
:error => "Invalid username/password",
|
22
|
+
:usage_periods => []
|
23
|
+
}
|
24
|
+
end
|
13
25
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: text/html; charset=iso-8859-1
|
3
|
+
|
4
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
6
|
+
<head><title>Exetel Pty Ltd</title>
|
7
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
8
|
+
<meta name="Keywords" content="ADSL, ADSL2, VoIP, HSPA, HSDPA, Mobile, Hosting, Value, X Calling Card, Exetel, Residential, Business, Corporate, Agents, Country Broadband, SMS via ADSL, Wireless, Wireline, Voice, Ethernet, SHDSL, Fibre, Business Grade, VPN, VISP, Telephony, Cheap, Telephony" />
|
9
|
+
<meta name="Description" content="Exetel have been providing a range of Internet and phone services to customers since Feb' 2004. There are now over 100,000 customers using a wide range of different Exetel services in every State and Territory." />
|
10
|
+
<link href="css/index_alt.css" rel="stylesheet" type="text/css" />
|
11
|
+
<script type="text/javascript" src="js/index_alt.js"></script>
|
12
|
+
</head>
|
13
|
+
<body>
|
14
|
+
|
15
|
+
<div id="container">
|
16
|
+
<div id="login">
|
17
|
+
<form action="https://www.exetel.com.au/login/redirect.php" method="post" name="loginform">
|
18
|
+
<input type="text" name="login_name" accesskey="u" tabindex="1" class="input_text" autocomplete="on" />
|
19
|
+
<input type="password" name="password" accesskey="p" tabindex="2" class="input_text" />
|
20
|
+
<input name="doLogin" type="hidden" value="1" />
|
21
|
+
<input type="image" name="submit" src="images/front_btn_login.gif" class="btn_login" />
|
22
|
+
</form>
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<div id="button_resi">
|
26
|
+
<a class="button_resi" href="res_main.php"><!-- --></a>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div id="button_busi">
|
30
|
+
<a class="button_busi" href="small_main.php"><!-- --></a>
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<div id="button_corp">
|
34
|
+
<a class="button_corp" href="large_main.php"><!-- --></a>
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<div id="button_agen">
|
38
|
+
<a class="button_agen" href="agents_main.php"><!-- --></a>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="button_country">
|
42
|
+
<a class="button_country" href="http://www.countrybroadband.com.au"><!-- --></a>
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<div id="button_wireless">
|
46
|
+
<a class="button_wireless" href="residential-hspa-information.php"><!-- --></a>
|
47
|
+
</div>
|
48
|
+
|
49
|
+
<div id="bottom_left_logo">
|
50
|
+
<a href="http://www.australiangeographic.com.au/society/2009-conservationist-of-the-year-awardee-ray-thomas.htm" target="_blank"><img src="images/ausGeo_web_logo.gif" alt="Australian Geographic" /></a>
|
51
|
+
</div>
|
52
|
+
|
53
|
+
<div id="links">
|
54
|
+
<ul>
|
55
|
+
<li><a href="https://helpdesk.exetel.com.au/">Helpdesk</a></li>
|
56
|
+
<li><a href="http://mirror.exetel.com.au/">Mirror</a></li>
|
57
|
+
<li><a href="http://games.exetel.com.au">Games</a></li>
|
58
|
+
<li><a href="https://webmail.exetel.com.au/src/login.php">Webmail</a></li>
|
59
|
+
<li><a href="http://forum.exetel.com.au/">Forums</a></li>
|
60
|
+
<li><a href="news_main.php">About</a></li>
|
61
|
+
<li><a href="a_network.php">Network Status</a></li>
|
62
|
+
<li><a href="contact.php">Contact</a></li>
|
63
|
+
</ul>
|
64
|
+
</div>
|
65
|
+
</div>
|
66
|
+
|
67
|
+
<div id="noflash"><a href="index.php">Click here for the <b>Flash</b> version</a></div>
|
68
|
+
|
69
|
+
</body>
|
70
|
+
</html>
|