Created
September 3, 2012 15:02
-
-
Save peterhellberg/3609934 to your computer and use it in GitHub Desktop.
Simple GeoIP service class using freegeoip.net and the Ruby Standard Library
This file contains hidden or 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
| require 'net/http' | |
| require 'ostruct' | |
| require 'json' | |
| class GeoipService | |
| def initialize(http = nil) | |
| @http = http || Net::HTTP.new('freegeoip.net') | |
| end | |
| def call(host) | |
| OpenStruct.new JSON.parse @http.get("/json/#{host}").body | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Albeit with no error checking.