lib/moocher/geo_ip.rb in moocher-0.1.1.5pre vs lib/moocher/geo_ip.rb in moocher-0.1.1.6pre

- old
+ new

@@ -1,22 +1,48 @@ +require 'httparty' +require 'ipaddress' + + module Moocher + module GeoIp + def geolocate_ip(ipaddress) + return "IP Address doesn't seem to be valid." if !(IPAddress.valid? ipaddress) + base_url = 'https://api.moocher.io/ip/' + response = HTTParty.get(base_url + ipaddress) + if response.success? + response.parsed_response + else + "Sorry No data was found." + end + end + + def geolocate_my_ip + base_url = 'https://api.moocher.io/ip' + response = HTTParty.get(base_url) + if response.success? + response.parsed_response + else + "Sorry No data was found." + end + end + end end