ispusage 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/bin/ispusage +6 -0
- data/lib/ispusage/fetchers/fetcher.rb +29 -0
- data/lib/ispusage/fetchers/iinet.rb +22 -0
- data/lib/ispusage/fetchers/internode.rb +50 -0
- data/lib/ispusage/fetchers.rb +3 -0
- data/lib/ispusage/usage_period.rb +31 -0
- data/lib/ispusage.rb +46 -0
- data/spec/fetchers/fetcher_spec.rb +13 -0
- data/spec/fetchers/iinet_spec.rb +21 -0
- data/spec/fetchers/internode_spec.rb +25 -0
- data/spec/fixtures/auiinet_single_account.xml +152 -0
- data/spec/fixtures/auinternode_home.xml +2 -0
- data/spec/fixtures/auinternode_home_usage.xml +7 -0
- data/spec/ispusage_spec.rb +4 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/usage_period_spec.rb +20 -0
- metadata +92 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Alan Harper
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= ispusage
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Alan Harper. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ispusage"
|
8
|
+
gem.summary = %Q{Fetch ISP quota Usage}
|
9
|
+
gem.description = %Q{Fetch ISP qutoa usage}
|
10
|
+
gem.email = "alan@aussiegeek.net"
|
11
|
+
gem.homepage = "http://github.com/aussiegeek/ispusage"
|
12
|
+
gem.authors = ["Alan Harper"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "ispusage #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/ispusage
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class IspUsage
|
5
|
+
class Fetchers
|
6
|
+
class Fetcher
|
7
|
+
attr_accessor :usage_periods, :username, :password
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
@username = options[:username]
|
11
|
+
@password = options[:password]
|
12
|
+
|
13
|
+
self.usage_periods = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_hash
|
17
|
+
{
|
18
|
+
:isp => self.class.to_s.split('::').last,
|
19
|
+
:username => @username,
|
20
|
+
:usage_periods => self.usage_periods.map(&:to_hash)
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json
|
25
|
+
to_hash.to_json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
class IspUsage
|
6
|
+
class Fetchers
|
7
|
+
class AUIinet < Fetcher
|
8
|
+
attr_reader :used, :quota
|
9
|
+
def initialize(options)
|
10
|
+
super(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def fetch_usage
|
14
|
+
xml = open("https://toolbox.iinet.net.au/cgi-bin/new/volume_usage_xml.cgi?action=login&username=#{@username}&password=#{@password}")
|
15
|
+
doc = Nokogiri::XML(xml)
|
16
|
+
used = doc.search("/ii_feed[1]/volume_usage[1]/expected_traffic_types[1]/type[1]/@used").text.to_i / 1048576
|
17
|
+
quota = doc.search("/ii_feed[1]/volume_usage[1]/expected_traffic_types[1]/type[1]/quota_allocation[1]").text.to_i
|
18
|
+
self.usage_periods << UsagePeriod.new(:used => used, :quota => quota)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
|
6
|
+
class IspUsage
|
7
|
+
class Fetchers
|
8
|
+
class AUInternode < Fetcher
|
9
|
+
def initialize(options)
|
10
|
+
super(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def fetch_usage
|
14
|
+
url = URI.parse("https://@customer-webtools-api.internode.on.net/api/v1.5/")
|
15
|
+
req = Net::HTTP::Get.new(url.path)
|
16
|
+
req.basic_auth @username, @password
|
17
|
+
|
18
|
+
services_xml = ""
|
19
|
+
req = Net::HTTP.new('customer-webtools-api.internode.on.net', 443)
|
20
|
+
req.use_ssl = true
|
21
|
+
req.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
22
|
+
req.start() {|http|
|
23
|
+
req = Net::HTTP::Get.new('/api/v1.5/')
|
24
|
+
req.basic_auth @username, @password
|
25
|
+
response = http.request(req)
|
26
|
+
services_xml = response.body
|
27
|
+
}
|
28
|
+
services_doc = Nokogiri::XML(services_xml)
|
29
|
+
service_id = services_doc.search('/internode[1]/api[1]/services[1]/service[1]').text
|
30
|
+
|
31
|
+
usage_xml = ""
|
32
|
+
req = Net::HTTP.new('customer-webtools-api.internode.on.net', 443)
|
33
|
+
req.use_ssl = true
|
34
|
+
req.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
35
|
+
req.start() {|http|
|
36
|
+
req = Net::HTTP::Get.new("/api/v1.5/#{service_id}/usage")
|
37
|
+
req.basic_auth @username, @password
|
38
|
+
response = http.request(req)
|
39
|
+
usage_xml = response.body
|
40
|
+
}
|
41
|
+
|
42
|
+
usage_doc = Nokogiri::XML(usage_xml)
|
43
|
+
|
44
|
+
used = usage_doc.search("/internode[1]/api[1]/traffic[1]").text.to_i / 1000000
|
45
|
+
quota = usage_doc.search("/internode[1]/api[1]/traffic[1]/@quota").text.to_i / 1000000
|
46
|
+
self.usage_periods << UsagePeriod.new(:used => used, :quota => quota)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class IspUsage
|
2
|
+
class UsagePeriod
|
3
|
+
attr_accessor :quota, :used, :label
|
4
|
+
def initialize(options = {})
|
5
|
+
self.label = 'No Label Set'
|
6
|
+
auto_setters = [:quota, :used, :label]
|
7
|
+
options.each do |key, value|
|
8
|
+
if auto_setters.include?(key)
|
9
|
+
self.send(key.to_s + '=', value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def total
|
15
|
+
if quota > used
|
16
|
+
return quota
|
17
|
+
else
|
18
|
+
return used
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_hash
|
23
|
+
{
|
24
|
+
:quota => quota,
|
25
|
+
:used => used,
|
26
|
+
:total => total,
|
27
|
+
:label => label
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/ispusage.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'ispusage/fetchers'
|
2
|
+
require 'ispusage/usage_period'
|
3
|
+
require 'optparse'
|
4
|
+
require 'pp'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
class IspUsage
|
8
|
+
|
9
|
+
ISPS = [
|
10
|
+
'AUBigpond',
|
11
|
+
'AUIinet',
|
12
|
+
'AUInternode'
|
13
|
+
]
|
14
|
+
|
15
|
+
class Cli
|
16
|
+
class << self
|
17
|
+
def run!(*args)
|
18
|
+
options = {:output => :text}
|
19
|
+
optparse = OptionParser.new do|opts|
|
20
|
+
opts.on('-i', '--isp isp', 'ISP') {|i| options[:isp] = i}
|
21
|
+
opts.on('-u', '--username username', 'Username') {|u| options[:username] = u}
|
22
|
+
opts.on('-p', '--password password', 'Password') {|p| options[:password] = p}
|
23
|
+
opts.on('-j', '--json', 'JSON Output') {|j| options[:output] = :json}
|
24
|
+
end
|
25
|
+
optparse.parse!
|
26
|
+
|
27
|
+
unless ISPS.include?(options[:isp])
|
28
|
+
puts 'Unknown ISP: ' + options[:isp]
|
29
|
+
return 1
|
30
|
+
end
|
31
|
+
|
32
|
+
ispclass = eval("IspUsage::Fetchers::#{options[:isp]}")
|
33
|
+
fetcher = ispclass.new(options)
|
34
|
+
|
35
|
+
fetcher.fetch_usage
|
36
|
+
case options[:output]
|
37
|
+
when :text
|
38
|
+
puts fetcher.used.to_s + '/' + fetcher.quota.to_s
|
39
|
+
when :json
|
40
|
+
puts fetcher.to_json
|
41
|
+
end
|
42
|
+
return 0
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe IspUsage::Fetchers::Fetcher do
|
4
|
+
it "should return hash for usage information" do
|
5
|
+
@usage = IspUsage::Fetchers::Fetcher.new(:username => 'bob', :password => 'xkcd')
|
6
|
+
@usage.usage_periods << IspUsage::UsagePeriod.new(:used => 500, :quota => 1000, :label => 'All Day')
|
7
|
+
@usage.to_hash.should == {
|
8
|
+
:usage_periods => [{:used => 500, :quota => 1000, :total => 1000, :label => 'All Day'}],
|
9
|
+
:isp => 'Fetcher',
|
10
|
+
:username => 'bob'
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe IspUsage::Fetchers::AUIinet do
|
4
|
+
describe "single usage period" do
|
5
|
+
before do
|
6
|
+
fixture = File.read(File.dirname(__FILE__) + '/../fixtures/auiinet_single_account.xml')
|
7
|
+
FakeWeb.register_uri(:get, 'https://toolbox.iinet.net.au/cgi-bin/new/volume_usage_xml.cgi?action=login&username=user&password=password', :body => fixture)
|
8
|
+
options = {:username => 'user', :password => 'password'}
|
9
|
+
@usage = IspUsage::Fetchers::AUIinet.new(options)
|
10
|
+
@usage.fetch_usage
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return usage correctly" do
|
14
|
+
@usage.usage_periods.first.used.should == 28613
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return quota correctly" do
|
18
|
+
@usage.usage_periods.first.quota.should == 100000
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe IspUsage::Fetchers::AUInternode do
|
4
|
+
describe "single usage period" do
|
5
|
+
before do
|
6
|
+
services = File.read(File.dirname(__FILE__) + '/../fixtures/auinternode_home.xml')
|
7
|
+
FakeWeb.register_uri(:get, 'https://user:password@customer-webtools-api.internode.on.net/api/v1.5/', :body => services)
|
8
|
+
service = File.read(File.dirname(__FILE__) + '/../fixtures/auinternode_home_usage.xml')
|
9
|
+
FakeWeb.register_uri(:get, 'https://user:password@customer-webtools-api.internode.on.net/api/v1.5/1234567/usage', :body => service)
|
10
|
+
|
11
|
+
|
12
|
+
options = {:username => 'user', :password => 'password'}
|
13
|
+
@usage = IspUsage::Fetchers::AUInternode.new(options)
|
14
|
+
@usage.fetch_usage
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return usage correctly" do
|
18
|
+
@usage.usage_periods.first.used.should == 38565
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return quota correctly" do
|
22
|
+
@usage.usage_periods.first.quota.should == 50000
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
<ii_feed>
|
2
|
+
<account_info>
|
3
|
+
<plan>Business 3</plan>
|
4
|
+
<product>adsl_business V2</product>
|
5
|
+
</account_info>
|
6
|
+
<volume_usage>
|
7
|
+
<quota_reset>
|
8
|
+
<anniversary>28</anniversary>
|
9
|
+
<days_so_far>10</days_so_far>
|
10
|
+
<days_remaining>22</days_remaining>
|
11
|
+
</quota_reset>
|
12
|
+
<expected_traffic_types>
|
13
|
+
<type classification="anytime" used="30003394620">
|
14
|
+
<name>non-free</name>
|
15
|
+
<quota_allocation>100000</quota_allocation>
|
16
|
+
<is_shaped speed="0">false</is_shaped>
|
17
|
+
</type>
|
18
|
+
<type classification="freezone" used="1467105012">
|
19
|
+
<name>freezone</name>
|
20
|
+
</type>
|
21
|
+
</expected_traffic_types>
|
22
|
+
<volume_usage>
|
23
|
+
<day_hour period="2010-01-28">
|
24
|
+
<usage type="anytime">8476364804</usage>
|
25
|
+
<usage type="freezone">19950428</usage>
|
26
|
+
</day_hour>
|
27
|
+
<day_hour period="2010-01-29">
|
28
|
+
<usage type="anytime">5680001329</usage>
|
29
|
+
<usage type="freezone">2678761</usage>
|
30
|
+
</day_hour>
|
31
|
+
<day_hour period="2010-01-30">
|
32
|
+
<usage type="anytime">235408370</usage>
|
33
|
+
<usage type="freezone">55411712</usage>
|
34
|
+
</day_hour>
|
35
|
+
<day_hour period="2010-01-31">
|
36
|
+
<usage type="anytime">158825278</usage>
|
37
|
+
<usage type="freezone">2005748</usage>
|
38
|
+
</day_hour>
|
39
|
+
<day_hour period="2010-02-01">
|
40
|
+
<usage type="anytime">838021923</usage>
|
41
|
+
<usage type="freezone">6545194</usage>
|
42
|
+
</day_hour>
|
43
|
+
<day_hour period="2010-02-02">
|
44
|
+
<usage type="anytime">665067485</usage>
|
45
|
+
<usage type="freezone">5278122</usage>
|
46
|
+
</day_hour>
|
47
|
+
<day_hour period="2010-02-03">
|
48
|
+
<usage type="anytime">518595034</usage>
|
49
|
+
<usage type="freezone">119592204</usage>
|
50
|
+
</day_hour>
|
51
|
+
<day_hour period="2010-02-04">
|
52
|
+
<usage type="anytime">7044499877</usage>
|
53
|
+
<usage type="freezone">1067657233</usage>
|
54
|
+
</day_hour>
|
55
|
+
<day_hour period="2010-02-05">
|
56
|
+
<usage type="anytime">5841971792</usage>
|
57
|
+
<usage type="freezone">118317383</usage>
|
58
|
+
</day_hour>
|
59
|
+
<day_hour period="2010-02-06">
|
60
|
+
<usage type="anytime">544638728</usage>
|
61
|
+
<usage type="freezone">69668227</usage>
|
62
|
+
</day_hour>
|
63
|
+
<day_hour period="2010-02-07">
|
64
|
+
<usage type="anytime">0</usage>
|
65
|
+
<usage type="freezone">0</usage>
|
66
|
+
</day_hour>
|
67
|
+
<day_hour period="2010-02-08">
|
68
|
+
<usage type="anytime">0</usage>
|
69
|
+
<usage type="freezone">0</usage>
|
70
|
+
</day_hour>
|
71
|
+
<day_hour period="2010-02-09">
|
72
|
+
<usage type="anytime">0</usage>
|
73
|
+
<usage type="freezone">0</usage>
|
74
|
+
</day_hour>
|
75
|
+
<day_hour period="2010-02-10">
|
76
|
+
<usage type="anytime">0</usage>
|
77
|
+
<usage type="freezone">0</usage>
|
78
|
+
</day_hour>
|
79
|
+
<day_hour period="2010-02-11">
|
80
|
+
<usage type="anytime">0</usage>
|
81
|
+
<usage type="freezone">0</usage>
|
82
|
+
</day_hour>
|
83
|
+
<day_hour period="2010-02-12">
|
84
|
+
<usage type="anytime">0</usage>
|
85
|
+
<usage type="freezone">0</usage>
|
86
|
+
</day_hour>
|
87
|
+
<day_hour period="2010-02-13">
|
88
|
+
<usage type="anytime">0</usage>
|
89
|
+
<usage type="freezone">0</usage>
|
90
|
+
</day_hour>
|
91
|
+
<day_hour period="2010-02-14">
|
92
|
+
<usage type="anytime">0</usage>
|
93
|
+
<usage type="freezone">0</usage>
|
94
|
+
</day_hour>
|
95
|
+
<day_hour period="2010-02-15">
|
96
|
+
<usage type="anytime">0</usage>
|
97
|
+
<usage type="freezone">0</usage>
|
98
|
+
</day_hour>
|
99
|
+
<day_hour period="2010-02-16">
|
100
|
+
<usage type="anytime">0</usage>
|
101
|
+
<usage type="freezone">0</usage>
|
102
|
+
</day_hour>
|
103
|
+
<day_hour period="2010-02-17">
|
104
|
+
<usage type="anytime">0</usage>
|
105
|
+
<usage type="freezone">0</usage>
|
106
|
+
</day_hour>
|
107
|
+
<day_hour period="2010-02-18">
|
108
|
+
<usage type="anytime">0</usage>
|
109
|
+
<usage type="freezone">0</usage>
|
110
|
+
</day_hour>
|
111
|
+
<day_hour period="2010-02-19">
|
112
|
+
<usage type="anytime">0</usage>
|
113
|
+
<usage type="freezone">0</usage>
|
114
|
+
</day_hour>
|
115
|
+
<day_hour period="2010-02-20">
|
116
|
+
<usage type="anytime">0</usage>
|
117
|
+
<usage type="freezone">0</usage>
|
118
|
+
</day_hour>
|
119
|
+
<day_hour period="2010-02-21">
|
120
|
+
<usage type="anytime">0</usage>
|
121
|
+
<usage type="freezone">0</usage>
|
122
|
+
</day_hour>
|
123
|
+
<day_hour period="2010-02-22">
|
124
|
+
<usage type="anytime">0</usage>
|
125
|
+
<usage type="freezone">0</usage>
|
126
|
+
</day_hour>
|
127
|
+
<day_hour period="2010-02-23">
|
128
|
+
<usage type="anytime">0</usage>
|
129
|
+
<usage type="freezone">0</usage>
|
130
|
+
</day_hour>
|
131
|
+
<day_hour period="2010-02-24">
|
132
|
+
<usage type="anytime">0</usage>
|
133
|
+
<usage type="freezone">0</usage>
|
134
|
+
</day_hour>
|
135
|
+
<day_hour period="2010-02-25">
|
136
|
+
<usage type="anytime">0</usage>
|
137
|
+
<usage type="freezone">0</usage>
|
138
|
+
</day_hour>
|
139
|
+
<day_hour period="2010-02-26">
|
140
|
+
<usage type="anytime">0</usage>
|
141
|
+
<usage type="freezone">0</usage>
|
142
|
+
</day_hour>
|
143
|
+
<day_hour period="2010-02-27">
|
144
|
+
<usage type="anytime">0</usage>
|
145
|
+
<usage type="freezone">0</usage>
|
146
|
+
</day_hour>
|
147
|
+
</volume_usage>
|
148
|
+
</volume_usage>
|
149
|
+
<connections>
|
150
|
+
<ip on_since="2010-02-04 20:38:12">1.2.3.4</ip>
|
151
|
+
</connections>
|
152
|
+
</ii_feed>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<internode>
|
3
|
+
<api>
|
4
|
+
<service type='Personal_ADSL' request='usage'>2659798</service>
|
5
|
+
<traffic name='total' rollover='2010-02-21' plan-interval='Monthly' quota='50000000000' unit='bytes'>38565393900</traffic>
|
6
|
+
</api>
|
7
|
+
</internode>
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib', 'ispusage'))
|
3
|
+
require 'ispusage'
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'spec'
|
7
|
+
require 'spec/autorun'
|
8
|
+
require 'fakeweb'
|
9
|
+
|
10
|
+
FakeWeb.allow_net_connect = false
|
11
|
+
Spec::Runner.configure do |config|
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe IspUsage::UsagePeriod do
|
4
|
+
it "should return hash for usage period" do
|
5
|
+
@usage_period = IspUsage::UsagePeriod.new(:quota => 1000, :used => 500, :label => 'All Day')
|
6
|
+
@usage_period.to_hash.should == {:quota => 1000, :used => 500, :total => 1000, :label => 'All Day'}
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "calculate totals" do
|
10
|
+
it "when under quota" do
|
11
|
+
@usage_period = IspUsage::UsagePeriod.new(:quota => 1000, :used => 500)
|
12
|
+
@usage_period.total.should == 1000
|
13
|
+
end
|
14
|
+
|
15
|
+
it "when over quota" do
|
16
|
+
@usage_period = IspUsage::UsagePeriod.new(:quota => 1000, :used => 1500)
|
17
|
+
@usage_period.total.should == 1500
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ispusage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alan Harper
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-13 00:00:00 +10:00
|
13
|
+
default_executable: ispusage
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
description: Fetch ISP qutoa usage
|
26
|
+
email: alan@aussiegeek.net
|
27
|
+
executables:
|
28
|
+
- ispusage
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- bin/ispusage
|
42
|
+
- lib/ispusage.rb
|
43
|
+
- lib/ispusage/fetchers.rb
|
44
|
+
- lib/ispusage/fetchers/fetcher.rb
|
45
|
+
- lib/ispusage/fetchers/iinet.rb
|
46
|
+
- lib/ispusage/fetchers/internode.rb
|
47
|
+
- lib/ispusage/usage_period.rb
|
48
|
+
- spec/fetchers/fetcher_spec.rb
|
49
|
+
- spec/fetchers/iinet_spec.rb
|
50
|
+
- spec/fetchers/internode_spec.rb
|
51
|
+
- spec/fixtures/auiinet_single_account.xml
|
52
|
+
- spec/fixtures/auinternode_home.xml
|
53
|
+
- spec/fixtures/auinternode_home_usage.xml
|
54
|
+
- spec/ispusage_spec.rb
|
55
|
+
- spec/spec.opts
|
56
|
+
- spec/spec_helper.rb
|
57
|
+
- spec/usage_period_spec.rb
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: http://github.com/aussiegeek/ispusage
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --charset=UTF-8
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.3.5
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Fetch ISP quota Usage
|
86
|
+
test_files:
|
87
|
+
- spec/fetchers/fetcher_spec.rb
|
88
|
+
- spec/fetchers/iinet_spec.rb
|
89
|
+
- spec/fetchers/internode_spec.rb
|
90
|
+
- spec/ispusage_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
- spec/usage_period_spec.rb
|