Skip to content

Commit

Permalink
Fix build warnings (#280)
Browse files Browse the repository at this point in the history
* fix warning from error prone during build

* docstring

* fix typo in the docstirng
  • Loading branch information
jchen293 authored Jul 31, 2023
1 parent a74c59a commit caf858b
Show file tree
Hide file tree
Showing 26 changed files with 89 additions and 87 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,22 @@ Users can subscribe to HTTP requests and responses via the `RequestHook` and `Re
EasyPostClient client = new EasyPostClient(System.getenv("EASYPOST_API_KEY"));

// For request hook custom function, make sure you have RequestHookResponses in the parameter
public static Object requestHookFunction(RequestHookResponses datas) {
// Pass your code here, the information about the request/response is available within the datas parameter.
public static Object requestHookFunction(RequestHookResponses data) {
// Pass your code here, the information about the request/response is available within the data parameter.
return true;
}

client.subscribeToRequestHook(requestHookFunction); // subscribe to request hook by passing your custom function
client.unsubscribeToRequestHook(requestHookFunction); // unsubscribe from request hook

// For response hook custom function, make sure you have ResponseHookResponses in the parameter
public static Object responseHookFunction(ResponseHookResponses datas) {
// Pass your code here, the information about the request/response is available within the datas parameter.
public static Object responseHookFunction(ResponseHookResponses data) {
// Pass your code here, the information about the request/response is available within the data parameter.
return true;
}

client.subscribeToRequestHook(responseHookFunction); // subscribe to response hook by passing your custom function
client.unsubscribeToRequestHook(responseHookFunction); // unsubscribe from response hook
client.subscribeToResponseHook(responseHookFunction); // subscribe to response hook by passing your custom function
client.unsubscribeToResponseHook(responseHookFunction); // unsubscribe from response hook
```

## Documentation
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/easypost/exception/APIException.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public String getCode() {
*
* @return message the message of the error object
*/
@Override
public String getMessage() {
return message;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/easypost/hooks/RequestHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void removeEventHandler(Function<RequestHookResponses, Object> handler) {
*/
public void executeEventHandler(RequestHookResponses datas) {
for (Function<RequestHookResponses, Object> eventHandler : eventHandlers) {
@SuppressWarnings("unused")
Object result = eventHandler.apply(datas);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/easypost/hooks/ResponseHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void removeEventHandler(Function<ResponseHookResponses, Object> handler)
*/
public void executeEventHandler(ResponseHookResponses datas) {
for (Function<ResponseHookResponses, Object> eventHandler : eventHandlers) {
@SuppressWarnings("unused")
Object result = eventHandler.apply(datas);
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/com/easypost/http/Requestor.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.net.URL;
import java.net.URLEncoder;
import java.net.URLStreamHandler;
import java.nio.charset.Charset;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -78,7 +79,7 @@ private static String urlEncodePair(final String key, final String value) throws
*
* @param apiKey API of this HTTP request.
* @return HTTP header
* @throws MissingParameterError
* @throws MissingParameterError When the request fails.
*/
private static Map<String, String> generateHeaders(String apiKey) throws MissingParameterError {
Map<String, String> headers = new HashMap<String, String>();
Expand Down Expand Up @@ -159,7 +160,7 @@ private static javax.net.ssl.HttpsURLConnection createEasyPostConnection(final S
* @param conn EasyPost HttpsURLConnection
* @param body Input body
* @return HttpsURLConnection
* @throws IOException
* @throws IOException When the request fails.
*/
private static javax.net.ssl.HttpsURLConnection writeBody(final javax.net.ssl.HttpsURLConnection conn,
final JsonObject body) throws IOException {
Expand Down Expand Up @@ -276,7 +277,7 @@ private static JsonObject createBody(final Map<String, Object> params) {
*
* @param params Map of parameter for the HTTP request body.
* @return Query string of the Map object.
* @throws UnsupportedEncodingException
* @throws UnsupportedEncodingException When the request fails.
*/
private static String createQuery(final Map<String, Object> params) throws UnsupportedEncodingException {
Map<String, String> flatParams = flattenParams(params);
Expand Down Expand Up @@ -329,7 +330,7 @@ private static Map<String, String> flattenParams(final Map<String, Object> param
*
* @param responseStream The InputStream from the response body.
* @return InputStream in string value.
* @throws IOException
* @throws IOException When the request fails.
*/
private static String getResponseBody(final InputStream responseStream) throws IOException {
if (responseStream.available() == 0) {
Expand Down Expand Up @@ -583,8 +584,7 @@ private static <T> T httpRequest(final RequestMethod method, final String url, f
}
Instant requestTimestamp = Instant.now();
UUID requestUuid = UUID.randomUUID();
Map<String, String> headers = new HashMap<String, String>();
headers = generateHeaders(client.getApiKey());
Map<String, String> headers = generateHeaders(client.getApiKey());

RequestHookResponses requestResponse = new RequestHookResponses(headers, method.toString(), url, body,
requestTimestamp.toString(), requestUuid.toString());
Expand Down Expand Up @@ -744,7 +744,8 @@ private static EasyPostResponse makeAppEngineRequest(final RequestMethod method,

if ((method == RequestMethod.POST || method == RequestMethod.PUT) && body != null) {
String bodyString = body.toString();
requestClass.getDeclaredMethod("setPayload", byte[].class).invoke(request, bodyString.getBytes());
requestClass.getDeclaredMethod("setPayload", byte[].class)
.invoke(request, bodyString.getBytes(Charset.defaultCharset()));
}

for (Map.Entry<String, String> header : generateHeaders(client.getApiKey()).entrySet()) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/easypost/model/CarrierMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class CarrierMetadata extends EasyPostResource {
private List<Carrier> carriers;

@Getter
public class Carrier {
public static class Carrier {
private String name;
private String humanReadable;
private List<PredefinedPackage> predefinedPackages;
Expand All @@ -19,7 +19,7 @@ public class Carrier {
}

@Getter
public class PredefinedPackage {
public static class PredefinedPackage {
private String carrier;
private String description;
private List<String> dimensions;
Expand All @@ -29,7 +29,7 @@ public class PredefinedPackage {
}

@Getter
public class ServiceLevels {
public static class ServiceLevels {
private String carrier;
private String description;
private List<String> dimensions;
Expand All @@ -39,7 +39,7 @@ public class ServiceLevels {
}

@Getter
public class ShipmentOption {
public static class ShipmentOption {
private String carrier;
private boolean deprecated;
private String description;
Expand All @@ -49,7 +49,7 @@ public class ShipmentOption {
}

@Getter
public class SupportedFeatures {
public static class SupportedFeatures {
private String carrier;
private String description;
private String name;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/easypost/model/Error.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Getter;

@Getter
@SuppressWarnings("JavaLangClash")
public final class Error {
private String message;
private String code;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/easypost/service/AddressService.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public AddressCollection getNextPage(AddressCollection collection) throws EndOfP
*/
public AddressCollection getNextPage(AddressCollection collection, Integer pageSize) throws EndOfPaginationError {
return collection.getNextPage(new Function<Map<String, Object>, AddressCollection>() {
@SneakyThrows
@Override @SneakyThrows
public AddressCollection apply(Map<String, Object> parameters) {
return all(parameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class BetaCarrierMetadataService {
* Retrieves all carrier metadata.
*
* @return CarrierMetadata object
* @throws EasyPostException
* @throws EasyPostException When the request fails.
* @deprecated Use carrierMetadata.retrieve instead
*/
public CarrierMetadata retrieveCarrierMetadata() throws EasyPostException {
Expand All @@ -36,7 +36,7 @@ public CarrierMetadata retrieveCarrierMetadata() throws EasyPostException {
*
* @param carriers The list of carriers in string.
* @return CarrierMetadata object
* @throws EasyPostException
* @throws EasyPostException When the request fails.
* @deprecated Use carrierMetadata.retrieve instead
*/
public CarrierMetadata retrieveCarrierMetadata(List<String> carriers) throws EasyPostException {
Expand All @@ -49,7 +49,7 @@ public CarrierMetadata retrieveCarrierMetadata(List<String> carriers) throws Eas
* @param carriers The list of carriers in string.
* @param types The list of types in string.
* @return CarrierMetadata object
* @throws EasyPostException
* @throws EasyPostException When the request fails.
* @deprecated Use carrierMetadata.retrieve instead
*/
public CarrierMetadata retrieveCarrierMetadata(List<String> carriers, List<String> types) throws EasyPostException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BetaReferralCustomerService {
* @param stripeCustomerId ID of the Stripe account.
* @param paymentMethodReference Reference of Stripe payment method.
* @return PaymentMethodObject object.
* @throws EasyPostException
* @throws EasyPostException When the request fails.
*/
public PaymentMethodObject addPaymentMethod(String stripeCustomerId, String paymentMethodReference)
throws EasyPostException {
Expand All @@ -41,7 +41,7 @@ public PaymentMethodObject addPaymentMethod(String stripeCustomerId, String paym
* @param paymentMethodReference Reference of Stripe payment method.
* @param primaryOrSecondary Primary or secondary of this payment method.
* @return PaymentMethodObject object.
* @throws EasyPostException
* @throws EasyPostException When the request fails.
*/
public PaymentMethodObject addPaymentMethod(String stripeCustomerId, String paymentMethodReference,
PaymentMethod.Priority primaryOrSecondary) throws EasyPostException {
Expand All @@ -64,7 +64,7 @@ public PaymentMethodObject addPaymentMethod(String stripeCustomerId, String paym
*
* @param refundAmount Amount to be refunded by cents.
* @return BetaPaymentRefund object.
* @throws EasyPostException
* @throws EasyPostException When the request fails.
*/
public BetaPaymentRefund refundByAmount(int refundAmount) throws EasyPostException {
HashMap<String, Object> params = new HashMap<>();
Expand All @@ -81,7 +81,7 @@ public BetaPaymentRefund refundByAmount(int refundAmount) throws EasyPostExcepti
*
* @param paymentLogId ID of the payment log.
* @return BetaPaymentRefund object.
* @throws EasyPostException
* @throws EasyPostException When the request fails.
*/
public BetaPaymentRefund refundByPaymentLog(String paymentLogId) throws EasyPostException {
HashMap<String, Object> params = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CarrierMetadataService {
* Retrieves all carrier metadata.
*
* @return CarrierMetadata object
* @throws EasyPostException
* @throws EasyPostException When the request fails.
*/
public CarrierMetadata retrieve() throws EasyPostException {
return retrieve(null);
Expand All @@ -35,7 +35,7 @@ public CarrierMetadata retrieve() throws EasyPostException {
*
* @param carriers The list of carriers in string.
* @return CarrierMetadata object
* @throws EasyPostException
* @throws EasyPostException When the request fails.
*/
public CarrierMetadata retrieve(List<String> carriers) throws EasyPostException {
return retrieve(carriers, null);
Expand All @@ -47,7 +47,7 @@ public CarrierMetadata retrieve(List<String> carriers) throws EasyPostException
* @param carriers The list of carriers in string.
* @param types The list of types in string.
* @return CarrierMetadata object
* @throws EasyPostException
* @throws EasyPostException When the request fails.
*/
public CarrierMetadata retrieve(List<String> carriers, List<String> types) throws EasyPostException {
HashMap<String, Object> params = new HashMap<>();
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/easypost/service/EasyPostClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class EasyPostClient {
* EasyPostClient constructor.
*
* @param apiKey API key for API calls.
* @throws MissingParameterError
* @throws MissingParameterError When the request fails.
*/
public EasyPostClient(String apiKey) throws MissingParameterError {
this(apiKey, Constants.Http.DEFAULT_CONNECT_TIMEOUT_MILLISECONDS);
Expand All @@ -65,7 +65,7 @@ public EasyPostClient(String apiKey) throws MissingParameterError {
*
* @param apiKey API key for API calls.
* @param apiBase API base for API calls.
* @throws MissingParameterError
* @throws MissingParameterError When the request fails.
*/
public EasyPostClient(String apiKey, String apiBase) throws MissingParameterError {
this(apiKey, Constants.Http.DEFAULT_CONNECT_TIMEOUT_MILLISECONDS,
Expand All @@ -77,7 +77,7 @@ public EasyPostClient(String apiKey, String apiBase) throws MissingParameterErro
*
* @param apiKey API key for API calls.
* @param connectTimeoutMilliseconds Timeout for connection.
* @throws MissingParameterError
* @throws MissingParameterError When the request fails.
*/
public EasyPostClient(String apiKey, int connectTimeoutMilliseconds) throws MissingParameterError {
this(apiKey, connectTimeoutMilliseconds, Constants.Http.API_BASE);
Expand All @@ -89,7 +89,7 @@ public EasyPostClient(String apiKey, int connectTimeoutMilliseconds) throws Miss
* @param apiKey API key for API calls.
* @param connectTimeoutMilliseconds Timeout for connection.
* @param apiBase API base for API calls.
* @throws MissingParameterError
* @throws MissingParameterError When the request fails.
*/
public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, String apiBase) throws MissingParameterError {
this(apiKey, connectTimeoutMilliseconds, Constants.Http.DEFAULT_READ_TIMEOUT_MILLISECONDS, apiBase);
Expand All @@ -101,7 +101,7 @@ public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, String apiB
* @param apiKey API key for API calls.
* @param connectTimeoutMilliseconds Timeout for connection.
* @param readTimeoutMilliseconds Timeout for read.
* @throws MissingParameterError
* @throws MissingParameterError When the request fails.
*/
public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, int readTimeoutMilliseconds)
throws MissingParameterError {
Expand All @@ -115,7 +115,7 @@ public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, int readTim
* @param connectTimeoutMilliseconds Timeout for connection.
* @param readTimeoutMilliseconds Timeout for read.
* @param apiBase API base for API calls.
* @throws MissingParameterError
* @throws MissingParameterError When the request fails.
*/
public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, int readTimeoutMilliseconds, String apiBase)
throws MissingParameterError {
Expand Down Expand Up @@ -159,31 +159,31 @@ public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, int readTim

/**
* Subscribes to a request hook from the given function.
* @param function
* @param function The function to be subscribed to the request hook
*/
public void subscribeToRequestHook(Function<RequestHookResponses, Object> function) {
this.requestHooks.addEventHandler(function);
}

/**
* Unsubscribes to a request hook from the given function.
* @param function
* @param function The function to be unsubscribed from the request hook
*/
public void unsubscribeFromRequestHook(Function<RequestHookResponses, Object> function) {
this.requestHooks.removeEventHandler(function);
}

/**
* Subscribes to a response hook from the given function.
* @param function
* @param function The function to be subscribed to the response hook
*/
public void subscribeToResponseHook(Function<ResponseHookResponses, Object> function) {
this.responseHooks.addEventHandler(function);
}

/**
* Unubscribes to a response hook from the given function.
* @param function
* @param function The function to be unsubscribed from the response hook
*/
public void unsubscribeFromResponseHook(Function<ResponseHookResponses, Object> function) {
this.responseHooks.removeEventHandler(function);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/easypost/service/EventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public EventCollection getNextPage(EventCollection collection) throws EndOfPagin
*/
public EventCollection getNextPage(EventCollection collection, Integer pageSize) throws EndOfPaginationError {
return collection.getNextPage(new Function<Map<String, Object>, EventCollection>() {
@SneakyThrows
@Override @SneakyThrows
public EventCollection apply(Map<String, Object> parameters) {
return all(parameters);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/easypost/service/InsuranceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public InsuranceCollection getNextPage(InsuranceCollection collection) throws En
public InsuranceCollection getNextPage(
InsuranceCollection collection, Integer pageSize) throws EndOfPaginationError {
return collection.getNextPage(new Function<Map<String, Object>, InsuranceCollection>() {
@SneakyThrows
@Override @SneakyThrows
public InsuranceCollection apply(Map<String, Object> parameters) {
return all(parameters);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/easypost/service/PickupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public PickupCollection getNextPage(PickupCollection collection) throws EndOfPag
*/
public PickupCollection getNextPage(PickupCollection collection, Integer pageSize) throws EndOfPaginationError {
return collection.getNextPage(new Function<Map<String, Object>, PickupCollection>() {
@SneakyThrows
@Override @SneakyThrows
public PickupCollection apply(Map<String, Object> parameters) {
return all(parameters);
}
Expand Down
Loading

0 comments on commit caf858b

Please sign in to comment.