Package Description
$ dotnet add package EasyPost-ExtensionsA collection of helper utilities for the EasyPost .NET Client.
This project is unaffiliated with EasyPost.
The easiest way to install the EasyPost Extensions is via NuGet:
Install-Package EasyPost-Extensions
The information below is only highlights of this package's capabilities. For full reference, see the docs: http://www.nateharr.is/easypost-extensions-dotnet/api/index.html
The EasyPost .NET library provides a set of first-party parameter sets for each API-calling function.
The EasyPost Extensions library provides additional sets for specific functions, including:
myClient.Shipment.GenerateForm() functionUser, EndShipper or CarrierAccount using an existing objectRefund set for simplifying the refunding of a referral customerThe EasyPost Extensions library provides a set of extension methods for EasyPost services to make them easier to work with.
myClient.CarrierAccount.CreateFedEx() or myClient.CarrierAccount.CreateUps()myClient.ReferralCustomer.Refund()myClient.Shipment.Return()myClient.Webhook.Toggle()The EasyPost Extensions library provides a set of extension methods for EasyPost models to make them easier to work with.
Batch object as an enum with myBatch.BatchStateEnum()CustomsInfo object as an enum with myCustomsInfo.FormTypeEnum()CustomsInfo object as an enum with myCustomsInfo.NonDeliveryOptionEnum()CustomsItem object as an enum with myCustomsItem.RestrictionTypeEnum()Event object as an enum with myEvent.Type()Form object as an enum with myForm.Type()The EasyPost Extensions library provides a set of custom clients to make working with the EasyPost API easier.
ProxyClient - An extension of EasyPostClient that uses a proxy server to make API requestsIntrospectiveClient - An extension of EasyPostClient that supports pre- and post-request hooksMockClient - An extension of EasyPostClient that allows you to mock API requests and responsesThe EasyPost Extensions library provides a ClientManager class to help manage the EasyPost API client.
The ClientManager class wraps the EasyPost .NET library Client class, storing both your test and production API keys
to make it easier to switch between the two modes.
// Create a new ClientManager instance
var clientManager = new EasyPost.Extensions.ClientManager("test_123", "prod_123");
// Access the EasyPost .NET library Client instance to use as normal
var address = await clientManager.Client.Address.Create(parameters);
// Switch between test and production modes
clientManager.EnableTestMode();
clientManager.EnableProductionMode();
// It is recommended to always access the Client instance via the Client property directly, rather than storing it as a variable.
// When switching between test and production modes, the Client is re-initialized. Storing the Client as a variable may cause it to not be updated when switching modes.
// Yes
var address = await clientManager.Client.Address.Create(parameters);
// No
var client = clientManager.Client;
var address = await client.Address.Create(parameters);The EasyPost Extensions library provides an EasyPostWebhookController class to help manage EasyPost webhooks.
The controller, paired with an EasyPostEventProcessor, will automatically execute specific actions based on the type of event received.
End-users should implement their own controller that inherits from EasyPostWebhookController and override the WebhookSecret, EnableTestMode and EventProcessor properties.
[Route("api/incoming_easypost_webhook")]
public class MyWebhookController : EasyPostWebhookController
{
protected override string WebhookSecret => "my-webhook-secret";
protected override bool EnableTestMode => false;
protected override EasyPostEventProcessor EventProcessor => new()
{
OnBatchCreated = async (@event) =>
{
// Do something when a "batch.created" event is received
},
};
}The EasyPost Extensions library provides a set of helper functions to generate test data for you.
// Generate a random shipment
var shipment = EasyPost.Extensions.Testing.DummyData.Shipments.CreateShipment(myEasyPostClient);This library allows you to generate the following test data: