Method: MaxMind::Enquiry#lookup

Defined in:
lib/max_mind/enquiry.rb

#lookupObject

 Run the check and return a hash of responses from the server.



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
48
49
50
# File 'lib/max_mind/enquiry.rb', line 21

def lookup
  MaxMind.logger.debug "Beginning lookups"
  MaxMind.logger.debug "('#{sendable_attributes.inspect}')"
  for endpoint in MaxMind.endpoints
    MaxMind.logger.debug "Attempting lookup on #{endpoint}"
    uri = URI.parse(endpoint)
    req = Net::HTTP::Post.new(uri.path)
    req.set_form_data(sendable_attributes)
    res = Net::HTTP.new(uri.host, uri.port)
    if uri.scheme == 'https'
      res.use_ssl = true
      res.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end
    
    begin
      case res = res.request(req)
      when Net::HTTPSuccess
        return Lookup.new(res.body)
      else
        MaxMind.logger.debug "Error on #{endpoint} (#{res.class.to_s})"
        next
      end
    rescue Timeout::Error
      MaxMind.logger.debug "Timed out connecting to #{endpoint}"
      next
    end
  end
  
  false
end