Class: IspUsage::Fetchers::AUInternode

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

Returns a new instance of AUInternode.



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

def initialize(options)
  super(options)
end

Instance Method Details

#fetch_usageObject



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
46
47
# File 'lib/ispusage/fetchers/internode.rb', line 13

def fetch_usage
  url = URI.parse("https://@customer-webtools-api.internode.on.net/api/v1.5/")
  req = Net::HTTP::Get.new(url.path)
  req.basic_auth @username, @password

  services_xml = ""
  req = Net::HTTP.new('customer-webtools-api.internode.on.net', 443)
  req.use_ssl = true
  req.verify_mode = OpenSSL::SSL::VERIFY_NONE
  req.start() {|http|
    req = Net::HTTP::Get.new('/api/v1.5/')
    req.basic_auth @username, @password
    response = http.request(req)
    services_xml = response.body
  }
  services_doc = Nokogiri::XML(services_xml)
  service_id = services_doc.search('/internode[1]/api[1]/services[1]/service[1]').text

  usage_xml = ""
  req = Net::HTTP.new('customer-webtools-api.internode.on.net', 443)
  req.use_ssl = true
  req.verify_mode = OpenSSL::SSL::VERIFY_NONE
  req.start() {|http|
    req = Net::HTTP::Get.new("/api/v1.5/#{service_id}/usage")
    req.basic_auth @username, @password
    response = http.request(req)
    usage_xml = response.body
  }

  usage_doc = Nokogiri::XML(usage_xml)
  self.month_end = Time.parse(usage_doc.search("//traffic/@rollover").text)
  used = usage_doc.search("/internode[1]/api[1]/traffic[1]").text.to_i / 1000000
  quota = usage_doc.search("/internode[1]/api[1]/traffic[1]/@quota").text.to_i / 1000000
  self.new_usage_period(:used => used, :quota => quota)
end