|
11 | 11 | import com.fasterxml.jackson.databind.DeserializationFeature; |
12 | 12 | import com.fasterxml.jackson.databind.InjectableValues; |
13 | 13 | import com.fasterxml.jackson.databind.ObjectMapper; |
14 | | -import com.google.api.client.http.GenericUrl; |
15 | | -import com.google.api.client.http.HttpHeaders; |
16 | | -import com.google.api.client.http.HttpRequest; |
17 | | -import com.google.api.client.http.HttpRequestFactory; |
18 | | -import com.google.api.client.http.HttpResponse; |
19 | | -import com.google.api.client.http.HttpResponseException; |
20 | | -import com.google.api.client.http.HttpTransport; |
| 14 | +import com.google.api.client.http.*; |
21 | 15 | import com.google.api.client.http.javanet.NetHttpTransport; |
22 | | -import com.maxmind.geoip2.exception.AddressNotFoundException; |
23 | | -import com.maxmind.geoip2.exception.AuthenticationException; |
24 | | -import com.maxmind.geoip2.exception.GeoIp2Exception; |
25 | | -import com.maxmind.geoip2.exception.HttpException; |
26 | | -import com.maxmind.geoip2.exception.InvalidRequestException; |
27 | | -import com.maxmind.geoip2.exception.OutOfQueriesException; |
28 | | -import com.maxmind.geoip2.model.CityIspOrgResponse; |
29 | | -import com.maxmind.geoip2.model.CityResponse; |
30 | | -import com.maxmind.geoip2.model.CountryResponse; |
31 | | -import com.maxmind.geoip2.model.OmniResponse; |
| 16 | +import com.maxmind.geoip2.exception.*; |
| 17 | +import com.maxmind.geoip2.model.*; |
32 | 18 |
|
33 | 19 | /** |
34 | 20 | * <p> |
35 | | - * This class provides a client API for all the GeoIP2 web service's end points. |
36 | | - * The end points are Country, City, City/ISP/Org, and Omni. Each end point |
| 21 | + * This class provides a client API for all the GeoIP2 Precision web service end points. |
| 22 | + * The end points are Country and Insights. Each end point |
37 | 23 | * returns a different set of data about an IP address, with Country returning |
38 | | - * the least data and Omni the most. |
| 24 | + * the least data and Insights the most. |
39 | 25 | * </p> |
40 | 26 | * |
41 | 27 | * <p> |
@@ -241,33 +227,71 @@ public CityResponse city(InetAddress ipAddress) throws IOException, |
241 | 227 | * if there is an error from the web service |
242 | 228 | * @throws IOException |
243 | 229 | * if an IO error happens during the request |
| 230 | + * |
| 231 | + * @deprecated As of 0.8.0, use {@link #city()} instead. |
244 | 232 | */ |
| 233 | +@SuppressWarnings("deprecation") |
| 234 | +@Deprecated |
245 | 235 | public CityIspOrgResponse cityIspOrg() throws IOException, GeoIp2Exception { |
246 | 236 | return this.cityIspOrg(null); |
247 | 237 | } |
248 | 238 |
|
| 239 | + @SuppressWarnings("deprecation") |
| 240 | + @Deprecated |
249 | 241 | @Override |
250 | 242 | public CityIspOrgResponse cityIspOrg(InetAddress ipAddress) |
251 | 243 | throws IOException, GeoIp2Exception { |
252 | | - return this.responseFor("city_isp_org", ipAddress, |
| 244 | + return this.responseFor("city", ipAddress, |
253 | 245 | CityIspOrgResponse.class); |
254 | 246 | } |
255 | 247 |
|
| 248 | + /** |
| 249 | + * @return An Insights model for the requesting IP address |
| 250 | + * @throws GeoIp2Exception |
| 251 | + * if there is an error from the web service |
| 252 | + * @throws IOException |
| 253 | + * if an IO error happens during the request |
| 254 | + */ |
| 255 | + public InsightsResponse insights() throws IOException, GeoIp2Exception { |
| 256 | + return this.insights(null); |
| 257 | + } |
| 258 | + |
| 259 | + |
| 260 | + /** |
| 261 | + * @param ipAddress |
| 262 | + * IPv4 or IPv6 address to lookup. |
| 263 | + * @return A Insight model for the requested IP address. |
| 264 | + * @throws GeoIp2Exception |
| 265 | + * if there is an error looking up the IP |
| 266 | + * @throws IOException |
| 267 | + * if there is an IO error |
| 268 | + */ |
| 269 | + public InsightsResponse insights(InetAddress ipAddress) throws IOException, |
| 270 | + GeoIp2Exception { |
| 271 | + return this.responseFor("insights", ipAddress, InsightsResponse.class); |
| 272 | + } |
| 273 | + |
256 | 274 | /** |
257 | 275 | * @return An Omni model for the requesting IP address |
258 | 276 | * @throws GeoIp2Exception |
259 | 277 | * if there is an error from the web service |
260 | 278 | * @throws IOException |
261 | 279 | * if an IO error happens during the request |
| 280 | + * |
| 281 | + * @deprecated As of 0.8.0, use {@link #insights()} instead. |
262 | 282 | */ |
| 283 | + @SuppressWarnings("deprecation") |
| 284 | + @Deprecated |
263 | 285 | public OmniResponse omni() throws IOException, GeoIp2Exception { |
264 | 286 | return this.omni(null); |
265 | 287 | } |
266 | 288 |
|
| 289 | + @SuppressWarnings("deprecation") |
| 290 | + @Deprecated |
267 | 291 | @Override |
268 | 292 | public OmniResponse omni(InetAddress ipAddress) throws IOException, |
269 | 293 | GeoIp2Exception { |
270 | | - return this.responseFor("omni", ipAddress, OmniResponse.class); |
| 294 | + return this.responseFor("insights", ipAddress, OmniResponse.class); |
271 | 295 | } |
272 | 296 |
|
273 | 297 | private <T> T responseFor(String path, InetAddress ipAddress, Class<T> cls) |
@@ -408,7 +432,7 @@ private static void handleErrorWithJsonBody(Map<String, String> content, |
408 | 432 | } |
409 | 433 |
|
410 | 434 | private GenericUrl createUri(String path, InetAddress ipAddress) { |
411 | | - return new GenericUrl("https://" + this.host + "/geoip/v2.0/" + path |
| 435 | + return new GenericUrl("https://" + this.host + "/geoip/v2.1/" + path |
412 | 436 | + "/" + (ipAddress == null ? "me" : ipAddress.getHostAddress())); |
413 | 437 |
|
414 | 438 | } |
|
0 commit comments