Class: IspUsage::Fetchers::AUThree
- 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
- #fetch_usage ⇒ Object
-
#initialize(options) ⇒ AUThree
constructor
A new instance of AUThree.
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() 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 |
# 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') login_form = page.form('login') login_form.login = self.username login_form.password = self.password page = agent.submit(login_form, login_form..first) pin_form = page.form('myForm') if pin_form.nil? puts "Authentication failure" exit(1) end pin_form.pin = [:pin] page = agent.submit(pin_form, pin_form..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 |