Skip to content

Commit b021995

Browse files
authored
Add claims API functions (#308)
* Add claims API functions * Switch to GA * rename variable
1 parent 9a74779 commit b021995

16 files changed

+1151
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## Next Release
4+
5+
- Adds new `Claim` service for filing claims on EasyPost shipments and insurances
6+
37
## v6.3.0 (2024-07-12)
48

59
- Adds new `shipment.recommend_ship_date`, `smartrate.recommend_ship_date`, and `smartrate.estimate_delivery_date` functions

examples

Submodule examples updated 223 files

lib/easypost/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def initialize(api_key:, read_timeout: 60, open_timeout: 30, api_base: 'https://
4242
EasyPost::Services::CarrierAccount,
4343
EasyPost::Services::CarrierMetadata,
4444
EasyPost::Services::CarrierType,
45+
EasyPost::Services::Claim,
4546
EasyPost::Services::CustomsInfo,
4647
EasyPost::Services::CustomsItem,
4748
EasyPost::Services::EndShipper,

lib/easypost/models.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module EasyPost::Models
1010
require_relative 'models/brand'
1111
require_relative 'models/carrier_account'
1212
require_relative 'models/carrier_type'
13+
require_relative 'models/claim'
1314
require_relative 'models/customs_info'
1415
require_relative 'models/customs_item'
1516
require_relative 'models/end_shipper'

lib/easypost/models/claim.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
# The Claim object has all the details for the filed claims
4+
class EasyPost::Models::Claim < EasyPost::Models::EasyPostObject
5+
end

lib/easypost/services.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module EasyPost::Services
1414
require_relative 'services/carrier_account'
1515
require_relative 'services/carrier_metadata'
1616
require_relative 'services/carrier_type'
17+
require_relative 'services/claim'
1718
require_relative 'services/customs_info'
1819
require_relative 'services/customs_item'
1920
require_relative 'services/end_shipper'

lib/easypost/services/claim.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# frozen_string_literal: true
2+
3+
class EasyPost::Services::Claim < EasyPost::Services::Service
4+
MODEL_CLASS = EasyPost::Models::Claim
5+
6+
# Create an Claim object
7+
def create(params = {})
8+
response = @client.make_request(:post, 'claims', params)
9+
10+
EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
11+
end
12+
13+
# Retrieve an Claim object
14+
def retrieve(id)
15+
response = @client.make_request(:get, "claims/#{id}", nil)
16+
17+
EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
18+
end
19+
20+
# Retrieve all Claim objects
21+
def all(params = {})
22+
filters = { key: 'claims' }
23+
24+
get_all_helper('claims', MODEL_CLASS, params, filters)
25+
end
26+
27+
# Get the next page of claims.
28+
def get_next_page(collection, page_size = nil)
29+
raise EasyPost::Errors::EndOfPaginationError.new unless more_pages?(collection)
30+
31+
params = { before_id: collection.claims.last.id }
32+
params[:page_size] = page_size unless page_size.nil?
33+
34+
all(params)
35+
end
36+
37+
# Cancel a filed claim
38+
def cancel(id)
39+
response = @client.make_request(:post, "claims/#{id}/cancel", nil)
40+
41+
EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
42+
end
43+
end

lib/easypost/utilities/static_mapper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module EasyPost::InternalUtilities::StaticMapper
1111
'brd' => EasyPost::Models::Brand,
1212
'ca' => EasyPost::Models::CarrierAccount,
1313
'card' => EasyPost::Models::PaymentMethod,
14+
'clm' => EasyPost::Models::Claim,
1415
'cstinfo' => EasyPost::Models::CustomsInfo,
1516
'cstitem' => EasyPost::Models::CustomsItem,
1617
'es' => EasyPost::Models::EndShipper,
@@ -43,6 +44,7 @@ module EasyPost::InternalUtilities::StaticMapper
4344
'Batch' => EasyPost::Models::Batch,
4445
'Brand' => EasyPost::Models::Brand,
4546
'CarrierAccount' => EasyPost::Models::CarrierAccount,
47+
'Claim' => EasyPost::Models::Claim,
4648
'CreditCard' => EasyPost::Models::PaymentMethod,
4749
'CustomsInfo' => EasyPost::Models::CustomsInfo,
4850
'CustomsItem' => EasyPost::Models::CustomsItem,

spec/cassettes/claim/EasyPost_Services_Claim_all_retrieves_all_claim_objects.yml

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)