Skip to content

Commit

Permalink
Add claims API functions (#308)
Browse files Browse the repository at this point in the history
* Add claims API functions

* Switch to GA

* rename variable
  • Loading branch information
jchen293 committed Jul 24, 2024
1 parent 9a74779 commit b021995
Show file tree
Hide file tree
Showing 16 changed files with 1,151 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## Next Release

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

## v6.3.0 (2024-07-12)

- Adds new `shipment.recommend_ship_date`, `smartrate.recommend_ship_date`, and `smartrate.estimate_delivery_date` functions
Expand Down
2 changes: 1 addition & 1 deletion examples
Submodule examples updated 223 files
1 change: 1 addition & 0 deletions lib/easypost/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def initialize(api_key:, read_timeout: 60, open_timeout: 30, api_base: 'https://
EasyPost::Services::CarrierAccount,
EasyPost::Services::CarrierMetadata,
EasyPost::Services::CarrierType,
EasyPost::Services::Claim,
EasyPost::Services::CustomsInfo,
EasyPost::Services::CustomsItem,
EasyPost::Services::EndShipper,
Expand Down
1 change: 1 addition & 0 deletions lib/easypost/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module EasyPost::Models
require_relative 'models/brand'
require_relative 'models/carrier_account'
require_relative 'models/carrier_type'
require_relative 'models/claim'
require_relative 'models/customs_info'
require_relative 'models/customs_item'
require_relative 'models/end_shipper'
Expand Down
5 changes: 5 additions & 0 deletions lib/easypost/models/claim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

# The Claim object has all the details for the filed claims
class EasyPost::Models::Claim < EasyPost::Models::EasyPostObject
end
1 change: 1 addition & 0 deletions lib/easypost/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module EasyPost::Services
require_relative 'services/carrier_account'
require_relative 'services/carrier_metadata'
require_relative 'services/carrier_type'
require_relative 'services/claim'
require_relative 'services/customs_info'
require_relative 'services/customs_item'
require_relative 'services/end_shipper'
Expand Down
43 changes: 43 additions & 0 deletions lib/easypost/services/claim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

class EasyPost::Services::Claim < EasyPost::Services::Service
MODEL_CLASS = EasyPost::Models::Claim

# Create an Claim object
def create(params = {})
response = @client.make_request(:post, 'claims', params)

EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
end

# Retrieve an Claim object
def retrieve(id)
response = @client.make_request(:get, "claims/#{id}", nil)

EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
end

# Retrieve all Claim objects
def all(params = {})
filters = { key: 'claims' }

get_all_helper('claims', MODEL_CLASS, params, filters)
end

# Get the next page of claims.
def get_next_page(collection, page_size = nil)
raise EasyPost::Errors::EndOfPaginationError.new unless more_pages?(collection)

params = { before_id: collection.claims.last.id }
params[:page_size] = page_size unless page_size.nil?

all(params)
end

# Cancel a filed claim
def cancel(id)
response = @client.make_request(:post, "claims/#{id}/cancel", nil)

EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
end
end
2 changes: 2 additions & 0 deletions lib/easypost/utilities/static_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module EasyPost::InternalUtilities::StaticMapper
'brd' => EasyPost::Models::Brand,
'ca' => EasyPost::Models::CarrierAccount,
'card' => EasyPost::Models::PaymentMethod,
'clm' => EasyPost::Models::Claim,
'cstinfo' => EasyPost::Models::CustomsInfo,
'cstitem' => EasyPost::Models::CustomsItem,
'es' => EasyPost::Models::EndShipper,
Expand Down Expand Up @@ -43,6 +44,7 @@ module EasyPost::InternalUtilities::StaticMapper
'Batch' => EasyPost::Models::Batch,
'Brand' => EasyPost::Models::Brand,
'CarrierAccount' => EasyPost::Models::CarrierAccount,
'Claim' => EasyPost::Models::Claim,
'CreditCard' => EasyPost::Models::PaymentMethod,
'CustomsInfo' => EasyPost::Models::CustomsInfo,
'CustomsItem' => EasyPost::Models::CustomsItem,
Expand Down

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

Loading

0 comments on commit b021995

Please sign in to comment.