diff --git a/CHANGELOG.md b/CHANGELOG.md index 34a17b36..455fb783 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -115,4 +115,14 @@ Updated to .NET 8.0, removed Newtonsoft.Json dependency, and updated to System.T ### Changed -Updated references to use proper converter to resolve enum string values \ No newline at end of file +Updated references to use proper converter to resolve enum string values + +## 2.0.2 + +### Changed + +- Adds the ability to initialize SDK with an HttpClient +- Adds cancellation token to client +- Adds HttpResponseMessage to ShipEngineException +- Adds missing markdown +- Redefines several properties as nullable reference types \ No newline at end of file diff --git a/ShipEngine/Models/Dto/Common/Customs.cs b/ShipEngine/Models/Dto/Common/Customs.cs index f7466ed6..b04d4a2f 100644 --- a/ShipEngine/Models/Dto/Common/Customs.cs +++ b/ShipEngine/Models/Dto/Common/Customs.cs @@ -24,7 +24,7 @@ public class Customs /// /// Customs declarations for each item in the shipment. /// - public List CustomsItems { get; set; } + public List? CustomsItems { get; set; } } /// diff --git a/ShipEngine/Models/Dto/CreateLabelFromRate/Result.cs b/ShipEngine/Models/Dto/CreateLabelFromRate/Result.cs index 33a59855..e757b43a 100644 --- a/ShipEngine/Models/Dto/CreateLabelFromRate/Result.cs +++ b/ShipEngine/Models/Dto/CreateLabelFromRate/Result.cs @@ -158,7 +158,7 @@ public class Result /// /// The label's package(s). /// - public List Packages { get; set; } + public List? Packages { get; set; } } /// diff --git a/ShipEngine/Models/Dto/CreateLabelFromShipmentDetails/Result.cs b/ShipEngine/Models/Dto/CreateLabelFromShipmentDetails/Result.cs index bc0fe88b..7ddb99e4 100644 --- a/ShipEngine/Models/Dto/CreateLabelFromShipmentDetails/Result.cs +++ b/ShipEngine/Models/Dto/CreateLabelFromShipmentDetails/Result.cs @@ -161,7 +161,7 @@ public class Result /// /// The label's package(s). /// - public List Packages { get; set; } + public List? Packages { get; set; } } /// diff --git a/ShipEngine/Models/Dto/GetRatesFromShipmentDetails/Params.cs b/ShipEngine/Models/Dto/GetRatesFromShipmentDetails/Params.cs index 3bf742e7..335c590c 100644 --- a/ShipEngine/Models/Dto/GetRatesFromShipmentDetails/Params.cs +++ b/ShipEngine/Models/Dto/GetRatesFromShipmentDetails/Params.cs @@ -145,6 +145,9 @@ public class Shipment /// public Weight Weight { get; set; } + /// + /// The type of comparison rate + /// [JsonConverter(typeof(JsonStringEnumConverter))] public ComparisonRateType? ComparisonRateType { get; set; } diff --git a/ShipEngine/Models/Dto/GetRatesFromShipmentDetails/Result.cs b/ShipEngine/Models/Dto/GetRatesFromShipmentDetails/Result.cs index 115965be..7287277c 100644 --- a/ShipEngine/Models/Dto/GetRatesFromShipmentDetails/Result.cs +++ b/ShipEngine/Models/Dto/GetRatesFromShipmentDetails/Result.cs @@ -4,6 +4,9 @@ namespace ShipEngineSDK.GetRatesWithShipmentDetails { + /// + /// Get rates with shipment details result + /// public class Result { /// @@ -29,12 +32,12 @@ public class Result /// /// Describe the packages included in this shipment as related to potential metadata that was imported from external order sources /// - public List Items { get; set; } + public List? Items { get; set; } /// /// Tax identifiers /// - public List TaxIdentifiers { get; set; } + public List? TaxIdentifiers { get; set; } /// /// You can optionally use this field to store your own identifier for this shipment. @@ -64,13 +67,13 @@ public class Result /// /// The recipient's mailing address /// - public Address ShipTo { get; set; } + public Address? ShipTo { get; set; } /// /// The shipment's origin address. If you frequently ship from the same location, consider creating a warehouse. /// Then you can simply specify the warehouse_id rather than the complete address each time. /// - public Address ShipFrom { get; set; } + public Address? ShipFrom { get; set; } /// /// The warehouse that the shipment is being shipped from. Either warehouse_id or ship_from must be specified. @@ -80,7 +83,7 @@ public class Result /// /// The return address for this shipment. Defaults to the ship_from address. /// - public Address ReturnTo { get; set; } + public Address? ReturnTo { get; set; } /// /// The type of delivery confirmation that is required for this shipment. @@ -90,12 +93,12 @@ public class Result /// /// Customs information. This is usually only needed for international shipments. /// - public Customs Customs { get; set; } + public Customs? Customs { get; set; } /// /// Advanced shipment options. These are entirely optional. /// - public AdvancedShipmentOptions AdvancedOptions { get; set; } + public AdvancedShipmentOptions? AdvancedOptions { get; set; } /// /// Indicates if the package will be picked up or dropped off by the carrier @@ -110,13 +113,13 @@ public class Result /// /// Arbitrary tags associated with this shipment. Tags can be used to categorize shipments, and shipments can be queried by their tags. /// - public List Tags { get; set; } + public List? Tags { get; set; } /// /// Total Weight of the Shipment /// - public Weight TotalWeight { get; set; } + public Weight? TotalWeight { get; set; } /// /// The order sources that are supported by ShipEngine @@ -126,30 +129,33 @@ public class Result /// /// The packages in the shipment. /// - public List Packages { get; set; } + public List? Packages { get; set; } /// /// The combined weight of all packages in the shipment /// - public Weight Weight { get; set; } + public Weight? Weight { get; set; } /// /// The rate responses /// - public RateResponse RateResponse { get; set; } + public RateResponse? RateResponse { get; set; } } + /// + /// The get rates with shipment details rate response + /// public class RateResponse { /// /// A list of shipment rates /// - public List Rates { get; set; } + public List? Rates { get; set; } /// /// A list of invalid shipment rates /// - public List InvalidRates { get; set; } + public List? InvalidRates { get; set; } /// /// A string that uniquely identifies the rate request @@ -174,9 +180,12 @@ public class RateResponse /// /// Any errors associated with the rate request /// - public List Errors { get; set; } + public List? Errors { get; set; } } + /// + /// The individual rate + /// public class Rate { /// @@ -197,33 +206,31 @@ public class Rate /// /// The shipping amount /// - public MonetaryValue ShippingAmount { get; set; } + public MonetaryValue? ShippingAmount { get; set; } /// /// The insurance amount /// - public MonetaryValue InsuranceAmount { get; set; } + public MonetaryValue? InsuranceAmount { get; set; } /// /// The sum of the carrier costs for the shipment /// - public MonetaryValue RequestedComparisonAmount { get; set; } - - + public MonetaryValue? RequestedComparisonAmount { get; set; } /// /// The confirmation amount /// - public MonetaryValue ConfirmationAmount { get; set; } + public MonetaryValue? ConfirmationAmount { get; set; } /// /// Any other charges associated with this rate /// - public MonetaryValue OtherAmount { get; set; } + public MonetaryValue? OtherAmount { get; set; } /// /// Tariff and additional taxes associated with an international shipment. /// - public MonetaryValue TaxAmount { get; set; } + public MonetaryValue? TaxAmount { get; set; } /// /// Certain carriers base their rates off of custom zones that vary depending upon @@ -306,11 +313,11 @@ public class Rate /// /// The warning messages /// - public List WarningMessages { get; set; } + public List? WarningMessages { get; set; } /// /// The error messages /// - public List ErrorMessages { get; set; } + public List? ErrorMessages { get; set; } } } \ No newline at end of file diff --git a/ShipEngine/Models/Dto/VoidLabelWithLabelId/Result.cs b/ShipEngine/Models/Dto/VoidLabelWithLabelId/Result.cs index f26b9d34..ebb90214 100644 --- a/ShipEngine/Models/Dto/VoidLabelWithLabelId/Result.cs +++ b/ShipEngine/Models/Dto/VoidLabelWithLabelId/Result.cs @@ -13,6 +13,6 @@ public class Result /// /// Message associated with the result of the void label attempt /// - public string Message { get; set; } + public string? Message { get; set; } } } \ No newline at end of file diff --git a/ShipEngine/Models/ShipEngineException.cs b/ShipEngine/Models/ShipEngineException.cs index 6d687e0a..5010393b 100644 --- a/ShipEngine/Models/ShipEngineException.cs +++ b/ShipEngine/Models/ShipEngineException.cs @@ -1,49 +1,48 @@ #pragma warning disable 1591 using System; +using System.Net.Http; namespace ShipEngineSDK { /// /// Error object returned from failed method calls /// - public class ShipEngineException : Exception + public class ShipEngineException( + string message, + ErrorSource errorSource = ErrorSource.Shipengine, + ErrorType errorType = ErrorType.System, + ErrorCode errorCode = ErrorCode.Unspecified, + string? requestID = null, + HttpResponseMessage? responseMessage = null) + : Exception(message) { /// /// A UUID that uniquely identifies the request id. /// This can be given to the support team to help debug non-trivial issues that may occur /// - public string? RequestId { get; } + public string? RequestId { get; } = requestID; /// /// The source of the error, as indicated by the name this informs us if the API call failed /// because of the carrier, the order source, or the ShipEngine API itself. /// - public ErrorSource ErrorSource { get; set; } + public ErrorSource ErrorSource { get; set; } = errorSource; /// /// The type of error /// - public ErrorType ErrorType { get; set; } + public ErrorType ErrorType { get; set; } = errorType; /// /// The error code specified for the failed API Call /// - public ErrorCode ErrorCode { get; set; } + public ErrorCode ErrorCode { get; set; } = errorCode; - - public ShipEngineException( - string message, - ErrorSource errorSource = ErrorSource.Shipengine, - ErrorType errorType = ErrorType.System, - ErrorCode errorCode = ErrorCode.Unspecified, - string requestID = null) : base(message) - { - ErrorSource = errorSource; - ErrorType = errorType; - ErrorCode = errorCode; - RequestId = requestID; - } + /// + /// The http response message returned from the failed API call + /// + public HttpResponseMessage? ResponseMessage { get; set; } = responseMessage; } } \ No newline at end of file diff --git a/ShipEngine/PublicAPI.Shipped.txt b/ShipEngine/PublicAPI.Shipped.txt index aa140317..470c837f 100644 --- a/ShipEngine/PublicAPI.Shipped.txt +++ b/ShipEngine/PublicAPI.Shipped.txt @@ -1,11 +1,9 @@ #nullable enable -override ShipEngineSDK.Common.MonetaryValueConverter.CanWrite.get -> bool -override ShipEngineSDK.Common.MonetaryValueConverter.ReadJson(Newtonsoft.Json.JsonReader! reader, System.Type! objectType, ShipEngineSDK.Common.MonetaryValue! existingValue, bool hasExistingValue, Newtonsoft.Json.JsonSerializer! serializer) -> ShipEngineSDK.Common.MonetaryValue! -override ShipEngineSDK.Common.MonetaryValueConverter.WriteJson(Newtonsoft.Json.JsonWriter! writer, ShipEngineSDK.Common.MonetaryValue! value, Newtonsoft.Json.JsonSerializer! serializer) -> void +override ShipEngineSDK.Common.MonetaryValueConverter.Read(ref System.Text.Json.Utf8JsonReader reader, System.Type! type, System.Text.Json.JsonSerializerOptions! options) -> ShipEngineSDK.Common.MonetaryValue! +override ShipEngineSDK.Common.MonetaryValueConverter.Write(System.Text.Json.Utf8JsonWriter! writer, ShipEngineSDK.Common.MonetaryValue! value, System.Text.Json.JsonSerializerOptions! options) -> void readonly ShipEngineSDK.Config.ApiKey -> string! readonly ShipEngineSDK.Config.Retries -> int readonly ShipEngineSDK.Config.Timeout -> System.TimeSpan -readonly ShipEngineSDK.ShipEngineClient.JsonSerializerSettings -> Newtonsoft.Json.JsonSerializerSettings! ShipEngineSDK.Common.Address ShipEngineSDK.Common.Address.Address() -> void ShipEngineSDK.Common.Address.AddressLine1.get -> string? @@ -80,7 +78,7 @@ ShipEngineSDK.Common.Customs ShipEngineSDK.Common.Customs.Contents.get -> ShipEngineSDK.Common.Enums.PackageContents ShipEngineSDK.Common.Customs.Contents.set -> void ShipEngineSDK.Common.Customs.Customs() -> void -ShipEngineSDK.Common.Customs.CustomsItems.get -> System.Collections.Generic.List! +ShipEngineSDK.Common.Customs.CustomsItems.get -> System.Collections.Generic.List? ShipEngineSDK.Common.Customs.CustomsItems.set -> void ShipEngineSDK.Common.Customs.NonDelivery.get -> ShipEngineSDK.Common.Enums.NonDelivery ShipEngineSDK.Common.Customs.NonDelivery.set -> void @@ -657,7 +655,7 @@ ShipEngineSDK.CreateLabelFromRate.Result.LabelLayout.get -> ShipEngineSDK.Common ShipEngineSDK.CreateLabelFromRate.Result.LabelLayout.set -> void ShipEngineSDK.CreateLabelFromRate.Result.PackageCode.get -> string? ShipEngineSDK.CreateLabelFromRate.Result.PackageCode.set -> void -ShipEngineSDK.CreateLabelFromRate.Result.Packages.get -> System.Collections.Generic.List! +ShipEngineSDK.CreateLabelFromRate.Result.Packages.get -> System.Collections.Generic.List? ShipEngineSDK.CreateLabelFromRate.Result.Packages.set -> void ShipEngineSDK.CreateLabelFromRate.Result.Result() -> void ShipEngineSDK.CreateLabelFromRate.Result.RmaNumber.get -> string? @@ -794,7 +792,7 @@ ShipEngineSDK.CreateLabelFromShipmentDetails.Result.LabelLayout.get -> ShipEngin ShipEngineSDK.CreateLabelFromShipmentDetails.Result.LabelLayout.set -> void ShipEngineSDK.CreateLabelFromShipmentDetails.Result.PackageCode.get -> string? ShipEngineSDK.CreateLabelFromShipmentDetails.Result.PackageCode.set -> void -ShipEngineSDK.CreateLabelFromShipmentDetails.Result.Packages.get -> System.Collections.Generic.List! +ShipEngineSDK.CreateLabelFromShipmentDetails.Result.Packages.get -> System.Collections.Generic.List? ShipEngineSDK.CreateLabelFromShipmentDetails.Result.Packages.set -> void ShipEngineSDK.CreateLabelFromShipmentDetails.Result.Result() -> void ShipEngineSDK.CreateLabelFromShipmentDetails.Result.RmaNumber.get -> string? @@ -899,21 +897,21 @@ ShipEngineSDK.GetRatesWithShipmentDetails.Rate.CarrierId.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.CarrierId.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Rate.CarrierNickname.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.CarrierNickname.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ConfirmationAmount.get -> ShipEngineSDK.Common.MonetaryValue! +ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ConfirmationAmount.get -> ShipEngineSDK.Common.MonetaryValue? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ConfirmationAmount.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Rate.DeliveryDays.get -> int? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.DeliveryDays.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ErrorMessages.get -> System.Collections.Generic.List! +ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ErrorMessages.get -> System.Collections.Generic.List? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ErrorMessages.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Rate.EstimatedDeliveryDate.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.EstimatedDeliveryDate.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Rate.GuaranteedService.get -> bool ShipEngineSDK.GetRatesWithShipmentDetails.Rate.GuaranteedService.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Rate.InsuranceAmount.get -> ShipEngineSDK.Common.MonetaryValue! +ShipEngineSDK.GetRatesWithShipmentDetails.Rate.InsuranceAmount.get -> ShipEngineSDK.Common.MonetaryValue? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.InsuranceAmount.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Rate.NegotiatedRate.get -> bool ShipEngineSDK.GetRatesWithShipmentDetails.Rate.NegotiatedRate.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Rate.OtherAmount.get -> ShipEngineSDK.Common.MonetaryValue! +ShipEngineSDK.GetRatesWithShipmentDetails.Rate.OtherAmount.get -> ShipEngineSDK.Common.MonetaryValue? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.OtherAmount.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Rate.PackageType.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.PackageType.set -> void @@ -922,7 +920,7 @@ ShipEngineSDK.GetRatesWithShipmentDetails.Rate.RateId.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.RateId.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Rate.RateType.get -> ShipEngineSDK.GetRatesWithShipmentDetails.RateType ShipEngineSDK.GetRatesWithShipmentDetails.Rate.RateType.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Rate.RequestedComparisonAmount.get -> ShipEngineSDK.Common.MonetaryValue! +ShipEngineSDK.GetRatesWithShipmentDetails.Rate.RequestedComparisonAmount.get -> ShipEngineSDK.Common.MonetaryValue? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.RequestedComparisonAmount.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ServiceCode.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ServiceCode.set -> void @@ -930,15 +928,15 @@ ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ServiceType.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ServiceType.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ShipDate.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ShipDate.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ShippingAmount.get -> ShipEngineSDK.Common.MonetaryValue! +ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ShippingAmount.get -> ShipEngineSDK.Common.MonetaryValue? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ShippingAmount.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Rate.TaxAmount.get -> ShipEngineSDK.Common.MonetaryValue! +ShipEngineSDK.GetRatesWithShipmentDetails.Rate.TaxAmount.get -> ShipEngineSDK.Common.MonetaryValue? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.TaxAmount.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Rate.Trackable.get -> bool ShipEngineSDK.GetRatesWithShipmentDetails.Rate.Trackable.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ValidationStatus.get -> ShipEngineSDK.GetRatesWithShipmentDetails.ValidationStatus ShipEngineSDK.GetRatesWithShipmentDetails.Rate.ValidationStatus.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Rate.WarningMessages.get -> System.Collections.Generic.List! +ShipEngineSDK.GetRatesWithShipmentDetails.Rate.WarningMessages.get -> System.Collections.Generic.List? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.WarningMessages.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Rate.Zone.get -> int? ShipEngineSDK.GetRatesWithShipmentDetails.Rate.Zone.set -> void @@ -951,14 +949,14 @@ ShipEngineSDK.GetRatesWithShipmentDetails.RateOptions.RateOptions() -> void ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.CreatedAt.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.CreatedAt.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.Errors.get -> System.Collections.Generic.List! +ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.Errors.get -> System.Collections.Generic.List? ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.Errors.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.InvalidRates.get -> System.Collections.Generic.List! +ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.InvalidRates.get -> System.Collections.Generic.List? ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.InvalidRates.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.RateRequestId.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.RateRequestId.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.RateResponse() -> void -ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.Rates.get -> System.Collections.Generic.List! +ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.Rates.get -> System.Collections.Generic.List? ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.Rates.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.ShipmentId.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse.ShipmentId.set -> void @@ -973,7 +971,7 @@ ShipEngineSDK.GetRatesWithShipmentDetails.RateType ShipEngineSDK.GetRatesWithShipmentDetails.RateType.Check = 0 -> ShipEngineSDK.GetRatesWithShipmentDetails.RateType ShipEngineSDK.GetRatesWithShipmentDetails.RateType.Shipment = 1 -> ShipEngineSDK.GetRatesWithShipmentDetails.RateType ShipEngineSDK.GetRatesWithShipmentDetails.Result -ShipEngineSDK.GetRatesWithShipmentDetails.Result.AdvancedOptions.get -> ShipEngineSDK.Common.AdvancedShipmentOptions! +ShipEngineSDK.GetRatesWithShipmentDetails.Result.AdvancedOptions.get -> ShipEngineSDK.Common.AdvancedShipmentOptions? ShipEngineSDK.GetRatesWithShipmentDetails.Result.AdvancedOptions.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Result.CarrierId.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Result.CarrierId.set -> void @@ -981,7 +979,7 @@ ShipEngineSDK.GetRatesWithShipmentDetails.Result.Confirmation.get -> ShipEngineS ShipEngineSDK.GetRatesWithShipmentDetails.Result.Confirmation.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Result.CreatedAt.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Result.CreatedAt.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Result.Customs.get -> ShipEngineSDK.Common.Customs! +ShipEngineSDK.GetRatesWithShipmentDetails.Result.Customs.get -> ShipEngineSDK.Common.Customs? ShipEngineSDK.GetRatesWithShipmentDetails.Result.Customs.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Result.ExternalOrderId.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Result.ExternalOrderId.set -> void @@ -989,7 +987,7 @@ ShipEngineSDK.GetRatesWithShipmentDetails.Result.ExternalShipmentId.get -> strin ShipEngineSDK.GetRatesWithShipmentDetails.Result.ExternalShipmentId.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Result.InsuranceProvider.get -> ShipEngineSDK.Common.Enums.InsuranceProvider ShipEngineSDK.GetRatesWithShipmentDetails.Result.InsuranceProvider.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Result.Items.get -> System.Collections.Generic.List! +ShipEngineSDK.GetRatesWithShipmentDetails.Result.Items.get -> System.Collections.Generic.List? ShipEngineSDK.GetRatesWithShipmentDetails.Result.Items.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Result.ModifiedAt.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Result.ModifiedAt.set -> void @@ -997,34 +995,34 @@ ShipEngineSDK.GetRatesWithShipmentDetails.Result.OrderSourceCode.get -> ShipEngi ShipEngineSDK.GetRatesWithShipmentDetails.Result.OrderSourceCode.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Result.OriginType.get -> ShipEngineSDK.Common.Enums.OriginType ShipEngineSDK.GetRatesWithShipmentDetails.Result.OriginType.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Result.Packages.get -> System.Collections.Generic.List! +ShipEngineSDK.GetRatesWithShipmentDetails.Result.Packages.get -> System.Collections.Generic.List? ShipEngineSDK.GetRatesWithShipmentDetails.Result.Packages.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Result.RateResponse.get -> ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse! +ShipEngineSDK.GetRatesWithShipmentDetails.Result.RateResponse.get -> ShipEngineSDK.GetRatesWithShipmentDetails.RateResponse? ShipEngineSDK.GetRatesWithShipmentDetails.Result.RateResponse.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Result.Result() -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Result.ReturnTo.get -> ShipEngineSDK.Common.Address! +ShipEngineSDK.GetRatesWithShipmentDetails.Result.ReturnTo.get -> ShipEngineSDK.Common.Address? ShipEngineSDK.GetRatesWithShipmentDetails.Result.ReturnTo.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Result.ServiceCode.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Result.ServiceCode.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Result.ShipDate.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Result.ShipDate.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Result.ShipFrom.get -> ShipEngineSDK.Common.Address! +ShipEngineSDK.GetRatesWithShipmentDetails.Result.ShipFrom.get -> ShipEngineSDK.Common.Address? ShipEngineSDK.GetRatesWithShipmentDetails.Result.ShipFrom.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Result.ShipmentId.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Result.ShipmentId.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Result.ShipmentStatus.get -> ShipEngineSDK.GetRatesWithShipmentDetails.ShipmentStatus ShipEngineSDK.GetRatesWithShipmentDetails.Result.ShipmentStatus.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Result.ShipTo.get -> ShipEngineSDK.Common.Address! +ShipEngineSDK.GetRatesWithShipmentDetails.Result.ShipTo.get -> ShipEngineSDK.Common.Address? ShipEngineSDK.GetRatesWithShipmentDetails.Result.ShipTo.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Result.Tags.get -> System.Collections.Generic.List! +ShipEngineSDK.GetRatesWithShipmentDetails.Result.Tags.get -> System.Collections.Generic.List? ShipEngineSDK.GetRatesWithShipmentDetails.Result.Tags.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Result.TaxIdentifiers.get -> System.Collections.Generic.List! +ShipEngineSDK.GetRatesWithShipmentDetails.Result.TaxIdentifiers.get -> System.Collections.Generic.List? ShipEngineSDK.GetRatesWithShipmentDetails.Result.TaxIdentifiers.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Result.TotalWeight.get -> ShipEngineSDK.Common.Weight! +ShipEngineSDK.GetRatesWithShipmentDetails.Result.TotalWeight.get -> ShipEngineSDK.Common.Weight? ShipEngineSDK.GetRatesWithShipmentDetails.Result.TotalWeight.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Result.WarehouseId.get -> string? ShipEngineSDK.GetRatesWithShipmentDetails.Result.WarehouseId.set -> void -ShipEngineSDK.GetRatesWithShipmentDetails.Result.Weight.get -> ShipEngineSDK.Common.Weight! +ShipEngineSDK.GetRatesWithShipmentDetails.Result.Weight.get -> ShipEngineSDK.Common.Weight? ShipEngineSDK.GetRatesWithShipmentDetails.Result.Weight.set -> void ShipEngineSDK.GetRatesWithShipmentDetails.Shipment ShipEngineSDK.GetRatesWithShipmentDetails.Shipment.ComparisonRateType.get -> ShipEngineSDK.GetRatesWithShipmentDetails.ComparisonRateType? @@ -1050,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 @@ -1153,12 +1170,14 @@ ShipEngineSDK.ShipEngine.CreateLabelFromShipmentDetails(ShipEngineSDK.CreateLabe ShipEngineSDK.ShipEngine.CreateLabelFromShipmentDetails(ShipEngineSDK.CreateLabelFromShipmentDetails.Params! labelParams, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! ShipEngineSDK.ShipEngine.CreateManifest(ShipEngineSDK.Config! methodConfig, ShipEngineSDK.Manifests.Params! manifestParams) -> System.Threading.Tasks.Task! ShipEngineSDK.ShipEngine.CreateManifest(ShipEngineSDK.Manifests.Params! manifestParams) -> System.Threading.Tasks.Task! +ShipEngineSDK.ShipEngine.Dispose() -> void ShipEngineSDK.ShipEngine.GetRatesWithShipmentDetails(ShipEngineSDK.GetRatesWithShipmentDetails.Params! rateParams) -> System.Threading.Tasks.Task! ShipEngineSDK.ShipEngine.GetRatesWithShipmentDetails(ShipEngineSDK.GetRatesWithShipmentDetails.Params! rateParams, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! ShipEngineSDK.ShipEngine.ListCarriers() -> System.Threading.Tasks.Task! ShipEngineSDK.ShipEngine.ListCarriers(ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! ShipEngineSDK.ShipEngine.ShipEngine(ShipEngineSDK.Config! config) -> void ShipEngineSDK.ShipEngine.ShipEngine(string! apiKey) -> void +ShipEngineSDK.ShipEngine.ShipEngine(System.Net.Http.HttpClient! httpClient) -> void ShipEngineSDK.ShipEngine.TrackUsingCarrierCodeAndTrackingNumber(string! trackingNumber, string! carrierCode) -> System.Threading.Tasks.Task! ShipEngineSDK.ShipEngine.TrackUsingCarrierCodeAndTrackingNumber(string! trackingNumber, string! carrierCode, ShipEngineSDK.Config! methodConfig) -> System.Threading.Tasks.Task! ShipEngineSDK.ShipEngine.TrackUsingLabelId(string! labelId) -> System.Threading.Tasks.Task! @@ -1171,6 +1190,8 @@ ShipEngineSDK.ShipEngine._client -> System.Net.Http.HttpClient! ShipEngineSDK.ShipEngine._config -> ShipEngineSDK.Config! ShipEngineSDK.ShipEngineClient ShipEngineSDK.ShipEngineClient.ShipEngineClient() -> void +ShipEngineSDK.ShipEngineClient.CancellationToken.get -> System.Threading.CancellationToken +ShipEngineSDK.ShipEngineClient.CancellationToken.set -> void ShipEngineSDK.ShipEngineException ShipEngineSDK.ShipEngineException.ErrorCode.get -> ShipEngineSDK.ErrorCode ShipEngineSDK.ShipEngineException.ErrorCode.set -> void @@ -1179,7 +1200,12 @@ ShipEngineSDK.ShipEngineException.ErrorSource.set -> void ShipEngineSDK.ShipEngineException.ErrorType.get -> ShipEngineSDK.ErrorType ShipEngineSDK.ShipEngineException.ErrorType.set -> void ShipEngineSDK.ShipEngineException.RequestId.get -> string? -ShipEngineSDK.ShipEngineException.ShipEngineException(string! message, ShipEngineSDK.ErrorSource errorSource = ShipEngineSDK.ErrorSource.Shipengine, ShipEngineSDK.ErrorType errorType = ShipEngineSDK.ErrorType.System, ShipEngineSDK.ErrorCode errorCode = ShipEngineSDK.ErrorCode.Unspecified, string! requestID = null) -> void +ShipEngineSDK.ShipEngineException.ResponseMessage.get -> System.Net.Http.HttpResponseMessage? +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, string? requestID = null, System.Net.Http.HttpResponseMessage? responseMessage = 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 @@ -1285,11 +1311,32 @@ ShipEngineSDK.ValidateAddresses.ValidationMessageType.Warning = 1 -> ShipEngineS ShipEngineSDK.VoidLabelWithLabelId.Result ShipEngineSDK.VoidLabelWithLabelId.Result.Approved.get -> bool ShipEngineSDK.VoidLabelWithLabelId.Result.Approved.set -> void -ShipEngineSDK.VoidLabelWithLabelId.Result.Message.get -> string! +ShipEngineSDK.VoidLabelWithLabelId.Result.Message.get -> string? ShipEngineSDK.VoidLabelWithLabelId.Result.Message.set -> void ShipEngineSDK.VoidLabelWithLabelId.Result.Result() -> void +static readonly ShipEngineSDK.ShipEngineClient.JsonSerializerOptions -> System.Text.Json.JsonSerializerOptions! static ShipEngineSDK.ShipEngineClient.ConfigureHttpClient(ShipEngineSDK.Config! config, System.Net.Http.HttpClient! client) -> System.Net.Http.HttpClient! +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/PublicAPI.Unshipped.txt b/ShipEngine/PublicAPI.Unshipped.txt index f032bb52..5f282702 100644 --- a/ShipEngine/PublicAPI.Unshipped.txt +++ b/ShipEngine/PublicAPI.Unshipped.txt @@ -1,3 +1 @@ -override ShipEngineSDK.Common.MonetaryValueConverter.Read(ref System.Text.Json.Utf8JsonReader reader, System.Type! type, System.Text.Json.JsonSerializerOptions! options) -> ShipEngineSDK.Common.MonetaryValue! -override ShipEngineSDK.Common.MonetaryValueConverter.Write(System.Text.Json.Utf8JsonWriter! writer, ShipEngineSDK.Common.MonetaryValue! value, System.Text.Json.JsonSerializerOptions! options) -> void -readonly ShipEngineSDK.ShipEngineClient.JsonSerializerOptions -> System.Text.Json.JsonSerializerOptions! \ No newline at end of file + \ No newline at end of file diff --git a/ShipEngine/ShipEngine.cs b/ShipEngine/ShipEngine.cs index 0d3fa593..c6da51cb 100644 --- a/ShipEngine/ShipEngine.cs +++ b/ShipEngine/ShipEngine.cs @@ -1,16 +1,381 @@ -using ShipEngineSDK.Common; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Result = ShipEngineSDK.ValidateAddresses.Result; +using ShipEngineSDK.Common; +using ShipEngineSDK.Manifests; +using System; using System.Collections.Generic; using System.Net.Http; using System.Text.Json; -using System.Text.Json.Serialization; using System.Threading.Tasks; 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 + /// + public static class ShipEngineExtensions + { + /// + /// Adds ShipEngine to the host builder and configures the client. + /// + /// + /// + /// + public static IHostApplicationBuilder AddShipEngine(this IHostApplicationBuilder builder, Action? configureClient = null) + { + builder.Services.AddHttpClient(c => + { + var baseUri = builder.Configuration["ShipEngine:BaseUrl"] ?? "https://api.shipengine.com"; + var apiKey = builder.Configuration["ShipEngine:ApiKey"] ?? ""; + ShipEngineClient.ConfigureHttpClient(c, apiKey, new Uri(baseUri)); + configureClient?.Invoke(c); + }); + + return builder; + } + } + /// /// Contains methods for interacting with the ShipEngine API. /// - public class ShipEngine : ShipEngineClient + public class ShipEngine : ShipEngineClient, IDisposable, IShipEngine { /// /// Global HttpClient for ShipEngine instance. @@ -28,9 +393,8 @@ public class ShipEngine : ShipEngineClient /// Api Key associated with the ShipEngine account you want to use public ShipEngine(string apiKey) : base() { - var client = new HttpClient(); _config = new Config(apiKey); - _client = ConfigureHttpClient(_config, client); + _client = ConfigureHttpClient(_config, new HttpClient()); } /// @@ -39,9 +403,25 @@ public ShipEngine(string apiKey) : base() /// Config object containing custom configurations public ShipEngine(Config config) : base() { - var client = new HttpClient(); this._config = config; - _client = ConfigureHttpClient(config, client); + _client = ConfigureHttpClient(config, new HttpClient()); + } + + /// + /// Initialize the ShipEngine SDK with an httpClient object + /// + /// HttpClient object to be used for ShipEngine API calls. We expect the httpClient has already been configured with ConfigureHttpClient + public ShipEngine(HttpClient httpClient) : base() + { + _client = httpClient; + } + + /// + /// Dispose of the ShipEngine client + /// + public void Dispose() + { + _client.Dispose(); } /// diff --git a/ShipEngine/ShipEngine.csproj b/ShipEngine/ShipEngine.csproj index ae9602f4..c035973b 100644 --- a/ShipEngine/ShipEngine.csproj +++ b/ShipEngine/ShipEngine.csproj @@ -4,7 +4,7 @@ ShipEngine sdk;rest;api;shipping;rates;label;tracking;cost;address;validation;normalization;fedex;ups;usps; - 2.0.1 + 2.0.2 ShipEngine ShipEngine The official ShipEngine C# SDK for .NET @@ -28,9 +28,12 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + + - + diff --git a/ShipEngine/ShipEngineClient.cs b/ShipEngine/ShipEngineClient.cs index b32400ef..b6a25afb 100644 --- a/ShipEngine/ShipEngineClient.cs +++ b/ShipEngine/ShipEngineClient.cs @@ -6,6 +6,7 @@ using System.Net.Http.Headers; using System.Text.Json; using System.Text.Json.Serialization; +using System.Threading; using System.Threading.Tasks; namespace ShipEngineSDK @@ -21,25 +22,22 @@ public class ShipEngineClient /// Options for serializing the method call params to JSON. /// A separate inline setting is used for deserializing the response /// - protected readonly JsonSerializerOptions JsonSerializerOptions; - - /// - /// Constructor for ShipEngineClient - /// - public ShipEngineClient() + protected static readonly JsonSerializerOptions JsonSerializerOptions = new JsonSerializerOptions { - JsonSerializerOptions = new JsonSerializerOptions - { - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, - PropertyNameCaseInsensitive = true, - WriteIndented = true, - Converters = { new JsonStringEnumMemberConverter() } - }; - } + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, + PropertyNameCaseInsensitive = true, + WriteIndented = true, + Converters = { new JsonStringEnumMemberConverter() } + }; private const string JsonMediaType = "application/json"; + /// + /// Token to cancel the request + /// + public CancellationToken CancellationToken { get; set; } + /// /// Sets the HttpClient User agent, the json media type, and the API key to be used /// for all ShipEngine API calls unless overrwritten at the method level. @@ -71,9 +69,24 @@ public static HttpClient ConfigureHttpClient(Config config, HttpClient client) return client; } - private async Task DeserializedResultOrThrow(HttpResponseMessage response) + /// + /// Sets the HttpClient User agent, the json media type, and the API key to be used + /// for all ShipEngine API calls unless overwritten at the method level. + /// + /// The HttpClient to be configured + /// The API key to be used for all ShipEngine API calls + /// The base URI for the ShipEngine API + /// The timeout for the ShipEngine API Calls + /// + public static HttpClient ConfigureHttpClient(HttpClient client, string apiKey, Uri? baseUri, TimeSpan? timeout = null) { + var config = new Config(apiKey, timeout); + client.BaseAddress = baseUri ?? new Uri("https://api.shipengine.com"); + return ConfigureHttpClient(config, client); + } + private async Task DeserializedResultOrThrow(HttpResponseMessage response) + { var contentString = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) @@ -95,7 +108,8 @@ private async Task DeserializedResultOrThrow(HttpResponseMessage response) error.ErrorSource, error.ErrorType, error.ErrorCode, - deserializedError.RequestId + deserializedError.RequestId, + response ); } @@ -127,14 +141,14 @@ public virtual async Task SendHttpRequestAsync(HttpMethod method, string p { int retry = 0; - HttpResponseMessage response = null; + HttpResponseMessage? response = null; ShipEngineException requestException; while (true) { try { var request = BuildRequest(method, path, jsonContent); - var streamTask = client.SendAsync(request); + var streamTask = client.SendAsync(request, CancellationToken); response = await streamTask; var deserializedResult = await DeserializedResultOrThrow(response); @@ -176,7 +190,7 @@ public virtual async Task SendHttpRequestAsync(HttpMethod method, string p } } - private async Task WaitAndRetry(HttpResponseMessage response, Config config, ShipEngineException ex) + private async Task WaitAndRetry(HttpResponseMessage? response, Config config, ShipEngineException ex) { int? retryAfter; @@ -196,14 +210,15 @@ private async Task WaitAndRetry(HttpResponseMessage response, Config config, Shi ErrorSource.Shipengine, ErrorType.System, ErrorCode.Timeout, - ex.RequestId + ex.RequestId, + ex.ResponseMessage ); } - await Task.Delay((int)retryAfter * 1000).ConfigureAwait(false); + await Task.Delay((int)retryAfter * 1000, CancellationToken).ConfigureAwait(false); } - private HttpRequestMessage BuildRequest(HttpMethod method, string path, string? jsonContent) + private static HttpRequestMessage BuildRequest(HttpMethod method, string path, string? jsonContent) { var request = new HttpRequestMessage(method, path); @@ -215,7 +230,7 @@ private HttpRequestMessage BuildRequest(HttpMethod method, string path, string? return request; } - private bool ShouldRetry( + private static bool ShouldRetry( int numRetries, HttpStatusCode? statusCode, HttpHeaders? headers,