Skip to content

Commit

Permalink
Merge pull request #47 from easykeys/fedex/restapi/shippingprovider
Browse files Browse the repository at this point in the history
Fedex/restapi/shippingprovider
  • Loading branch information
ucrengineer committed May 15, 2024
2 parents a76d7da + 905444f commit 1052186
Show file tree
Hide file tree
Showing 17 changed files with 525 additions and 91 deletions.
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mode: Mainline
next-version: 4.2.0
next-version: 4.3.0
branches:
feature:
tag: preview
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EasyKeys.Shipping.FedEx.Abstractions.Middleware;
using EasyKeys.Shipping.FedEx.Abstractions.OpenApis.V1.AddressValidation;
using EasyKeys.Shipping.FedEx.Abstractions.OpenApis.V1.AddressValidation;
using EasyKeys.Shipping.FedEx.Abstractions.OpenApis.V1.Authorization;
using EasyKeys.Shipping.FedEx.Abstractions.OpenApis.V1.RatesAndTransitTimes;
using EasyKeys.Shipping.FedEx.Abstractions.OpenApis.V1.Ship;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using EasyKeys.Shipping.FedEx.Abstractions.Options;
using System.IO.Compression;

using EasyKeys.Shipping.FedEx.Abstractions.Options;

using Microsoft.Extensions.Options;

using Newtonsoft.Json;

//----------------------
// <auto-generated>
// Generated using the NSwag toolchain v13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
Expand Down Expand Up @@ -285,6 +289,27 @@ protected virtual async System.Threading.Tasks.Task<ObjectResponseResult<T>> Rea
throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception);
}
}
if (response.Content.Headers.ContentEncoding.Contains("gzip"))
{
try
{
using var responseStream = await response.Content.ReadAsStreamAsync();
using var decompressionStream = new GZipStream(responseStream, CompressionMode.Decompress);
using var decompressedStream = new StreamReader(decompressionStream);
var jsonString = await decompressedStream.ReadToEndAsync();
var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings);
using var jsonReader = new JsonTextReader(decompressedStream);
var jsonObject = serializer.Deserialize<T>(jsonReader);
#pragma warning disable CS8604 // Possible null reference argument.
return new ObjectResponseResult<T>(jsonObject, jsonString);
#pragma warning restore CS8604 // Possible null reference argument.
}
catch (Newtonsoft.Json.JsonException exception)
{
var message = "Could not deserialize the response body stream as " + typeof(T).FullName + ".";
throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception);
}
}
else
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
#pragma warning disable 8603 // Disable "CS8603 Possible null reference return"
namespace EasyKeys.Shipping.FedEx.Abstractions.OpenApis.V1.Authorization;

using System.IO.Compression;

using EasyKeys.Shipping.FedEx.Abstractions.Options;

using Microsoft.Extensions.Options;

using Newtonsoft.Json;

using System = global::System;

[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
Expand Down Expand Up @@ -221,6 +225,27 @@ protected virtual async System.Threading.Tasks.Task<ObjectResponseResult<T>> Rea
throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception);
}
}
if (response.Content.Headers.ContentEncoding.Contains("gzip"))
{
try
{
using var responseStream = await response.Content.ReadAsStreamAsync();
using var decompressionStream = new GZipStream(responseStream, CompressionMode.Decompress);
using var decompressedStream = new StreamReader(decompressionStream);
var jsonString = await decompressedStream.ReadToEndAsync();
var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings);
using var jsonReader = new JsonTextReader(decompressedStream);
var jsonObject = serializer.Deserialize<T>(jsonReader);
#pragma warning disable CS8604 // Possible null reference argument.
return new ObjectResponseResult<T>(jsonObject, jsonString);
#pragma warning restore CS8604 // Possible null reference argument.
}
catch (Newtonsoft.Json.JsonException exception)
{
var message = "Could not deserialize the response body stream as " + typeof(T).FullName + ".";
throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception);
}
}
else
{
try
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using System.IO.Compression;
using System.IO.Compression;

using EasyKeys.Shipping.FedEx.Abstractions.Options;

Expand Down Expand Up @@ -312,9 +311,9 @@ protected virtual async System.Threading.Tasks.Task<ObjectResponseResult<T>> Rea
var jsonString = await decompressedStream.ReadToEndAsync();
var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings);
using var jsonReader = new JsonTextReader(decompressedStream);
var errorResponse = serializer.Deserialize<T>(jsonReader);
var jsonObject = serializer.Deserialize<T>(jsonReader);
#pragma warning disable CS8604 // Possible null reference argument.
return new ObjectResponseResult<T>(errorResponse, jsonString);
return new ObjectResponseResult<T>(jsonObject, jsonString);
#pragma warning restore CS8604 // Possible null reference argument.
}
catch (Newtonsoft.Json.JsonException exception)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using EasyKeys.Shipping.FedEx.Abstractions.OpenApis.V1.Authorization;
using System.IO.Compression;

using EasyKeys.Shipping.FedEx.Abstractions.OpenApis.V1.Authorization;
using EasyKeys.Shipping.FedEx.Abstractions.Options;

using Microsoft.Extensions.Options;

using Newtonsoft.Json;

//----------------------
// <auto-generated>
// Generated using the NSwag toolchain v13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
Expand All @@ -28,7 +32,7 @@ public partial class ShipApi
private System.Net.Http.HttpClient _httpClient;
private System.Lazy<Newtonsoft.Json.JsonSerializerSettings> _settings;

public ShipApi(IOptionsMonitor<FedExOptions> options, System.Net.Http.HttpClient httpClient)
public ShipApi(IOptionsMonitor<FedExApiOptions> options, System.Net.Http.HttpClient httpClient)
{
_baseUrl = options.CurrentValue.Url;
_httpClient = httpClient;
Expand Down Expand Up @@ -1116,6 +1120,27 @@ protected virtual async System.Threading.Tasks.Task<ObjectResponseResult<T>> Rea
throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception);
}
}
if (response.Content.Headers.ContentEncoding.Contains("gzip"))
{
try
{
using var responseStream = await response.Content.ReadAsStreamAsync();
using var decompressionStream = new GZipStream(responseStream, CompressionMode.Decompress);
using var decompressedStream = new StreamReader(decompressionStream);
var jsonString = await decompressedStream.ReadToEndAsync();
var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings);
using var jsonReader = new JsonTextReader(decompressedStream);
var jsonObject = serializer.Deserialize<T>(jsonReader);
#pragma warning disable CS8604 // Possible null reference argument.
return new ObjectResponseResult<T>(jsonObject, jsonString);
#pragma warning restore CS8604 // Possible null reference argument.
}
catch (Newtonsoft.Json.JsonException exception)
{
var message = "Could not deserialize the response body stream as " + typeof(T).FullName + ".";
throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception);
}
}
else
{
try
Expand Down Expand Up @@ -1196,7 +1221,7 @@ public partial class Full_Schema_Ship
/// </summary>
[Newtonsoft.Json.JsonProperty("mergeLabelDocOption", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public Full_Schema_ShipMergeLabelDocOption MergeLabelDocOption { get; set; }
public Full_Schema_ShipMergeLabelDocOption? MergeLabelDocOption { get; set; }

[Newtonsoft.Json.JsonProperty("requestedShipment", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required]
Expand All @@ -1213,17 +1238,17 @@ public partial class Full_Schema_Ship

[Newtonsoft.Json.JsonProperty("shipAction", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public OpenShipmentAction ShipAction { get; set; }
public OpenShipmentAction? ShipAction { get; set; }

[Newtonsoft.Json.JsonProperty("processingOptionType", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public AsynchronousProcessingOptionType_1 ProcessingOptionType { get; set; }
public AsynchronousProcessingOptionType_1? ProcessingOptionType { get; set; }

/// <summary>
/// This flag is used to specify if the shipment is singleshot mps or one Label at a time, piece by piece shipment. Default is false. If true, one label at a time is processed.
/// </summary>
[Newtonsoft.Json.JsonProperty("oneLabelAtATime", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public bool OneLabelAtATime { get; set; }
public bool? OneLabelAtATime { get; set; }

private System.Collections.Generic.IDictionary<string, object>? _additionalProperties;

Expand Down Expand Up @@ -2801,7 +2826,7 @@ public System.Collections.Generic.IDictionary<string, object> AdditionalProperti
}

/// <summary>
/// These are Special service elements for FedEx Ground Home Delivery shipments. If selected, element homedeliveryPremiumType is mandatory.
/// These are Special service elements for FedEx Ground Home Delivery shipments. If selected, element homedeliveryPremiumType is mandatory.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class HomeDeliveryPremiumDetail
Expand Down Expand Up @@ -3086,7 +3111,7 @@ public partial class CustomsClearanceDetail
/// </summary>
[Newtonsoft.Json.JsonProperty("freightOnValue", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public CustomsClearanceDetailFreightOnValue FreightOnValue { get; set; }
public CustomsClearanceDetailFreightOnValue? FreightOnValue { get; set; }

[Newtonsoft.Json.JsonProperty("dutiesPayment", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public Payment_1? DutiesPayment { get; set; }
Expand Down Expand Up @@ -3374,7 +3399,7 @@ public System.Collections.Generic.IDictionary<string, object> AdditionalProperti
}

/// <summary>
/// Information about the person who is paying for the shipment. Not applicable for credit card payment.
/// Information about the person who is paying for the shipment. Not applicable for credit card payment.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class Payor_1
Expand Down Expand Up @@ -3870,7 +3895,7 @@ public System.Collections.Generic.IDictionary<string, object> AdditionalProperti
}

/// <summary>
/// Specifies about the statements to be declared for Customs.
/// Specifies about the statements to be declared for Customs.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class CustomsDeclarationStatementDetail
Expand Down Expand Up @@ -5330,7 +5355,7 @@ public System.Collections.Generic.IDictionary<string, object> AdditionalProperti
public partial class AlcoholDetail
{
/// <summary>
/// Specify the Alcohol Recipient Type of the shipment. &lt;br&gt; Example: LICENSEE
/// Specify the Alcohol Recipient Type of the shipment. &lt;br&gt; Example: LICENSEE
/// </summary>
[Newtonsoft.Json.JsonProperty("alcoholRecipientType", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
Expand Down Expand Up @@ -5702,7 +5727,7 @@ public partial class LabelResponseVO
/// Specifies if the document is encoded.&lt;br&gt;Example: encoded label
/// </summary>
[Newtonsoft.Json.JsonProperty("encodedLabel", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? EncodedLabel { get; set; }
public byte[] EncodedLabel { get; set; }

Check warning on line 5730 in src/EasyKeys.Shipping.FedEx.Abstractions/OpenApis/V1/Ship/ShipApi.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'EncodedLabel' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

/// <summary>
/// The URL of the shipping document/label&lt;br&gt;Example: https://.../document/v2/document/retrieve/SH,794816968200_Merge/isLabel=true&amp;autoPrint=false&lt;br&gt;&lt;i&gt;Note: The URL once created will be active for 24 hours.&lt;/i&gt;
Expand Down Expand Up @@ -6671,7 +6696,7 @@ public partial class HazardousCommodityOptionDetail01
public HazardousCommodityOptionDetail01LabelTextOption LabelTextOption { get; set; }

/// <summary>
/// 'DG Data Upload Mode:- Optional.,DG Full Validation Mode:- Optional,Text used in labeling the commodity under control of the LabelTextOption field&lt;br&gt;Example:Customer Supplied Label Text'
/// 'DG Data Upload Mode:- Optional.,DG Full Validation Mode:- Optional,Text used in labeling the commodity under control of the LabelTextOption field&lt;br&gt;Example:Customer Supplied Label Text'
/// <br/>
/// <br/>
/// </summary>
Expand Down Expand Up @@ -8858,7 +8883,7 @@ public System.Collections.Generic.IDictionary<string, object> AdditionalProperti
}

/// <summary>
/// The request elements required to cancel a shipment.
/// The request elements required to cancel a shipment.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class Full_Schema_Cancel_Shipment
Expand Down Expand Up @@ -9362,7 +9387,7 @@ public partial class RequestedShipmentVerify
public ShippingDocumentSpecification? ShippingDocumentSpecification { get; set; }

/// <summary>
/// Indicate the type of rates to be returned.&lt;br&gt;Following are values:&lt;ul&gt;&lt;li&gt;LIST - Returns published list rates will be returned in addition to account-specific rate (if applicable).&lt;/li&gt;&lt;li&gt;PREFERRED - It returns rates in currency as specified in the PreferredCurrency element.&lt;/li&gt;&lt;li&gt;ACCOUNT - Returns account specific rates. Note: The account specific rates are returned by default if the shipper account number is specified in the shipment.&lt;/li&gt;&lt;li&gt;INCENTIVE - This is one-time discount for incentivizing the customer.&lt;/li&gt;&lt;/ul&gt;Examples: ["ACCOUNT", "PREFERRED"]
/// Indicate the type of rates to be returned.&lt;br&gt;Following are values:&lt;ul&gt;&lt;li&gt;LIST - Returns published list rates will be returned in addition to account-specific rate (if applicable).&lt;/li&gt;&lt;li&gt;PREFERRED - It returns rates in currency as specified in the PreferredCurrency element.&lt;/li&gt;&lt;li&gt;ACCOUNT - Returns account specific rates. Note: The account specific rates are returned by default if the shipper account number is specified in the shipment.&lt;/li&gt;&lt;li&gt;INCENTIVE - This is one-time discount for incentivizing the customer.&lt;/li&gt;&lt;/ul&gt;Examples: ["ACCOUNT", "PREFERRED"]
/// </summary>
[Newtonsoft.Json.JsonProperty("rateRequestType", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ItemConverterType = typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public System.Collections.Generic.ICollection<RateRequestType2>? RateRequestType { get; set; }
Expand Down Expand Up @@ -10839,6 +10864,8 @@ public enum WeightUnits

[System.Runtime.Serialization.EnumMember(Value = @"KG")]
KG = 0,
[System.Runtime.Serialization.EnumMember(Value = @"LB")]
LB = 1

}

Expand All @@ -10848,6 +10875,8 @@ public enum Weight_4Units

[System.Runtime.Serialization.EnumMember(Value = @"KG")]
KG = 0,
[System.Runtime.Serialization.EnumMember(Value = @"LB")]
LB = 1

}

Expand Down Expand Up @@ -11824,6 +11853,9 @@ public enum LabelResponseVOContentType
[System.Runtime.Serialization.EnumMember(Value = @"MERGED_LABELS_ONLY")]
MERGED_LABELS_ONLY = 15,

[System.Runtime.Serialization.EnumMember(Value = @"TERMS_AND_CONDITIONS")]
TERMS_AND_CONDITIONS = 16,

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.Text.Json;
using System.Text.Json.Serialization;

using Newtonsoft.Json;
using Newtonsoft.Json;

namespace EasyKeys.Shipping.FedEx.Abstractions.Options;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EasyKeys.Shipping.Abstractions;
using EasyKeys.Shipping.FedEx.Abstractions.Middleware;
using EasyKeys.Shipping.FedEx.Abstractions.Options;
using EasyKeys.Shipping.FedEx.AddressValidation;

Expand All @@ -18,7 +17,7 @@ public static class AddressValidationServiceExtensions
/// <param name="sectionName">The section name for the configuration. The default is <see cref="FedExOptions"/>.</param>
/// <param name="configOptions">The configuration for the <see cref="FedExOptions"/>. The default is null.</param>
/// <returns></returns>
public static IServiceCollection AddWebServicesFedExAddressValidation(
public static IServiceCollection AddWebServicesFedExAddressValidationProvider(
this IServiceCollection services,
string sectionName = nameof(FedExOptions),
Action<FedExOptions, IServiceProvider>? configOptions = null)
Expand All @@ -45,7 +44,7 @@ public static IServiceCollection AddWebServicesFedExAddressValidation(
/// <param name="sectionName"></param>
/// <param name="configOptions"></param>
/// <returns></returns>
public static IServiceCollection AddRestApiFedExAddressValidation(
public static IServiceCollection AddRestApiFedExAddressValidationProvider(
this IServiceCollection services,
string sectionName = nameof(FedExApiOptions),
Action<FedExApiOptions, IServiceProvider>? configOptions = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class ConsoleServiceCollectionExtensions
public static void ConfigureServices(HostBuilderContext hostBuilder, IServiceCollection services)
{
services.AddScoped<IMain, Main>();
services.AddWebServicesFedExAddressValidation();
services.AddWebServicesFedExAddressValidationProvider();
services.AddWebServicesFedExRateProvider();
services.AddFedExShipmenProvider();
services.AddFedExTrackingProvider();
Expand Down
Loading

0 comments on commit 1052186

Please sign in to comment.