geoip2-0.4.1.0: Pure haskell interface to MaxMind GeoIP database
Safe HaskellNone
LanguageHaskell2010

Data.GeoIP2

Synopsis

Library description

A haskell library for reading MaxMind's GeoIP version 2 files. It supports both IPv4 and IPv6 addresses. When a match is found, it is parsed and a simplified structure is returned. If you want to access other fields than those that are exposed, it is internally possible.

The database is mmapped upon opening, all querying can be later performed purely without IO monad.

Opening the database

data GeoDB Source #

Handle for search operations

openGeoDB :: FilePath -> IO GeoDB Source #

Open database, mmap it into memory, parse header and return a handle for search operations This function may throw DecodeException

openGeoDBBS :: ByteString -> Either String GeoDB Source #

Open database from a bytestring

geoDbLanguages :: GeoDB -> [Text] Source #

Languages supported in database

geoDbType :: GeoDB -> Text Source #

String that indicates the structure of each data record associated with an IP address

geoDbDescription :: GeoDB -> Maybe Text Source #

Description of a database in english

geoDbAddrType :: GeoDB -> GeoIP Source #

Type of address (IPv4/IPv6) stored in a database

data GeoIP Source #

Address type stored in database

Constructors

GeoIPv6 
GeoIPv4 

Instances

Instances details
Eq GeoIP Source # 
Instance details

Defined in Data.GeoIP2

Methods

(==) :: GeoIP -> GeoIP -> Bool #

(/=) :: GeoIP -> GeoIP -> Bool #

Show GeoIP Source # 
Instance details

Defined in Data.GeoIP2

Methods

showsPrec :: Int -> GeoIP -> ShowS #

show :: GeoIP -> String #

showList :: [GeoIP] -> ShowS #

Querying the database

findGeoData Source #

Arguments

:: GeoDB

Db handle

-> Text

Language code (e.g. "en")

-> IP

IP address to search

-> Either String GeoResult

Result, if something is found

Search GeoIP database

data Location Source #

Location of the IP address

Instances

Instances details
Eq Location Source # 
Instance details

Defined in Data.GeoIP2

Show Location Source # 
Instance details

Defined in Data.GeoIP2

data AS Source #

Constructors

AS 

Instances

Instances details
Eq AS Source # 
Instance details

Defined in Data.GeoIP2

Methods

(==) :: AS -> AS -> Bool #

(/=) :: AS -> AS -> Bool #

Show AS Source # 
Instance details

Defined in Data.GeoIP2

Methods

showsPrec :: Int -> AS -> ShowS #

show :: AS -> String #

showList :: [AS] -> ShowS #

Internals

data GeoFieldT a Source #

Instances

Instances details
Show GeoField Source # 
Instance details

Defined in Data.GeoIP2.Fields

Serialize GeoField Source # 
Instance details

Defined in Data.GeoIP2.Fields

Eq a => Eq (GeoFieldT a) Source # 
Instance details

Defined in Data.GeoIP2.Fields

Methods

(==) :: GeoFieldT a -> GeoFieldT a -> Bool #

(/=) :: GeoFieldT a -> GeoFieldT a -> Bool #

Ord a => Ord (GeoFieldT a) Source # 
Instance details

Defined in Data.GeoIP2.Fields

rawGeoData :: GeoDB -> IP -> Either String GeoField Source #

Search GeoIP database and return complete unparsed data

Lenses

_DataMap :: forall a. Prism' (GeoFieldT a) (Map (GeoFieldT a) (GeoFieldT a)) Source #

key :: Text -> Traversal' GeoField GeoField Source #

Helper lens to access key in a DataMap

geoNum :: Num b => Fold GeoField b Source #

Helper lens to convert integer Word/Int to whatever number type is needed