Class: IspUsage::Fetchers::AUExetel
- Defined in:
- lib/ispusage/fetchers/au_exetel.rb
Instance Attribute Summary
Attributes inherited from Fetcher
#error, #month_end, #options, #password, #usage_periods, #username
Instance Method Summary collapse
- #fetch_usage ⇒ Object
-
#initialize(options) ⇒ AUExetel
constructor
A new instance of AUExetel.
Methods inherited from Fetcher
#month_used, #new_usage_period, #to_hash, #to_json
Constructor Details
#initialize(options) ⇒ AUExetel
Returns a new instance of AUExetel.
7 8 9 |
# File 'lib/ispusage/fetchers/au_exetel.rb', line 7 def initialize() super() end |
Instance Method Details
#fetch_usage ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ispusage/fetchers/au_exetel.rb', line 11 def fetch_usage agent = Mechanize.new page = agent.get('http://www.exetel.com.au/index_alt.php') form = page.form('loginform') form.login_name = self.username form.password = self.password page = agent.submit(form, form..first) month_start = Time.parse(page.search('/html/body/div/div[3]/div[2]/div[2]/div/p').text.match(/Usage From: (\S+)/)[0]) self.month_end = Time.local(month_start.year, month_start.month + 1, month_start.day) page.search('.new_usage_content').each do |usage_div| matches = usage_div.text.match(/^(\d+\.\d+)\D+(\d+)/) next if matches.nil? usage_period = self.new_usage_period usage_period.used = matches[1].to_f * 1000 usage_period.quota = matches[2].to_f * 1000 end usage_periods.first.label = 'Peak' usage_periods.last.label = 'Off Peak' end |