Skip to content

Instantly share code, notes, and snippets.

@t0nylombardi
Created April 19, 2017 13:22
Show Gist options
  • Save t0nylombardi/e594a53899613719166b2798aee91bee to your computer and use it in GitHub Desktop.
Save t0nylombardi/e594a53899613719166b2798aee91bee to your computer and use it in GitHub Desktop.
pixel_fragment_4
# 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