Skip to content

Commit

Permalink
- Remove Shipment.CreateReturn function
Browse files Browse the repository at this point in the history
- Remove now-unneeded nullability utilities
- Update CHANGELOG.md with info about nullable properties
  • Loading branch information
nwithan8 committed Sep 9, 2022
1 parent befdc7a commit 57cc343
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 68 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
- Some properties have been renamed to avoid naming conflicts:
- `Rate.rate` is now `Rate.Price`
- `Message.message` is now `Message.Text`
- All properties are now nullable.
- Almost all properties will be assigned a value during JSON deserialization. This is mostly to address compiler warnings.
- Users can proceed with the assumption that any given property will not be null.
- All objects now share a common base set of properties, including `Id`, `CreatedAt`, `UpdatedAt`, and `Mode`.
- Under the hood improvements:
- Underlying `Request`-`Client`-`ClientConfiguration` relationship has been re-architected to allow for thread safety.
Expand Down
16 changes: 0 additions & 16 deletions EasyPost/Models/API/Shipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,6 @@ public class Shipment : EasyPostObject

#region CRUD Operations

/// <summary>
/// Return this shipment.
/// </summary>
/// <returns>A return shipment.</returns>
[CrudOperations.Create]
public async Task<Shipment> Return()
{
if (Id == null)
{
// This is a local object, not one pulled from the server.
throw new Exception("id is null");
}

return await (Client as Client)!.Shipment.CreateReturn(this);
}

/// <summary>
/// Get the Smartrates for this shipment.
/// </summary>
Expand Down
35 changes: 0 additions & 35 deletions EasyPost/Services/ShipmentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,41 +47,6 @@ public async Task<Shipment> Create(Dictionary<string, object> parameters, bool w
return await Create<Shipment>("shipments", parameters);
}

/// <summary>
/// Create a return shipment for a shipment.
/// Uses the same To and From addresses as the original shipment by default.
/// Users can override the To and From addresses by passing in new addresses.
/// </summary>
/// <param name="shipment">Shipment to return.</param>
/// <param name="overrideToAddress">Override the To address for the return.</param>
/// <param name="overrideFromAddress">Override the From address for the return.</param>
/// <returns>A return shipment.</returns>
[CrudOperations.Create]
public async Task<Shipment> CreateReturn(Shipment shipment, Address? overrideToAddress = null, Address? overrideFromAddress = null)
{
if (shipment.Id == null)
{
throw new Exception("Shipment.id is null.");
}

overrideToAddress ??= shipment.FromAddress; // Use override address if provided, otherwise use original shipment From address as return To address.
overrideFromAddress ??= shipment.ToAddress; // Use override address if provided, otherwise use original shipment To address as return From address.

if (Nullability.AnyAreNull(overrideToAddress, overrideFromAddress, shipment.Parcel))
{
throw new Exception("Shipment missing required elements.");
}

return await Create(
new Dictionary<string, object>
{
{ "to_address", overrideToAddress! },
{ "from_address", overrideFromAddress! },
{ "parcel", shipment.Parcel! },
{ "is_return", true },
});
}

/// <summary>
/// Get a paginated list of shipments.
/// </summary>
Expand Down
17 changes: 0 additions & 17 deletions EasyPost/Utilities/Nullability.cs

This file was deleted.

0 comments on commit 57cc343

Please sign in to comment.