Search in sources :

Example 1 with InsightsResponse

use of com.maxmind.geoip2.model.InsightsResponse in project nutch by apache.

the class GeoIPDocumentCreator method createDocFromInsightsService.

public static NutchDocument createDocFromInsightsService(String serverIp, NutchDocument doc, WebServiceClient client) throws UnknownHostException, IOException, GeoIp2Exception {
    addIfNotNull(doc, "ip", serverIp);
    InsightsResponse response = client.insights(InetAddress.getByName(serverIp));
    // CityResponse response = client.city(InetAddress.getByName(serverIp));
    City city = response.getCity();
    // 'Minneapolis'
    addIfNotNull(doc, "cityName", city.getName());
    // 50
    addIfNotNull(doc, "cityConfidence", city.getConfidence());
    addIfNotNull(doc, "cityGeoNameId", city.getGeoNameId());
    Continent continent = response.getContinent();
    addIfNotNull(doc, "continentCode", continent.getCode());
    addIfNotNull(doc, "continentGeoNameId", continent.getGeoNameId());
    addIfNotNull(doc, "continentName", continent.getName());
    Country country = response.getCountry();
    // 'US'
    addIfNotNull(doc, "countryIsoCode", country.getIsoCode());
    // 'United States'
    addIfNotNull(doc, "countryName", country.getName());
    // 99
    addIfNotNull(doc, "countryConfidence", country.getConfidence());
    addIfNotNull(doc, "countryGeoName", country.getGeoNameId());
    Location location = response.getLocation();
    // 44.9733,
    addIfNotNull(doc, "latLon", location.getLatitude() + "," + location.getLongitude());
    // -93.2323
    // 3
    addIfNotNull(doc, "accRadius", location.getAccuracyRadius());
    // 'America/Chicago'
    addIfNotNull(doc, "timeZone", location.getTimeZone());
    addIfNotNull(doc, "metroCode", location.getMetroCode());
    Postal postal = response.getPostal();
    // '55455'
    addIfNotNull(doc, "postalCode", postal.getCode());
    // 40
    addIfNotNull(doc, "postalConfidence", postal.getConfidence());
    RepresentedCountry rCountry = response.getRepresentedCountry();
    addIfNotNull(doc, "countryType", rCountry.getType());
    Subdivision subdivision = response.getMostSpecificSubdivision();
    // 'Minnesota'
    addIfNotNull(doc, "subDivName", subdivision.getName());
    // 'MN'
    addIfNotNull(doc, "subDivIdoCode", subdivision.getIsoCode());
    // 90
    addIfNotNull(doc, "subDivConfidence", subdivision.getConfidence());
    addIfNotNull(doc, "subDivGeoNameId", subdivision.getGeoNameId());
    Traits traits = response.getTraits();
    addIfNotNull(doc, "autonSystemNum", traits.getAutonomousSystemNumber());
    addIfNotNull(doc, "autonSystemOrg", traits.getAutonomousSystemOrganization());
    addIfNotNull(doc, "domain", traits.getDomain());
    addIfNotNull(doc, "isp", traits.getIsp());
    addIfNotNull(doc, "org", traits.getOrganization());
    addIfNotNull(doc, "userType", traits.getUserType());
    // for better results, users should upgrade to
    // https://www.maxmind.com/en/solutions/geoip2-enterprise-product-suite/anonymous-ip-database
    addIfNotNull(doc, "isAnonProxy", String.valueOf(traits.isAnonymousProxy()));
    return doc;
}
Also used : Continent(com.maxmind.geoip2.record.Continent) RepresentedCountry(com.maxmind.geoip2.record.RepresentedCountry) RepresentedCountry(com.maxmind.geoip2.record.RepresentedCountry) Country(com.maxmind.geoip2.record.Country) InsightsResponse(com.maxmind.geoip2.model.InsightsResponse) City(com.maxmind.geoip2.record.City) Subdivision(com.maxmind.geoip2.record.Subdivision) Postal(com.maxmind.geoip2.record.Postal) Traits(com.maxmind.geoip2.record.Traits) Location(com.maxmind.geoip2.record.Location)

Aggregations

InsightsResponse (com.maxmind.geoip2.model.InsightsResponse)1 City (com.maxmind.geoip2.record.City)1 Continent (com.maxmind.geoip2.record.Continent)1 Country (com.maxmind.geoip2.record.Country)1 Location (com.maxmind.geoip2.record.Location)1 Postal (com.maxmind.geoip2.record.Postal)1 RepresentedCountry (com.maxmind.geoip2.record.RepresentedCountry)1 Subdivision (com.maxmind.geoip2.record.Subdivision)1 Traits (com.maxmind.geoip2.record.Traits)1