Class: IspUsage::Fetchers::AUTpg

Inherits:
Fetcher
  • Object
show all
Defined in:
lib/ispusage/fetchers/au_tpg.rb

Instance Attribute Summary

Attributes inherited from Fetcher

#error, #month_end, #options, #password, #usage_periods, #username

Instance Method Summary collapse

Methods inherited from Fetcher

#month_used, #new_usage_period, #to_hash, #to_json

Constructor Details

#initialize(options) ⇒ AUTpg

Returns a new instance of AUTpg.



7
8
9
# File 'lib/ispusage/fetchers/au_tpg.rb', line 7

def initialize(options)
  super(options)
end

Instance Method Details

#fetch_usageObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ispusage/fetchers/au_tpg.rb', line 11

def fetch_usage
  agent = Mechanize.new

  page = agent.get('https://cyberstore.tpg.com.au/your_account/')
  form = page.form('form')
  form.check_username = self.username
  form.password = self.password

  page = agent.submit(form, form.buttons.first)
  if page.body =~ /Invalid username/
    self.error = "Error: Invalid username or password"
    return
  end

  page = agent.get('https://cyberstore.tpg.com.au/your_account/index.php?function=checkaccountusage')

  usage_text = page.search('table.light_box table tr').text
  peak = self.new_usage_period(:label => 'Peak', :type => :balance)
  peak.used = usage_text.match(/\dPeak Downloads used: (\d+)/)[1].to_i

  offpeak = self.new_usage_period(:label => 'Off Peak', :type => :balance)
  offpeak.used = usage_text.match(/Off-Peak Downloads used: (\d+)/)[1].to_i

end