Class: IspUsage::Fetchers::AUOptus
- Defined in:
- lib/ispusage/fetchers/au_optus.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) ⇒ AUOptus
constructor
A new instance of AUOptus.
Methods inherited from Fetcher
#month_used, #new_usage_period, #to_hash, #to_json
Constructor Details
#initialize(options) ⇒ AUOptus
Returns a new instance of AUOptus.
7 8 9 |
# File 'lib/ispusage/fetchers/au_optus.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 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ispusage/fetchers/au_optus.rb', line 11 def fetch_usage agent = Mechanize.new page = agent.get('https://my.optus.com.au/web/oscportal.portal?site=personal') form = page.form('Login') form['USER'] = self.username form['PASSWORD'] = self.password page = agent.submit(form, form..first) account_no = page.search('h2').text.match(/\d+/) services = page.search('ol.service_list') services.each do |service| phone_no = service.search('div>a').text.strip page = agent.get("https://my.optus.com.au/web/oscportal.portal?_nfpb=true&_pageLabel=redirectPage&redirectTo=deeplink_myusage_postpaid&site=personal&pageName=unbilledUsage&virAcctNum=#{phone_no}&accNum=#{account_no}&_activeBA=#{account_no}&_activeSI=#{phone_no}") plan_text = page.search("html>body>div>div>div:nth-of-type(3)>div>div:nth-of-type(2)>div:nth-of-type(4)>div>table tr:nth-of-type(5)>td>table tr:nth-of-type(2)>td>div>table tr:nth-of-type(2)>td:nth-of-type(2)").text downloads = self.new_usage_period start_date = Time.parse(page.form('UnbilledUsageTableForm')['fromDate']) self.month_end = Time.local(start_date.year, start_date.day + 1, start_date.month - 1) downloads.label = phone_no downloads.quota = plan_text.match(/(\d+)MB/)[1].to_i usagesummary = page.search('table.usagesummary') usagesummary.search('tr').each do |row| row_name = row.search('td[1]').text case row_name when 'Data - Mobile Internet' downloads.used = row.search('td[2]').text.match(/\d+\./)[0].to_i end end end end |