Class: IspUsage::Fetchers::AUIinet

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

Instance Attribute Summary collapse

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) ⇒ AUIinet

Returns a new instance of AUIinet.



9
10
11
# File 'lib/ispusage/fetchers/iinet.rb', line 9

def initialize(options)
  super(options)
end

Instance Attribute Details

#quotaObject (readonly)

Returns the value of attribute quota.



8
9
10
# File 'lib/ispusage/fetchers/iinet.rb', line 8

def quota
  @quota
end

#usedObject (readonly)

Returns the value of attribute used.



8
9
10
# File 'lib/ispusage/fetchers/iinet.rb', line 8

def used
  @used
end

Instance Method Details

#fetch_usageObject



13
14
15
16
17
18
19
20
# File 'lib/ispusage/fetchers/iinet.rb', line 13

def fetch_usage
  xml = open("https://toolbox.iinet.net.au/cgi-bin/new/volume_usage_xml.cgi?action=login&username=#{@username}&password=#{@password}")
  doc = Nokogiri::XML(xml)
  used = doc.search("/ii_feed[1]/volume_usage[1]/expected_traffic_types[1]/type[1]/@used").text.to_i / 998315 #best I can figure iinet uses base 2 and base 10 bytes
  quota = doc.search("/ii_feed[1]/volume_usage[1]/expected_traffic_types[1]/type[1]/quota_allocation[1]").text.to_i
  self.month_end = Time.local(Time.now.year,Time.now.month, doc.search("//anniversary").text.to_i)
  self.new_usage_period(:used => used, :quota => quota)
end