Class: GeoIP::City

Inherits:
Object
  • Object
show all
Defined in:
ext/geoip/geoip.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(*args) ⇒ Object

The first argument is the filename of the GeoIPCity.dat file load_option = :standard, :index, or :memory. default :memory check_cache = true or false. default false

filesystem: read database from filesystem, uses least memory.

index: the most frequently accessed index portion of the database,

resulting in faster lookups than :filesystem, but less memory usage than
:memory.

memory: load database into memory, faster performance but uses more

memory.


184
185
186
187
# File 'ext/geoip/geoip.c', line 184

static VALUE rb_geoip_city_new(int argc, VALUE *argv, VALUE self)
{
  return rb_geoip_database_new(mGeoIP_City, argc, argv, self);
}

Instance Method Details

#look_up(addr) ⇒ Object

Pass this function an IP address as a string, it will return a hash containing all the information that the database knows about the IP

db.look_up('24.24.24.24')
=> {:city=>"Ithaca", :latitude=>42.4277992248535,
    :country_code=>"US", :longitude=>-76.4981994628906,
    :country_code3=>"USA", :dma_code=>555,
    :country_name=>"United States", :area_code=>607,
    :region=>"NY"}


198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'ext/geoip/geoip.c', line 198

VALUE rb_geoip_city_look_up(VALUE self, VALUE addr) {
  GeoIP *gi;
  GeoIPRecord *record = NULL;
  VALUE hash = Qnil;

  Check_Type(addr, T_STRING);
  Data_Get_Struct(self, GeoIP, gi);
  if(record = GeoIP_record_by_addr(gi, StringValuePtr(addr))) {
    hash =  rb_city_record_to_hash(record);
    GeoIPRecord_delete(record);
  }
  return hash;
}