Sha256: a1280226d53be08bbcfb8ef2330bd5de380690183fb27fb681f9a9feffdc667f

Contents?: true

Size: 571 Bytes

Versions: 1

Compression:

Stored size: 571 Bytes

Contents

require 'httparty'
require 'ipaddress'


module Apility
  module GeoIp
    def geolocate_ip(ipaddress=nil)
      base_url = 'https://api.apility.net/ip/'
      if ipaddress
          return "IP Address doesn't seem to be valid." if !(IPAddress.valid? ipaddress)
          response = HTTParty.get(base_url + ipaddress)
          response.success? ? response.parsed_response : "Sorry No data was found."
        else
          response = HTTParty.get(base_url)
          response.success? ? response.parsed_response : "Sorry No data was found."
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
apility-1.0 lib/apility/geo_ip.rb