Class: IP2LocationIORuby::Api::IPGeolocation
- Inherits:
-
Object
- Object
- IP2LocationIORuby::Api::IPGeolocation
- Defined in:
- lib/ip2location_io_ruby/api/ipgeolocation.rb
Class Method Summary collapse
-
.lookup(ip, language = '') ⇒ Object
Lookup given IP address for an enriched data set.
Class Method Details
.lookup(ip, language = '') ⇒ Object
Lookup given IP address for an enriched data set.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ip2location_io_ruby/api/ipgeolocation.rb', line 12 def self.lookup(ip, language = '') uri = URI.parse("https://api.ip2location.io/?key=" + IP2LocationIORuby::Configuration.api_key + "&format=json&ip=" + ip + "&lang=" + language + "&source=sdk-ruby-iplio&source_version=" + IP2LocationIORuby::VERSION) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) response = http.request(request) if response == nil raise Exception.new "IPGeolocation lookup error." elsif JSON[response.body]['error'] raise Exception.new JSON[response.body]['error']['error_message'] else return response end end |