Skip to content

Commit

Permalink
Add WebServiceProvider interface. Closes maxmind#359.
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwald committed Nov 21, 2023
1 parent 4863330 commit 964586c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CHANGELOG
4.2.0
------------------

* A `WebServiceProvider` interface has been added to facilitate mocking of
`WebServiceClient`. Requested by Evan Chrisinger. GitHub #359.
* The GeoIP2 IP Risk database has been discontinued. Methods and classes
related to it have been deprecated.
* The `fromString` static method on the `ConnectionType` enum now has
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/maxmind/geoip2/WebServiceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
* throws a {@link GeoIp2Exception}.
* </p>
*/
public class WebServiceClient implements GeoIp2Provider, Closeable {
public class WebServiceClient implements WebServiceProvider, Closeable {
private final String host;
private final List<String> locales;
private final String authHeader;
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/com/maxmind/geoip2/WebServiceProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.maxmind.geoip2;

import com.maxmind.geoip2.exception.GeoIp2Exception;
import com.maxmind.geoip2.model.CityResponse;
import com.maxmind.geoip2.model.CountryResponse;
import com.maxmind.geoip2.model.InsightsResponse;
import java.io.IOException;
import java.net.InetAddress;

public interface WebServiceProvider extends GeoIp2Provider {
/**
* @return A Country model for the requesting IP address
* @throws GeoIp2Exception if there is an error from the web service
* @throws IOException if an IO error happens during the request
*/
CountryResponse country() throws IOException, GeoIp2Exception;

/**
* @return A City model for the requesting IP address
* @throws GeoIp2Exception if there is an error from the web service
* @throws IOException if an IO error happens during the request
*/
CityResponse city() throws IOException, GeoIp2Exception;

/**
* @return An Insights model for the requesting IP address
* @throws GeoIp2Exception if there is an error from the web service
* @throws IOException if an IO error happens during the request
*/
InsightsResponse insights() throws IOException, GeoIp2Exception;

/**
* @param ipAddress IPv4 or IPv6 address to lookup.
* @return An Insight model for the requested IP address.
* @throws GeoIp2Exception if there is an error looking up the IP
* @throws IOException if there is an IO error
*/
InsightsResponse insights(InetAddress ipAddress) throws IOException,
GeoIp2Exception;
}

0 comments on commit 964586c

Please sign in to comment.