Neat Geo IP Documentation

This page consists of two subsections which are
Project structure
API documentation

Project structure

All the details about the project structure including source code explanation can be found here.

The project is developed on Spring Boot which is suitable for making stand-alone and agile development. In below you can see the structure of this project.

neatgeoip/
├── db
│   └── GeoLite2-City.mmdb
├── pom.xml
├── README.md
├── sh
│   └── openshift.sh
└── src
    └── main
       └── java
          └── com
              └── madadipouya
                  └── neatgeoip
                      ├── Application.java
                      ├── rest
                      │   ├── CountryRestController.java
                      │   └── HomeRestController.java
                      ├── pojo
                      │   └── Country.java
                      ├── service
                      │   ├── MaxMindService.java
                      │   └── MaxMindServiceImpl.java
                      └── util
                        └── loader
                          └── DatabaseFileLoader.java

As you can see the project structure is quite simple and straightforward.

db folder

db folder and its file used for looking up the country of the IP address. The database file belongs to MaxMind and is getting updated automatically monthly.

sh folder

sh folder contains openshift.sh file which is specific to the Openshift environment. Basically the script runs monthly to remove database file and restart the application, so the newly updated database will be downloaded. Basically, once the application started, it looks for the database file and if it cannot be found, it will download from MaxMind repository.

src folder

src folder contains the logic and source code of the service. In the following section the purpose of each source code is described in brief.

Application.java

Application.java starts Spring Boot application.

CountryRestController.java

CountryRestController.java refers to service at "/getCountry" which looks up for the country of the given IP address.

HomeRestController.java

HomeRestController.java refers to service at "/" which redirects user to Neat Geo IP Github page.

Country.java

Country.java is the content of the service which returns to the user. The content includes name (countryName), isoCode, name of the country in other languages (German, Russian, Portuguese [Brazil], Japanese, English, French, Chinese, and Spanish). The final parameter is error in which demonstrates occurred error in the API call.

MaxMindService.java

MaxMindService.java is an interface to get the country name of the IP.

MaxMindServiceImpl.java

MaxMindServiceImpl.java is the implementation of MaxMindService.java which utilizes MaxMind library as.

DatabaseFileLoader.java

DatabaseFileLoader.java contains the logic of loading the database file based on environment application running. If the database file exists in the local repository ("/db" folder), it uses the file, otherwise, it attempts to download the file from MaxMind server and unzip it as well. The logic of this class is optimized for Openshift and usual normal environment. Keep note that the database file is loaded into memory, if your instance has shortage of the memory, comment `line 57` in LoadDbFile.java.

API documentation

This section describes how to use and call the Neat Geo IP Rest API.

API description

Basically Neat Geo IP provides only one API to use. The API method is getCountry which requires ip parameter. The API returns a JSON string as response.

The API URL is located at :
http://neatgeoip-api.madadipouya.com/

To call the API use UTF-8. For instance,
http://neatgeoip-api.madadipouya.com/getCountry?ip=WW.XX.YY.ZZ

Consequently when you call the above API method, you get similar response to following :


{
    "name":"FooBar",
    "isoCode":"Foo",
    "names":
    {
        "de":"Foo",
        "ru":"Foo",
        "pt-BR":"Foo",
        "ja":"Foo",
        "en":"Foo",
        "fr":"Foo",
        "zh-CN":"Foo",
        "es":"Foo"
    },
    "errors":[]
}
    

Example

A sample API call of getCountry method for the IP "5.254.65.130".
http://neatgeoip-api.madadipouya.com/getCountry?ip=5.254.65.130

The response of the API call :


{
    "name":"Turkey",
    "isoCode":"TR",
    "names":
    {
        "de":"Türkei",
        "ru":"Турция",
        "pt-BR":"Turquia",
        "ja":"トルコ共和国",
        "en":"Turkey",
        "fr":"Turquie",
        "zh-CN":"土耳其",
        "es":"Turquía"
    },
    "errors":[]
}
  

If the location cannot be retrieved "Country not found!" error will be returned in JSON response.

{
   "name":"",
   "isoCode":"",
   "names":{},
   "errors":["Country not found!"]
}

This page is maintained by kasramp
Hosted on GitHub Pages — Theme by orderedlist