Skip to content

attack/focus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple interface to the www.hostip.info API.

hostip.info is a “Community Geotarget IP Project” and provides a simple API to transform an “IP Address” into a location (including Country, City, and coordinates).

No API key or sign-up is required to use the service.

hostip.info does request that if a lot of databases lookups are being done that you download the entire database from them instead.

# focus 209.85.171.100
require 'rubygems'
require 'focus'

focus = Focus.new("209.85.171.100")

puts focus.location.coordinates
require 'focus'
@focus = Focus.new("209.85.171.100")
@focus.location.coordinates

Using caching is highly advised if possible. The ip_address to location conversion doesn’t normally change over time (if ever) so why continuously query it?

Assumption: caching is already enabled and working.

require 'focus'
ip_address = "209.85.171.100"
@focus = Rails.cache.fetch(Spotlight.key(ip_address), :expires_in => 1.weeks) do
  Focus.new(ip_address)
end
@focus.location.coordinates

Other then the code written by [me](github.com/attack) and the code created by [‘jeweler’](github.com/technicalpickles/jeweler/tree/master) for making and maintaining gems, there is strong influence from [jnunemaker](github.com/jnunemaker) and the gem google-weather.

Copyright © 2009 Mark G. See LICENSE for details.

About

For ip address to location translations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages