Skip to content

Commit

Permalink
Merge pull request #460 from ralexmatthews/claims
Browse files Browse the repository at this point in the history
Adds support for claims API
  • Loading branch information
ralexmatthews authored Jul 23, 2024
2 parents ef1fd7a + 1db708a commit d17e60c
Show file tree
Hide file tree
Showing 25 changed files with 2,599 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ If you would need or want to view what requests are being made to the EasyPost A
```javascript
const client = new EasyPostClient('my-key');

const logOutgoingRequest = (request) => console.log("Outgoing:", request);
const logResponse = (response) => console.log("Response:", response)
const logOutgoingRequest = (request) => console.log('Outgoing:', request);
const logResponse = (response) => console.log('Response:', response);

// optionally add your hook to listen for outgoing requests
client.addRequestHook(logOutgoingRequest);
// and optionally the hook for the response
client.addResponseHook(logResponse)
client.addResponseHook(logResponse);

// ...do other stuff

Expand Down
2 changes: 1 addition & 1 deletion examples
Submodule examples updated 225 files
4 changes: 3 additions & 1 deletion src/easypost.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import BillingService from './services/billing_service';
import CarrierAccountService from './services/carrier_account_service';
import CarrierMetadataService from './services/carrier_metadata_service';
import CarrierTypeService from './services/carrier_type_service';
import ClaimService from './services/claim_service';
import CustomsInfoService from './services/customs_info_service';
import CustomsItemService from './services/customs_item_service';
import EndShipperService from './services/end_shipper_service';
Expand Down Expand Up @@ -93,6 +94,7 @@ export const SERVICES = {
CarrierAccount: CarrierAccountService,
CarrierMetadata: CarrierMetadataService,
CarrierType: CarrierTypeService,
Claim: ClaimService,
CustomsInfo: CustomsInfoService,
CustomsItem: CustomsItemService,
EndShipper: EndShipperService,
Expand Down Expand Up @@ -239,7 +241,7 @@ export default class EasyPostClient {
}

let completePath = this.baseUrl + path;
completePath = path.includes('beta') ? completePath.replace('v2', '') : completePath;
completePath = path.includes('beta') ? completePath.replace('/v2', '') : completePath;

return completePath;
}
Expand Down
28 changes: 28 additions & 0 deletions src/models/claim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import EasyPostObject from './easypost_object';

/**
* An {@link https://docs.easypost.com/docs/insurance/claims Claim} object represents claim for a {@link Shipment shipment}.
* @public
* @extends EasyPostObject
*/
export default class Claim extends EasyPostObject {
static id;
static object;
static mode;
static attachments;
static contact_email;
static created_at;
static description;
static history;
static insurance_amount;
static insurance_id;
static payment_method;
static requested_amount;
static shipment_id;
static status;
static status_detail;
static status_timestamp;
static tracking_code;
static type;
static updated_at;
}
2 changes: 2 additions & 0 deletions src/services/base_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Batch from '../models/batch';
import Brand from '../models/brand';
import CarrierAccount from '../models/carrier_account';
import CarrierType from '../models/carrier_type';
import Claim from '../models/claim';
import CustomsInfo from '../models/customs_info';
import CustomsItem from '../models/customs_item';
import EasyPostObject from '../models/easypost_object';
Expand Down Expand Up @@ -37,6 +38,7 @@ const EASYPOST_OBJECT_ID_PREFIX_TO_CLASS_NAME_MAP = {
brd: Brand,
ca: CarrierAccount,
cfrep: Report,
clm: Claim,
cstinfo: CustomsInfo,
cstitem: CustomsItem,
es: EndShipper,
Expand Down
66 changes: 66 additions & 0 deletions src/services/claim_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import baseService from './base_service';

export default (easypostClient) =>
/**
* The ClaimService class provides methods for interacting with EasyPost {@link Claim} objects.
* @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service.
*/
class ClaimService extends baseService(easypostClient) {
/**
* Create a {@link Claim claim} record.
* See {@link https://www.easypost.com/docs/api/node#create-a-claim EasyPost API Documentation} for more information.
* @param {Object} params - Parameters for the claim to be created.
* @returns {Claim} - The created claim.
*/
static async create(params) {
const url = 'claims';

return this._create(url, params);
}

/**
* Retrieve all {@link Claim} records associated with the current authenticated user.
* See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-claims EasyPost API Documentation} for more information.
* @param {Object} [params] - Parameters to filter the claim records.
* @returns {Object} - An object containing the list of {@link Claim claim} records and pagination information.
*/
static async all(params = {}) {
const url = 'claims';

return this._all(url, params);
}

/**
* Retrieve the next page of Claim collection.
* @param {Object} claims An object containing a list of {@link Claim claims} and pagination information.
* @param {Number} pageSize The number of records to return on each page
* @returns {EasyPostObject|Promise<never>} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error.
*/
static async getNextPage(claims, pageSize = null) {
const url = 'claims';
return this._getNextPage(url, 'claims', claims, pageSize);
}

/**
* Retrieve a {@link Claim claim} record by its ID.
* See {@link https://www.easypost.com/docs/api/node#retrieve-a-claim EasyPost API Documentation} for more information.
* @param {string} id - The ID of the claim to retrieve.
* @returns {Claim} - The retrieved claim.
*/
static async retrieve(id) {
const url = `claims/${id}`;

return this._retrieve(url);
}

/**
* Cancel a {@link Claim claim} record by its ID.
* See {@link https://www.easypost.com/docs/api/node#refund-a-claim EasyPost API Documentation} for more information.
* @param {string} id - The ID of the claim to be canceled.
* @returns {Claim} - The canceled claim.
*/
static async cancel(id) {
const url = `claims/${id}/cancel`;
return this._create(url);
}
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d17e60c

Please sign in to comment.