Class: Arin::RWS::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/arin-rws/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient



13
14
# File 'lib/arin-rws/client.rb', line 13

def initialize
end

Class Method Details

.init_httpObject



7
8
9
10
# File 'lib/arin-rws/client.rb', line 7

def self.init_http
  @@http = Net::HTTP.start(Arin::RWS::HOST, Arin::RWS::PORT)
  @@http.read_timeout=10
end

.query(resource) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/arin-rws/client.rb', line 16

def self.query(resource)
  tries = 5
  begin
    r = @@http.get("#{Arin::RWS::BASE_PATH}/#{resource}")
    result = JSON.parse(r.body)
    result
  rescue EOFError, Errno::ECONNRESET
    if (tries -= 1) > 0
      self.init_http
      retry
    end
  end
end

Instance Method Details

#find_asn(asn) ⇒ Object



40
41
42
# File 'lib/arin-rws/client.rb', line 40

def find_asn(asn)
  r = Client::query("asn/#{asn}.json")
end

#find_cidr(cidr) ⇒ Object



35
36
37
38
# File 'lib/arin-rws/client.rb', line 35

def find_cidr(cidr)
  r = Client::query("cidr/#{cidr}.json")
  Arin::RWS::Network.new(r)
end

#find_ip(ip) ⇒ Object



30
31
32
33
# File 'lib/arin-rws/client.rb', line 30

def find_ip(ip)
  r = Client::query("ip/#{ip}.json")
  Arin::RWS::Network.new(r)
end