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;
}
Aggregations