Class: IspUsage::Fetchers::AUThree

Inherits:
Fetcher
  • Object
show all
Defined in:
lib/ispusage/fetchers/au_three.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) ⇒ AUThree

Returns a new instance of AUThree.



7
8
9
# File 'lib/ispusage/fetchers/au_three.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
# File 'lib/ispusage/fetchers/au_three.rb', line 11

def fetch_usage
  agent = Mechanize.new
  page = agent.get('https://www.my.three.com.au/My3/jfn')
   = page.form('login')
  . = self.username
  .password = self.password
  page = agent.submit(, .buttons.first)
  pin_form = page.form('myForm')
  if pin_form.nil?
    puts "Authentication failure"
    exit(1)
  end
  pin_form.pin = options[:pin]
  page = agent.submit(pin_form, pin_form.buttons.first)
  
  downloads = self.new_usage_period
  self.month_end = Time.parse(page.search("/html/body/div/div/div[3]/div/div[3]/table/tbody/tr/td[4]/p[3]").text)
  downloads.quota = page.search("td[width='190px;']").text.strip.to_i
  downloads.used = downloads.quota - page.search('br+strong.largeclass').text.strip.to_i
end