From e4739f787fb0deefd831245d31788955ef6db44d Mon Sep 17 00:00:00 2001 From: Joe Pill Date: Mon, 24 Jun 2024 16:39:31 -0500 Subject: [PATCH] feat: add interface, mockable ShipEngine --- ShipEngine/PublicAPI.Shipped.txt | 39 ++++ ShipEngine/ShipEngine.cs | 340 ++++++++++++++++++++++++++++++- 2 files changed, 378 insertions(+), 1 deletion(-) diff --git a/ShipEngine/PublicAPI.Shipped.txt b/ShipEngine/PublicAPI.Shipped.txt index 183f6ad7..79649624 100644 --- a/ShipEngine/PublicAPI.Shipped.txt +++ b/ShipEngine/PublicAPI.Shipped.txt @@ -1048,6 +1048,25 @@ ShipEngineSDK.GetRatesWithShipmentDetails.ValidationStatus.HasWarnings = 2 -> Sh ShipEngineSDK.GetRatesWithShipmentDetails.ValidationStatus.Invalid = 1 -> ShipEngineSDK.GetRatesWithShipmentDetails.ValidationStatus ShipEngineSDK.GetRatesWithShipmentDetails.ValidationStatus.Unknown = 3 -> ShipEngineSDK.GetRatesWithShipmentDetails.ValidationStatus ShipEngineSDK.GetRatesWithShipmentDetails.ValidationStatus.Valid = 0 -> ShipEngineSDK.GetRatesWithShipmentDetails.ValidationStatus +ShipEngineSDK.IShipEngine +ShipEngineSDK.IShipEngine.CreateLabelFromRate(ShipEngineSDK.CreateLabelFromRate.Params! createLabelFromRateParams) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.CreateLabelFromRate(ShipEngineSDK.CreateLabelFromRate.Params! createLabelFromRateParams, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.CreateLabelFromShipmentDetails(ShipEngineSDK.CreateLabelFromShipmentDetails.Params! labelParams) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.CreateLabelFromShipmentDetails(ShipEngineSDK.CreateLabelFromShipmentDetails.Params! labelParams, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.CreateManifest(ShipEngineSDK.Config! methodConfig, ShipEngineSDK.Manifests.Params! manifestParams) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.CreateManifest(ShipEngineSDK.Manifests.Params! manifestParams) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.GetRatesWithShipmentDetails(ShipEngineSDK.GetRatesWithShipmentDetails.Params! rateParams) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.GetRatesWithShipmentDetails(ShipEngineSDK.GetRatesWithShipmentDetails.Params! rateParams, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.ListCarriers() -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.ListCarriers(ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.TrackUsingCarrierCodeAndTrackingNumber(string! trackingNumber, string! carrierCode) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.TrackUsingCarrierCodeAndTrackingNumber(string! trackingNumber, string! carrierCode, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.TrackUsingLabelId(string! labelId) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.TrackUsingLabelId(string! labelId, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.ValidateAddresses(System.Collections.Generic.List! addresses) -> System.Threading.Tasks.Task!>! +ShipEngineSDK.IShipEngine.ValidateAddresses(System.Collections.Generic.List! addresses, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task!>! +ShipEngineSDK.IShipEngine.VoidLabelWithLabelId(string! labelId) -> System.Threading.Tasks.Task! +ShipEngineSDK.IShipEngine.VoidLabelWithLabelId(string! labelId, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! ShipEngineSDK.ListCarriers.AdvancedOption ShipEngineSDK.ListCarriers.AdvancedOption.AdvancedOption() -> void ShipEngineSDK.ListCarriers.Carrier @@ -1188,6 +1207,8 @@ ShipEngineSDK.ShipEngineException.ResponseMessage.get -> System.Net.Http.HttpRes ShipEngineSDK.ShipEngineException.ResponseMessage.set -> void ShipEngineSDK.ShipEngineException.ShipEngineException(string! message, ShipEngineSDK.ErrorSource errorSource = ShipEngineSDK.ErrorSource.Shipengine, ShipEngineSDK.ErrorType errorType = ShipEngineSDK.ErrorType.System, ShipEngineSDK.ErrorCode errorCode = ShipEngineSDK.ErrorCode.Unspecified, System.Net.Http.HttpResponseMessage? responseMessage = null, string? requestID = null) -> void ShipEngineSDK.ShipEngineExtensions +ShipEngineSDK.ShipEngineMock +ShipEngineSDK.ShipEngineMock.ShipEngineMock() -> void ShipEngineSDK.TrackUsingCarrierCodeAndTrackingNumber.Result ShipEngineSDK.TrackUsingCarrierCodeAndTrackingNumber.Result.Result() -> void ShipEngineSDK.TrackUsingCarrierCodeAndTrackingNumber.Result.StatusCode.get -> ShipEngineSDK.Common.Enums.TrackingStatusCode @@ -1301,6 +1322,24 @@ static ShipEngineSDK.ShipEngineClient.ConfigureHttpClient(ShipEngineSDK.Config! static ShipEngineSDK.ShipEngineClient.ConfigureHttpClient(System.Net.Http.HttpClient! client, string! apiKey, System.Uri? baseUri, System.TimeSpan? timeout = null) -> System.Net.Http.HttpClient! static ShipEngineSDK.ShipEngineExtensions.AddShipEngine(this Microsoft.Extensions.Hosting.IHostApplicationBuilder! builder, System.Action? configureClient = null) -> Microsoft.Extensions.Hosting.IHostApplicationBuilder! virtual ShipEngineSDK.ShipEngineClient.SendHttpRequestAsync(System.Net.Http.HttpMethod! method, string! path, string? jsonContent, System.Net.Http.HttpClient! client, ShipEngineSDK.Config! config) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.CreateLabelFromRate(ShipEngineSDK.CreateLabelFromRate.Params! createLabelFromRateParams) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.CreateLabelFromRate(ShipEngineSDK.CreateLabelFromRate.Params! createLabelFromRateParams, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.CreateLabelFromShipmentDetails(ShipEngineSDK.CreateLabelFromShipmentDetails.Params! labelParams) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.CreateLabelFromShipmentDetails(ShipEngineSDK.CreateLabelFromShipmentDetails.Params! labelParams, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.CreateManifest(ShipEngineSDK.Config! methodConfig, ShipEngineSDK.Manifests.Params! manifestParams) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.CreateManifest(ShipEngineSDK.Manifests.Params! manifestParams) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.GetRatesWithShipmentDetails(ShipEngineSDK.GetRatesWithShipmentDetails.Params! rateParams) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.GetRatesWithShipmentDetails(ShipEngineSDK.GetRatesWithShipmentDetails.Params! rateParams, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.ListCarriers() -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.ListCarriers(ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.TrackUsingCarrierCodeAndTrackingNumber(string! trackingNumber, string! carrierCode) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.TrackUsingCarrierCodeAndTrackingNumber(string! trackingNumber, string! carrierCode, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.TrackUsingLabelId(string! labelId) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.TrackUsingLabelId(string! labelId, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.ValidateAddresses(System.Collections.Generic.List! addresses) -> System.Threading.Tasks.Task!>! +virtual ShipEngineSDK.ShipEngineMock.ValidateAddresses(System.Collections.Generic.List! addresses, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task!>! +virtual ShipEngineSDK.ShipEngineMock.VoidLabelWithLabelId(string! labelId) -> System.Threading.Tasks.Task! +virtual ShipEngineSDK.ShipEngineMock.VoidLabelWithLabelId(string! labelId, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! ~ShipEngineSDK.Common.Error.Message.get -> string ~ShipEngineSDK.Common.Error.Message.set -> void ~ShipEngineSDK.Common.ShipEngineAPIError.Errors.get -> System.Collections.Generic.List diff --git a/ShipEngine/ShipEngine.cs b/ShipEngine/ShipEngine.cs index 4c65038f..3094f957 100644 --- a/ShipEngine/ShipEngine.cs +++ b/ShipEngine/ShipEngine.cs @@ -1,6 +1,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using ShipEngineSDK.Common; +using ShipEngineSDK.Manifests; +using Result = ShipEngineSDK.ValidateAddresses.Result; using System; using System.Collections.Generic; using System.Net.Http; @@ -10,6 +12,342 @@ namespace ShipEngineSDK { + /// + /// Interface for ShipEngine + /// + public interface IShipEngine + { + /// + /// Validates an address in nearly any country in the world. + /// + /// The address to validate. This can even be an incomplete or improperly formatted address + /// An address validation result object + Task> ValidateAddresses(List
addresses); + + /// + /// Validates an address in nearly any country in the world. + /// + /// The address to validate. This can even be an incomplete or improperly formatted address + /// Configuration object that overrides the global config for this method call + /// An address validation result object + Task> ValidateAddresses(List
addresses, Config methodConfig); + + /// + /// Retrieve a list of all carriers that have been added to this account + /// + /// A list of carriers + Task ListCarriers(); + + /// + /// Retrieve a list of all carriers that have been added to this account + /// + /// Configuration object that overrides the global config for this method call. + /// A list of carriers + Task ListCarriers(Config methodConfig); + + /// + /// Create a manifest + /// + /// The details of the manifest you want to create. + /// + Task CreateManifest(Manifests.Params manifestParams); + + /// + /// Create a manifest + /// + /// Configuration object that overrides the global config for this method call. + /// The details of the manifest you want to create. + /// + Task CreateManifest(Config methodConfig, Manifests.Params manifestParams); + + /// + /// Void a label by ID to get a refund. + /// + /// The id of the label to void + /// Result object indicating the success of the void label attempt + Task VoidLabelWithLabelId(string labelId); + + /// + /// Void a label by ID to get a refund. + /// + /// The id of the label to void + /// Configuration object that overrides the global config for this method call + /// Result object indicating the success of the void label attempt + Task VoidLabelWithLabelId(string labelId, Config methodConfig); + + /// + /// Track a shipment using the label id + /// + /// The label id associated with the shipment + /// An object that contains the label id tracking information + Task TrackUsingLabelId(string labelId); + + /// + /// Track a shipment using the label id + /// + /// The label id associated with the shipment + /// Configuration object that overrides the global config for this method call + /// An object that contains the label id tracking information + Task TrackUsingLabelId(string labelId, Config methodConfig); + + /// + /// Tracks a package based on the trackingNumber and carrierCode. + /// + /// The tracking number of the package you wish to track. + /// The carrierCode for the trackingNumber you are using to track the package. + /// + Task TrackUsingCarrierCodeAndTrackingNumber(string trackingNumber, string carrierCode); + + /// + /// Tracks a package based on the trackingNumber and carrierCode. + /// + /// The tracking number of the package you wish to track. + /// The carrierCode for the trackingNumber you are using to track the package. + /// Configuration object that overrides the global config for this method call + /// + Task TrackUsingCarrierCodeAndTrackingNumber(string trackingNumber, string carrierCode, Config methodConfig); + + /// + /// Create a label from shipment details + /// + /// Details of the label that you want to create + /// Object containing the created label information + Task CreateLabelFromShipmentDetails(CreateLabelFromShipmentDetails.Params labelParams); + + /// + /// Create a label from shipment details + /// + /// Details of the label that you want to create + /// Configuration object that overrides the global config for this method call + /// Object containing the created label information + Task CreateLabelFromShipmentDetails(CreateLabelFromShipmentDetails.Params labelParams, Config methodConfig); + + /// + /// Create a label from a rate id + /// + /// The details of the rate that you want to use to purchase a label + /// Object containing the created label information + Task CreateLabelFromRate(CreateLabelFromRate.Params createLabelFromRateParams); + + /// + /// Create a label from a rate id + /// + /// The details of the rate that you want to use to purchase a label + /// Configuration object that overrides the global config for this method call + /// Object containing the created label information + Task CreateLabelFromRate(CreateLabelFromRate.Params createLabelFromRateParams, Config methodConfig); + + /// + /// Retrieve rates for a package with the provided shipment details. + /// + /// + /// The rates result + Task GetRatesWithShipmentDetails(GetRatesWithShipmentDetails.Params rateParams); + + /// + /// Retrieve rates for a package with the provided shipment details. + /// + /// + /// Configuration object that overrides the global config for this method call + /// The rates result + Task GetRatesWithShipmentDetails(GetRatesWithShipmentDetails.Params rateParams, Config methodConfig); + } + + /// + /// Mock implementation of IShipEngine + /// + public class ShipEngineMock : IShipEngine + { + /// + /// Validates an address in nearly any country in the world. + /// + /// The address to validate. This can even be an incomplete or improperly formatted address + /// An address validation result object + public virtual Task> ValidateAddresses(List
addresses) + { + return Task.FromResult(new List()); + } + + /// + /// Validates an address in nearly any country in the world. + /// + /// The address to validate. This can even be an incomplete or improperly formatted address + /// Configuration object that overrides the global config for this method call. + /// An address validation result object + public virtual Task> ValidateAddresses(List
addresses, Config methodConfig) + { + return Task.FromResult(new List()); + } + + /// + /// Retrieve a list of all carriers that have been added to this account + /// + /// A list of carriers + public virtual Task ListCarriers() + { + return Task.FromResult(new ListCarriers.Result()); + } + + /// + /// Retrieve a list of all carriers that have been added to this account + /// + /// Configuration object that overrides the global config for this method call. + /// A list of carriers + public virtual Task ListCarriers(Config methodConfig) + { + return Task.FromResult(new ListCarriers.Result()); + } + + /// + /// Create a manifest + /// + /// The details of the manifest you want to create. + /// + public virtual Task CreateManifest(Params manifestParams) + { + return Task.FromResult(new Manifests.Result()); + } + + /// + /// Create a manifest + /// + /// Configuration object that overrides the global config for this method call. + /// The details of the manifest you want to create. + /// + public virtual Task CreateManifest(Config methodConfig, Params manifestParams) + { + return Task.FromResult(new Manifests.Result()); + } + + /// + /// Void a label by ID to get a refund. + /// + /// The id of the label to void + /// Result object indicating the success of the void label attempt + public virtual Task VoidLabelWithLabelId(string labelId) + { + return Task.FromResult(new VoidLabelWithLabelId.Result()); + } + + /// + /// Void a label by ID to get a refund. + /// + /// The id of the label to void + /// Configuration object that overrides the global config for this method call + /// Result object indicating the success of the void label attempt + public virtual Task VoidLabelWithLabelId(string labelId, Config methodConfig) + { + return Task.FromResult(new VoidLabelWithLabelId.Result()); + } + + /// + /// Track a shipment using the label id + /// + /// The label id associated with the shipment + /// An object that contains the label id tracking information + public virtual Task TrackUsingLabelId(string labelId) + { + return Task.FromResult(new TrackUsingLabelId.Result()); + } + + /// + /// Track a shipment using the label id + /// + /// The label id associated with the shipment + /// Configuration object that overrides the global config for this method call + /// An object that contains the label id tracking information + public virtual Task TrackUsingLabelId(string labelId, Config methodConfig) + { + return Task.FromResult(new TrackUsingLabelId.Result()); + } + + /// + /// Tracks a package based on the trackingNumber and carrierCode. + /// + /// The tracking number of the package you wish to track. + /// The carrierCode for the trackingNumber you are using to track the package. + /// + public virtual Task TrackUsingCarrierCodeAndTrackingNumber(string trackingNumber, string carrierCode) + { + return Task.FromResult(new TrackUsingCarrierCodeAndTrackingNumber.Result()); + } + + /// + /// Tracks a package based on the trackingNumber and carrierCode. + /// + /// The tracking number of the package you wish to track. + /// The carrierCode for the trackingNumber you are using to track the package. + /// Configuration object that overrides the global config for this method call + /// + public virtual Task TrackUsingCarrierCodeAndTrackingNumber(string trackingNumber, string carrierCode, Config methodConfig) + { + return Task.FromResult(new TrackUsingCarrierCodeAndTrackingNumber.Result()); + } + + /// + /// Create a label from shipment details + /// + /// Details of the label that you want to create + /// Object containing the created label information + public virtual Task CreateLabelFromShipmentDetails(CreateLabelFromShipmentDetails.Params labelParams) + { + return Task.FromResult(new CreateLabelFromShipmentDetails.Result()); + } + + /// + /// Create a label from shipment details + /// + /// Details of the label that you want to create + /// Configuration object that overrides the global config for this method call + /// Object containing the created label information + public virtual Task CreateLabelFromShipmentDetails(CreateLabelFromShipmentDetails.Params labelParams, Config methodConfig) + { + return Task.FromResult(new CreateLabelFromShipmentDetails.Result()); + } + + /// + /// Create a label from a rate id + /// + /// The details of the rate that you want to use to purchase a label + /// Object containing the created label information + public virtual Task CreateLabelFromRate(CreateLabelFromRate.Params createLabelFromRateParams) + { + return Task.FromResult(new CreateLabelFromRate.Result()); + } + + /// + /// Create a label from a rate id + /// + /// The details of the rate that you want to use to purchase a label + /// Configuration object that overrides the global config for this method call + /// Object containing the created label information + public virtual Task CreateLabelFromRate(CreateLabelFromRate.Params createLabelFromRateParams, Config methodConfig) + { + return Task.FromResult(new CreateLabelFromRate.Result()); + } + + /// + /// Retrieve rates for a package with the provided shipment details. + /// + /// + /// The rates result + public virtual Task GetRatesWithShipmentDetails(GetRatesWithShipmentDetails.Params rateParams) + { + return Task.FromResult(new GetRatesWithShipmentDetails.Result()); + } + + /// + /// Retrieve rates for a package with the provided shipment details. + /// + /// + /// Configuration object that overrides the global config for this method call + /// The rates result + public virtual Task GetRatesWithShipmentDetails(GetRatesWithShipmentDetails.Params rateParams, Config methodConfig) + { + return Task.FromResult(new GetRatesWithShipmentDetails.Result()); + } + } + /// /// Extension method to allow customized client configuration /// @@ -38,7 +376,7 @@ public static IHostApplicationBuilder AddShipEngine(this IHostApplicationBuilder /// /// Contains methods for interacting with the ShipEngine API. /// - public class ShipEngine : ShipEngineClient, IDisposable + public class ShipEngine : ShipEngineClient, IDisposable, IShipEngine { /// /// Global HttpClient for ShipEngine instance.