Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Claims service #320

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# CHANGELOG

## v7.3.0 (2024-07-15)
## Next Release

- Add new `Claim` service for filing claims on EasyPost shipments and insurances

## v7.3.0 (2024-07-16)

- Adds new `shipment.recommendShipDate`, `smartrate.recommendShipDate`, and `smartrate.estimateDeliveryDate` functions
- Routes `UpsAccount`, `UpsMailInnovationsAccount`, and `UpsSurepostAccount` create/update requests to the new `/ups_oauth_registrations` endpoint
Expand Down
2 changes: 1 addition & 1 deletion examples
Submodule examples updated 32 files
+27 −0 official/docs/csharp/current/smartrate/retrieve-recommend-ship-date.cs
+30 −0 official/docs/csharp/current/smartrate/retrieve-standalone-smartrate-deliver-by.cs
+30 −0 official/docs/csharp/current/smartrate/retrieve-standalone-smartrate-deliver-on.cs
+2 −0 official/docs/curl/current/smartrate/retrieve-recommend-ship-date.sh
+9 −0 official/docs/curl/current/smartrate/retrieve-standalone-smartrate-deliver-by.sh
+9 −0 official/docs/curl/current/smartrate/retrieve-standalone-smartrate-deliver-on.sh
+9 −0 official/docs/golang/current/carrier-accounts/create.go
+8 −0 official/docs/golang/current/carrier-accounts/update.go
+15 −0 official/docs/golang/current/smartrate/retrieve-recommend-ship-date.go
+22 −0 official/docs/golang/current/smartrate/retrieve-standalone-smartrate-deliver-by.go
+22 −0 official/docs/golang/current/smartrate/retrieve-standalone-smartrate-deliver-on.go
+20 −0 official/docs/java/current/smartrate/retrieve-recommend-ship-date.java
+25 −0 official/docs/java/current/smartrate/retrieve-standalone-smartrate-deliver-by.java
+25 −0 official/docs/java/current/smartrate/retrieve-standalone-smartrate-deliver-on.java
+9 −0 official/docs/node/current/smartrate/retrieve-recommend-ship-date.js
+16 −0 official/docs/node/current/smartrate/retrieve-standalone-smartrate-deliver-by.js
+16 −0 official/docs/node/current/smartrate/retrieve-standalone-smartrate-deliver-on.js
+7 −0 official/docs/php/current/smartrate/retrieve-recommend-ship-date.php
+14 −0 official/docs/php/current/smartrate/retrieve-standalone-smartrate-deliver-by.php
+14 −0 official/docs/php/current/smartrate/retrieve-standalone-smartrate-deliver-on.php
+10 −0 official/docs/python/current/smartrate/retrieve-recommend-ship-date.py
+14 −0 official/docs/python/current/smartrate/retrieve-standalone-smartrate-deliver-by.py
+14 −0 official/docs/python/current/smartrate/retrieve-standalone-smartrate-deliver-on.py
+194 −0 official/docs/responses/smartrate/smartrate-retrieve-recommend-ship-date.json
+89 −0 official/docs/responses/smartrate/standalone-smartrate-retrieve-standalone-smartrate-deliver-by.json
+99 −0 official/docs/responses/smartrate/standalone-smartrate-retrieve-standalone-smartrate-deliver-on.json
+10 −0 official/docs/ruby/current/smartrate/retrieve-recommend-ship-date.rb
+14 −0 official/docs/ruby/current/smartrate/retrieve-standalone-smartrate-deliver-by.rb
+14 −0 official/docs/ruby/current/smartrate/retrieve-standalone-smartrate-deliver-on.rb
+10 −0 official/fixtures/client-library-fixtures.json
+26 −31 style_guides/node/.eslintrc
+0 −4 style_guides/node/.prettierignore
5 changes: 4 additions & 1 deletion src/main/java/com/easypost/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.easypost.http.HashMapSerializer;
import com.easypost.model.AddressVerification;
import com.easypost.model.AddressVerificationDeserializer;
import com.easypost.model.DateDeserializer;
import com.easypost.model.Error;
import com.easypost.model.ErrorDeserializer;
import com.easypost.model.SmartrateCollection;
Expand All @@ -16,6 +17,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -83,7 +85,8 @@ public abstract static class Http {
.registerTypeAdapter(Error.class, new ErrorDeserializer())
.registerTypeAdapter(AddressVerification.class, new AddressVerificationDeserializer())
.registerTypeAdapter(StatelessRate[].class, new StatelessRateDeserializer())
.registerTypeAdapter(Webhook[].class, new WebhookDeserializer()).create();
.registerTypeAdapter(Webhook[].class, new WebhookDeserializer())
.registerTypeAdapter(Date.class, new DateDeserializer()).create();
public static final Gson PRETTY_PRINT_GSON = new GsonBuilder().setPrettyPrinting().serializeNulls()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/easypost/model/Claim.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.easypost.model;

import java.util.Date;
import java.util.List;
import lombok.Getter;

@Getter
public class Claim extends EasyPostResource {
private Date statusTimestamp;
private List<ClaimHistoryEntry> history;
private String approvedAmount;
private String checkDeliveryAddress;
private String contactEmail;
private String description;
private String insuranceAmount;
private String insuranceId;
private String paymentMethod;
private String recipientName;
private String requestedAmount;
private String salvageValue;
private String shipmentId;
private String status;
private String statusDetail;
private String trackingCode;
private String type;
}
27 changes: 27 additions & 0 deletions src/main/java/com/easypost/model/ClaimCollection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.easypost.model;

import java.util.List;
import java.util.Map;

import com.easypost.exception.General.EndOfPaginationError;
import lombok.Getter;

@Getter
public final class ClaimCollection extends PaginatedCollection<Claim> {
private List<Claim> claims;

@Override
protected Map<String, Object> buildNextPageParameters(List<Claim> claims, Integer pageSize)
throws EndOfPaginationError {
String lastId = claims.get(claims.size() - 1).getId();

Map<String, Object> parameters = new java.util.HashMap<>();
parameters.put("before_id", lastId);

if (pageSize != null) {
jchen293 marked this conversation as resolved.
Show resolved Hide resolved
parameters.put("page_size", pageSize);
}

return parameters;
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/easypost/model/ClaimHistoryEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.easypost.model;

import java.util.Date;
import lombok.Getter;

@Getter
public class ClaimHistoryEntry {
private String status;
private String statusDetail;
private Date statusTimestamp;
}
78 changes: 78 additions & 0 deletions src/main/java/com/easypost/model/DateDeserializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.easypost.model;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class DateDeserializer implements JsonDeserializer<Date> {
private static final String[] DATE_FORMATS = new String[]{
jchen293 marked this conversation as resolved.
Show resolved Hide resolved
// Basic formats
"yyyy-MM-dd",
"yyyy-MM-dd'T'HH:mm:ss",
"yyyy-MM-dd'T'HH:mm:ss'Z'",

// With milliseconds
"yyyy-MM-dd'T'HH:mm:ss.SSS",
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",

// With time zone offset
"yyyy-MM-dd'T'HH:mm:ssZ",
"yyyy-MM-dd'T'HH:mm:ssXXX",

// Alternative time formats
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd HH:mm:ss.SSS",

// Month and day only
"yyyy-MM-dd",
"MM/dd/yyyy",
"MM-dd-yyyy",

// Year and week
"yyyy-'W'ww",
"yyyy-'W'ww-u",

// Full date and time
"EEE, d MMM yyyy HH:mm:ss Z",
"EEE, d MMM yyyy HH:mm:ss z",
"EEEE, MMMM d, yyyy h:mm:ss a",

// Short formats
"M/d/yy",
"M-d-yy",
"M.d.yy",
"MM/dd/yyyy",
"MM-dd-yyyy"
};

/**
* Deserialize the Date format from a JSON object.
*
* @param json JSON object to deserialize.
* @param type Type of the object to deserialize.
* @param context Deserialization context.
* @return Deserialized Date object.
* @throws JsonParseException if the JSON object is not a valid SmartrateCollection.
*/
@Override
public Date deserialize(JsonElement json, Type type, JsonDeserializationContext context)
throws JsonParseException {
for (String format : DATE_FORMATS) {
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf.parse(json.getAsString());
} catch (ParseException e) {
throw new JsonParseException("Unable to parse this date format");
}
}
throw new JsonParseException("Unparseable date: \"" + json.getAsString() + "\"");
}
}
107 changes: 107 additions & 0 deletions src/main/java/com/easypost/service/ClaimService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.easypost.service;

import java.util.Map;
import java.util.function.Function;

import com.easypost.exception.EasyPostException;
import com.easypost.exception.General.EndOfPaginationError;
import com.easypost.http.Requestor;
import com.easypost.http.Requestor.RequestMethod;
import com.easypost.model.Claim;
import com.easypost.model.ClaimCollection;

import lombok.SneakyThrows;

public class ClaimService {
private final EasyPostClient client;

/**
* ClaimService constructor.
*
* @param client The client object.
*/
ClaimService(EasyPostClient client) {
this.client = client;
}

/**
* Create a new claim object from a map of parameters.
*
* @param params Map of parameters.
* @return Claim object
* @throws EasyPostException when the request fails.
*/
public Claim create(final Map<String, Object> params) throws EasyPostException {
String endpoint = "claims";

return Requestor.request(RequestMethod.POST, endpoint, params, Claim.class, client);
}

/**
* Retrieve an Claim from the API.
*
* @param id The ID of the Claim to retrieve.
* @return Claim object
* @throws EasyPostException when the request fails.
*/
public Claim retrieve(final String id) throws EasyPostException {
String endpoint = "claims/" + id;

return Requestor.request(RequestMethod.GET, endpoint, null, Claim.class, client);
}

/**
* Get a list of Claims.
*
* @param params a map of parameters
* @return ClaimCollection object
* @throws EasyPostException when the request fails.
*/
public ClaimCollection all(final Map<String, Object> params) throws EasyPostException {
String endpoint = "claims";

return Requestor.request(RequestMethod.GET, endpoint, params, ClaimCollection.class, client);
jchen293 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Cancel an Claim from the API.
*
* @param id The ID of the Claim to cancel.
* @return Claim object
* @throws EasyPostException when the request fails.
*/
public Claim cancel(final String id) throws EasyPostException {
String endpoint = String.format("claims/%s/cancel", id);

return Requestor.request(RequestMethod.POST, endpoint, null, Claim.class, client);
}

/**
* Get the next page of an ClaimCollection.
*
* @param collection ClaimCollection to get next page of.
* @return ClaimCollection object.
* @throws EndOfPaginationError when there are no more pages to retrieve.
*/
public ClaimCollection getNextPage(ClaimCollection collection) throws EndOfPaginationError {
return getNextPage(collection, null);
}

/**
* Get the next page of an ClaimCollection.
*
* @param collection ClaimCollection to get next page of.
* @param pageSize The number of results to return on the next page.
* @return ClaimCollection object.
* @throws EndOfPaginationError when there are no more pages to retrieve.
*/
public ClaimCollection getNextPage(
ClaimCollection collection, Integer pageSize) throws EndOfPaginationError {
return collection.getNextPage(new Function<Map<String, Object>, ClaimCollection>() {
@Override @SneakyThrows
public ClaimCollection apply(Map<String, Object> parameters) {
return all(parameters);
}
}, collection.getClaims(), pageSize);
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/easypost/service/EasyPostClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class EasyPostClient {
public final CarrierAccountService carrierAccount;
public final CarrierMetadataService carrierMetadata;
public final CarrierTypeService carrierType;
public final ClaimService claim;
public final CustomsInfoService customsInfo;
public final CustomsItemService customsItem;
public final EndShipperService endShipper;
Expand Down Expand Up @@ -136,6 +137,7 @@ public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, int readTim
this.carrierAccount = new CarrierAccountService(this);
this.carrierMetadata = new CarrierMetadataService(this);
this.carrierType = new CarrierTypeService(this);
this.claim = new ClaimService(this);
this.customsInfo = new CustomsInfoService(this);
this.customsItem = new CustomsItemService(this);
this.endShipper = new EndShipperService(this);
Expand Down
Loading
Loading