EasyPost-Extensions
0.5.0
See the version list below for details.
dotnet add package EasyPost-Extensions --version 0.5.0
NuGet\Install-Package EasyPost-Extensions -Version 0.5.0
<PackageReference Include="EasyPost-Extensions" Version="0.5.0" />
paket add EasyPost-Extensions --version 0.5.0
#r "nuget: EasyPost-Extensions, 0.5.0"
// Install EasyPost-Extensions as a Cake Addin #addin nuget:?package=EasyPost-Extensions&version=0.5.0 // Install EasyPost-Extensions as a Cake Tool #tool nuget:?package=EasyPost-Extensions&version=0.5.0
EasyPost Extensions (.NET)
A collection of helper utilities for the EasyPost .NET Client.
This project is unaffiliated with EasyPost.
Installation
The easiest way to install the EasyPost Extensions is via NuGet:
Install-Package EasyPost-Extensions
Usage
Parameter Dictionary Creation
Currently, the EasyPost .NET library requires end-users to pass in pre-formatted dictionaries of key-value pairs of data to the functions.
Example:
var parameters = new Dictionary<string, object> {
{ "name", "My Name" },
{ "street1", "123 Main St" },
{ "city", "San Francisco" },
{ "state", "CA" },
{ "zip", "94105" },
{ "country", "US" },
{ "phone", "415-123-4567" }
};
var address = await myClient.Address.Create(parameters);
This can lead to some confusion when end-users are not familiar with what JSON key-value pairs are expected for a given function.
This can also lead to errors if the end-user were to accidentally misspell a key, or if the key were to change in a future version of the library.
The EasyPost Extensions library provides a set of helper functions to create these dictionaries for you, ensuring that:
- The correct keys are used
- The correct value types are used
- The data is formatted correctly
- All required parameters are included
- The schema is valid for a specific API version
Example:
// Use an object constructor to create the address creation parameters
var addressCreateParameters = new EasyPost.Extensions.Parameters.V2.Address.Create {
Name = "My Name",
Street1 = "123 Main St",
City = "San Francisco",
State = "CA",
Zip = "94105",
Country = "US",
Phone = "415-123-4567"
};
// You can add additional parameters as needed outside of the constructor
addressCreateParameters.Company = "My Company";
// Then convert the object to a dictionary
// This step will validate the data and throw an exception if there are any errors (i.e. missing required parameters)
var addressCreateDictionary = addressCreateParameters.ToDictionary();
// Pass the dictionary into the EasyPost .NET library method as normal
var address = await myClient.Address.Create(addressCreateDictionary);
The parameter object models are divided by object type (i.e. Address, Parcel, etc.) and by function (i.e. Create, Retrieve, etc.).
Service and Model Extension Methods
Users can utilize the parameter objects above, passing the .ToDictionary()
results into the first-party EasyPost .NET
library methods.
var endShipperCreateParameters = new EasyPost.Extensions.Parameters.V2.EndShipper.Create {
Name = "My Name",
Street1 = "123 Main St",
City = "San Francisco",
State = "CA",
Zip = "94105",
Country = "US",
Phone = "415-123-4567"
};
// Pass the parameter object as a dictionary into the EasyPost .NET library
var endShipper = await myClient.EndShipper.Create(endShipperCreateParameters.ToDictionary());
The EasyPost Extensions library also provides a set of extension methods for EasyPost services and models to make this process easier, allowing users to pass in the parameter objects directly.
// import the proper namespaces to use the extension methods
using EasyPost.Extensions.ServiceMethodExtensions;
using EasyPost.Extensions.ModelMethodExtensions;
var endShipperCreateParameters = new EasyPost.Extensions.Parameters.V2.EndShipper.Create {
Name = "My Name",
Street1 = "123 Main St",
City = "San Francisco",
State = "CA",
Zip = "94105",
Country = "US",
Phone = "415-123-4567"
};
// Pass the parameter object directly into the EasyPost service extension method (no need to call .ToDictionary())
var endShipper = await myClient.EndShipper.Create(endShipperCreateParameters);
// You can also use the extension methods on the EasyPost models themselves
var endShipperUpdateParameters = new EasyPost.Extensions.Parameters.V2.EndShipper.Update {
Name = "My New Name"
};
// Pass the parameter object directly into the EasyPost model extension method (no need to call .ToDictionary())
await endShipper.Update(endShipperUpdateParameters);
Behind the scenes, these extension methods will simply validate the parameter object and convert it to a dictionary before passing it into the first-party EasyPost .NET library methods.
Client Manager
The 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);
API URL Generator
The EasyPost API is currently on v2
, but there is also the beta
version for beta features.
In case the EasyPost API base URL ever changes (either to a new subdomain or to a new version), the EasyPost Extensions library provides a helper function to generate the API URL for you.
Example:
// Generate the API URL for the v2 API
var apiVersionV2Enum = EasyPost.Extensions.ApiVersion.V2;
var apiV2Url = = EasyPost.Extensions.General.BuildApiBaseUrl(apiVersionV2Enum);
// apiV2Url will be, e.g. "https://api.easypost.com/v2/"
Test Data Generators
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:
- Address objects
- Batch objects
- Carrier strings
- CustomsInfo objects
- CustomsItem objects
- Insurance objects
- Parcel objects
- Pickup objects
- Rate objects
- Smartrate objects
- Shipment objects
- TaxIdentifier parameters
- Tracker objects
- Webhook objects
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- EasyPost-Official (>= 4.3.0)
- N8.NetTools.Common (>= 0.6.2)
- N8.NetTools.Common.Attributes (>= 1.1.0)
-
.NETStandard 2.0
- EasyPost-Official (>= 4.3.0)
- N8.NetTools.Common (>= 0.6.2)
- N8.NetTools.Common.Attributes (>= 1.1.0)
-
.NETStandard 2.1
- EasyPost-Official (>= 4.3.0)
- N8.NetTools.Common (>= 0.6.2)
- N8.NetTools.Common.Attributes (>= 1.1.0)
-
net5.0
- EasyPost-Official (>= 4.3.0)
- N8.NetTools.Common (>= 0.6.2)
- N8.NetTools.Common.Attributes (>= 1.1.0)
-
net6.0
- EasyPost-Official (>= 4.3.0)
- N8.NetTools.Common (>= 0.6.2)
- N8.NetTools.Common.Attributes (>= 1.1.0)
-
net7.0
- EasyPost-Official (>= 4.3.0)
- N8.NetTools.Common (>= 0.6.2)
- N8.NetTools.Common.Attributes (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.7.2 | 0 | 11/5/2024 |
1.7.1 | 74 | 10/11/2024 |
1.7.0 | 99 | 10/10/2024 |
1.6.1 | 81 | 10/9/2024 |
1.6.0 | 78 | 10/9/2024 |
1.5.0 | 121 | 6/6/2024 |
1.4.0 | 248 | 11/6/2023 |
1.3.0 | 142 | 8/30/2023 |
1.2.0 | 180 | 7/6/2023 |
1.1.0 | 141 | 6/7/2023 |
1.0.0 | 158 | 5/16/2023 |
0.6.0 | 300 | 1/29/2023 |
0.5.0 | 285 | 1/22/2023 |
0.4.0 | 285 | 1/18/2023 |
0.3.0 | 283 | 1/14/2023 |
0.2.0 | 310 | 12/19/2022 |
0.1.0 | 327 | 10/19/2022 |