Class: IpResolvers::IpInfoIo

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsign/ip_resolvers/ip_info_io.rb

Instance Method Summary collapse

Constructor Details

#initialize(resolver) ⇒ IpInfoIo

Returns a new instance of IpInfoIo.


4
5
6
# File 'lib/dnsign/ip_resolvers/ip_info_io.rb', line 4

def initialize(resolver)
  @resolver = resolver
end

Instance Method Details

#fetchObject


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dnsign/ip_resolvers/ip_info_io.rb', line 8

def fetch
  uri = URI 'http://ipinfo.io/json'

  res = ::Net::HTTP.get_response uri

  if /2../.match res.code
    data = JSON.parse res.body
    data.fetch 'ip'
  else
    raise Error::InvalidResponseFromIpResolverService "Invalid response for #{self.class} with code: #{res.code}; body: #{res.body}"
  end

end