Created
April 19, 2017 13:22
-
-
Save t0nylombardi/e594a53899613719166b2798aee91bee to your computer and use it in GitHub Desktop.
pixel_fragment_4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/services/locations.rb | |
module Services | |
class Locations | |
require 'net/http' | |
def self.lookup(ip) | |
ip_address = ip | |
url = "http://freegeoip.net/json/#{ip_address}" | |
begin | |
HTTParty.get(url, timeout: 2) | |
rescue Timeout::Error | |
Rails.logger.warn("Could not post to #{url}: timeout") | |
{city: nil, region_name: nil} | |
rescue | |
Rails.logger.warn("Could not post to #{url}") | |
{city: nil, region_name: nil} | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment