Skip to content

Commit

Permalink
Merge pull request #93 from ShipEngine/jpill/include-http-response-wi…
Browse files Browse the repository at this point in the history
…th-error

feat: initialize SDK with httpClient, add HttpResponseMessage to Exception
  • Loading branch information
jpill authored Jun 28, 2024
2 parents f20d97c + 55261e5 commit 561e3af
Show file tree
Hide file tree
Showing 13 changed files with 578 additions and 116 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
2 changes: 1 addition & 1 deletion ShipEngine/Models/Dto/Common/Customs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Customs
/// <summary>
/// Customs declarations for each item in the shipment.
/// </summary>
public List<CustomsItem> CustomsItems { get; set; }
public List<CustomsItem>? CustomsItems { get; set; }
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion ShipEngine/Models/Dto/CreateLabelFromRate/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public class Result
/// <summary>
/// The label's package(s).
/// </summary>
public List<Package> Packages { get; set; }
public List<Package>? Packages { get; set; }
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public class Result
/// <summary>
/// The label's package(s).
/// </summary>
public List<LabelPackage> Packages { get; set; }
public List<LabelPackage>? Packages { get; set; }
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions ShipEngine/Models/Dto/GetRatesFromShipmentDetails/Params.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public class Shipment
/// </summary>
public Weight Weight { get; set; }

/// <summary>
/// The type of comparison rate
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
public ComparisonRateType? ComparisonRateType { get; set; }

