Sha256: 00e773c74669fbbc5a874c1ad6012cf5b1322bc1aa2340847d6be20f6d33477c

Contents?: true

Size: 570 Bytes

Versions: 8

Compression:

Stored size: 570 Bytes

Contents

require 'httparty'
require 'ipaddress'


module Moocher
  module GeoIp
    def geolocate_ip(ipaddress=nil)
      base_url = 'https://api.moocher.io/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

8 entries across 8 versions & 1 rubygems

Version Path
moocher-0.3.2 lib/moocher/geo_ip.rb
moocher-0.2.2 lib/moocher/geo_ip.rb
moocher-0.2.1.3 lib/moocher/geo_ip.rb
moocher-0.2.1.2 lib/moocher/geo_ip.rb
moocher-0.2.1.1 lib/moocher/geo_ip.rb
moocher-0.2.1 lib/moocher/geo_ip.rb
moocher-0.2 lib/moocher/geo_ip.rb
moocher-0.1.1.7pre lib/moocher/geo_ip.rb