Expand Down
57 changes: 32 additions & 25 deletions ShipEngine/Models/Dto/GetRatesFromShipmentDetails/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace ShipEngineSDK.GetRatesWithShipmentDetails
{
/// <summary>
/// Get rates with shipment details result
/// </summary>
public class Result
{
/// <summary>
Expand All @@ -29,12 +32,12 @@ public class Result
/// <summary>
/// Describe the packages included in this shipment as related to potential metadata that was imported from external order sources
/// </summary>
public List<ShipmentItem> Items { get; set; }
public List<ShipmentItem>? Items { get; set; }

/// <summary>
/// Tax identifiers
/// </summary>
public List<TaxIdentifier> TaxIdentifiers { get; set; }
public List<TaxIdentifier>? TaxIdentifiers { get; set; }

/// <summary>
/// You can optionally use this field to store your own identifier for this shipment.
Expand Down Expand Up @@ -64,13 +67,13 @@ public class Result
/// <summary>
/// The recipient's mailing address
/// </summary>
public Address ShipTo { get; set; }
public Address? ShipTo { get; set; }

/// <summary>
/// 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.
/// </summary>
public Address ShipFrom { get; set; }
public Address? ShipFrom { get; set; }

/// <summary>
/// The warehouse that the shipment is being shipped from. Either warehouse_id or ship_from must be specified.
Expand All @@ -80,7 +83,7 @@ public class Result
/// <summary>
/// The return address for this shipment. Defaults to the ship_from address.
/// </summary>
public Address ReturnTo { get; set; }
public Address? ReturnTo { get; set; }

/// <summary>
/// The type of delivery confirmation that is required for this shipment.
Expand All @@ -90,12 +93,12 @@ public class Result
/// <summary>
/// Customs information. This is usually only needed for international shipments.
/// </summary>
public Customs Customs { get; set; }
public Customs? Customs { get; set; }

/// <summary>
/// Advanced shipment options. These are entirely optional.
/// </summary>
public AdvancedShipmentOptions AdvancedOptions { get; set; }
public AdvancedShipmentOptions? AdvancedOptions { get; set; }

/// <summary>
/// Indicates if the package will be picked up or dropped off by the carrier
Expand All @@ -110,13 +113,13 @@ public class Result
/// <summary>
/// Arbitrary tags associated with this shipment. Tags can be used to categorize shipments, and shipments can be queried by their tags.
/// </summary>
public List<string> Tags { get; set; }
public List<string>? Tags { get; set; }


/// <summary>
/// Total Weight of the Shipment
/// </summary>
public Weight TotalWeight { get; set; }
public Weight? TotalWeight { get; set; }

/// <summary>
/// The order sources that are supported by ShipEngine
Expand All @@ -126,30 +129,33 @@ public class Result
/// <summary>
/// The packages in the shipment.
/// </summary>
public List<ShipmentPackage> Packages { get; set; }
public List<ShipmentPackage>? Packages { get; set; }

/// <summary>
/// The combined weight of all packages in the shipment
/// </summary>
public Weight Weight { get; set; }
public Weight? Weight { get; set; }

/// <summary>
/// The rate responses
/// </summary>
public RateResponse RateResponse { get; set; }
public RateResponse? RateResponse { get; set; }
}

/// <summary>
/// The get rates with shipment details rate response
/// </summary>
public class RateResponse
{
/// <summary>
/// A list of shipment rates
/// </summary>
public List<Rate> Rates { get; set; }
public List<Rate>? Rates { get; set; }

/// <summary>
/// A list of invalid shipment rates
/// </summary>
public List<Rate> InvalidRates { get; set; }
public List<Rate>? InvalidRates { get; set; }

/// <summary>
/// A string that uniquely identifies the rate request
Expand All @@ -174,9 +180,12 @@ public class RateResponse
/// <summary>
/// Any errors associated with the rate request
/// </summary>
public List<ShipEngineException> Errors { get; set; }
public List<ShipEngineException>? Errors { get; set; }
}

/// <summary>
/// The individual rate
/// </summary>
public class Rate
{
/// <summary>
Expand All @@ -197,33 +206,31 @@ public class Rate
/// <summary>
/// The shipping amount
/// </summary>
public MonetaryValue ShippingAmount { get; set; }
public MonetaryValue? ShippingAmount { get; set; }

/// <summary>
/// The insurance amount
/// </summary>
public MonetaryValue InsuranceAmount { get; set; }
public MonetaryValue? InsuranceAmount { get; set; }

/// <summary>
/// The sum of the carrier costs for the shipment
/// </summary>
public MonetaryValue RequestedComparisonAmount { get; set; }


public MonetaryValue? RequestedComparisonAmount { get; set; }

/// <summary>
/// The confirmation amount
/// </summary>
public MonetaryValue ConfirmationAmount { get; set; }
public MonetaryValue? ConfirmationAmount { get; set; }

/// <summary>
/// Any other charges associated with this rate
/// </summary>
public MonetaryValue OtherAmount { get; set; }
public MonetaryValue? OtherAmount { get; set; }
/// <summary>
/// Tariff and additional taxes associated with an international shipment.
/// </summary>
public MonetaryValue TaxAmount { get; set; }
public MonetaryValue? TaxAmount { get; set; }

/// <summary>
/// Certain carriers base their rates off of custom zones that vary depending upon
Expand Down Expand Up @@ -306,11 +313,11 @@ public class Rate
/// <summary>
/// The warning messages
/// </summary>
public List<string> WarningMessages { get; set; }
public List<string>? WarningMessages { get; set; }

/// <summary>
/// The error messages
/// </summary>
public List<string> ErrorMessages { get; set; }
public List<string>? ErrorMessages { get; set; }
}
}
2 changes: 1 addition & 1 deletion ShipEngine/Models/Dto/VoidLabelWithLabelId/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class Result
/// <summary>
/// Message associated with the result of the void label attempt
/// </summary>
public string Message { get; set; }
public string? Message { get; set; }
}
}
35 changes: 17 additions & 18 deletions ShipEngine/Models/ShipEngineException.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
#pragma warning disable 1591

using System;
using System.Net.Http;

namespace ShipEngineSDK
{
/// <summary>
/// Error object returned from failed method calls
/// </summary>
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)
{
/// <summary>
/// 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
/// </summary>

public string? RequestId { get; }
public string? RequestId { get; } = requestID;

/// <summary>
/// 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.
/// </summary>
public ErrorSource ErrorSource { get; set; }
public ErrorSource ErrorSource { get; set; } = errorSource;

/// <summary>
/// The type of error
/// </summary>
public ErrorType ErrorType { get; set; }
public ErrorType ErrorType { get; set; } = errorType;

/// <summary>
/// The error code specified for the failed API Call
/// </summary>
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;
}
/// <summary>
/// The http response message returned from the failed API call
/// </summary>
public HttpResponseMessage? ResponseMessage { get; set; } = responseMessage;
}
}
Loading

0 comments on commit 561e3af

Please sign in to comment.