From 3d6ff215326464ee7193a895b36731b66509eb45 Mon Sep 17 00:00:00 2001 From: Nate Harris Date: Wed, 29 Nov 2023 16:07:43 -0700 Subject: [PATCH] [chore] Open internal methods (#525) - Make base GetNextPage public - Make RequestAsync public - Make BuildNextPageParameters public --- EasyPost.Integration/Extensions.cs | 26 +++++++++++++++++++ EasyPost/Models/API/Address.cs | 2 +- EasyPost/Models/API/Batch.cs | 2 +- EasyPost/Models/API/EndShipper.cs | 2 +- EasyPost/Models/API/Event.cs | 2 +- EasyPost/Models/API/Insurance.cs | 2 +- EasyPost/Models/API/Pickup.cs | 2 +- EasyPost/Models/API/ReferralCustomer.cs | 2 +- EasyPost/Models/API/Refund.cs | 2 +- EasyPost/Models/API/Report.cs | 2 +- EasyPost/Models/API/ScanForm.cs | 2 +- EasyPost/Models/API/Shipment.cs | 2 +- EasyPost/Models/API/Tracker.cs | 2 +- EasyPost/Models/Shared/PaginatedCollection.cs | 8 +++--- EasyPost/_base/EasyPostClient.cs | 4 +-- 15 files changed, 44 insertions(+), 18 deletions(-) create mode 100644 EasyPost.Integration/Extensions.cs diff --git a/EasyPost.Integration/Extensions.cs b/EasyPost.Integration/Extensions.cs new file mode 100644 index 000000000..2005d7ca0 --- /dev/null +++ b/EasyPost.Integration/Extensions.cs @@ -0,0 +1,26 @@ +using EasyPost.Models.API; +using EasyPost.Models.Shared; +using Xunit; + +namespace EasyPost.Integration; + +public class Extensions +{ + /// + /// Test that an end-user can inherit and override the method. + /// If this test can be compiled, then the method is publicly accessible. + /// + public class CustomPaginatedCollection : PaginatedCollection // Using Tracker as a placeholder for any type + { + public override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) => throw new NotImplementedException(); + } + + /// + /// This test simply exists to ensure this file is compiled when the test suite is run. + /// + [Fact] + public void Compile() + { + Assert.True(true); + } +} diff --git a/EasyPost/Models/API/Address.cs b/EasyPost/Models/API/Address.cs index 553d8ca0c..131e244ad 100644 --- a/EasyPost/Models/API/Address.cs +++ b/EasyPost/Models/API/Address.cs @@ -142,7 +142,7 @@ public class AddressCollection : PaginatedCollection
/// The request size of the next page. /// The type of parameters to construct. /// A TParameters-type parameters set. - protected internal override TParameters BuildNextPageParameters(IEnumerable
entries, int? pageSize = null) + public override TParameters BuildNextPageParameters(IEnumerable
entries, int? pageSize = null) { Parameters.Address.All parameters = Filters != null ? (Parameters.Address.All)Filters : new Parameters.Address.All(); diff --git a/EasyPost/Models/API/Batch.cs b/EasyPost/Models/API/Batch.cs index adf63798e..a6d9699ab 100644 --- a/EasyPost/Models/API/Batch.cs +++ b/EasyPost/Models/API/Batch.cs @@ -110,7 +110,7 @@ public class BatchCollection : PaginatedCollection /// The request size of the next page. /// The type of parameters to construct. /// A TParameters-type parameters set. - protected internal override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) + public override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) { Parameters.Batch.All parameters = Filters != null ? (Parameters.Batch.All)Filters : new Parameters.Batch.All(); diff --git a/EasyPost/Models/API/EndShipper.cs b/EasyPost/Models/API/EndShipper.cs index 4314765ab..cf3ff1ff1 100644 --- a/EasyPost/Models/API/EndShipper.cs +++ b/EasyPost/Models/API/EndShipper.cs @@ -115,6 +115,6 @@ public class EndShipperCollection : PaginatedCollection /// The type of parameters to construct. /// A TParameters-type parameters set. // Cannot currently get the next page of EndShippers, so this is not implemented. - protected internal override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) => throw new EndOfPaginationError(); + public override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) => throw new EndOfPaginationError(); } } diff --git a/EasyPost/Models/API/Event.cs b/EasyPost/Models/API/Event.cs index fd6d3bcec..c4ee6a354 100644 --- a/EasyPost/Models/API/Event.cs +++ b/EasyPost/Models/API/Event.cs @@ -90,7 +90,7 @@ public class EventCollection : PaginatedCollection /// The request size of the next page. /// The type of parameters to construct. /// A TParameters-type parameters set. - protected internal override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) + public override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) { Parameters.Event.All parameters = Filters != null ? (Parameters.Event.All)Filters : new Parameters.Event.All(); diff --git a/EasyPost/Models/API/Insurance.cs b/EasyPost/Models/API/Insurance.cs index e2ac4fcd8..749a69931 100644 --- a/EasyPost/Models/API/Insurance.cs +++ b/EasyPost/Models/API/Insurance.cs @@ -113,7 +113,7 @@ public class InsuranceCollection : PaginatedCollection /// The request size of the next page. /// The type of parameters to construct. /// A TParameters-type parameters set. - protected internal override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) + public override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) { Parameters.Insurance.All parameters = Filters != null ? (Parameters.Insurance.All)Filters : new Parameters.Insurance.All(); diff --git a/EasyPost/Models/API/Pickup.cs b/EasyPost/Models/API/Pickup.cs index 7ad030d8d..87f4d0fa4 100644 --- a/EasyPost/Models/API/Pickup.cs +++ b/EasyPost/Models/API/Pickup.cs @@ -86,7 +86,7 @@ public class PickupCollection : PaginatedCollection /// The request size of the next page. /// The type of parameters to construct. /// A TParameters-type parameters set. - protected internal override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) + public override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) { Parameters.Pickup.All parameters = Filters != null ? (Parameters.Pickup.All)Filters : new Parameters.Pickup.All(); diff --git a/EasyPost/Models/API/ReferralCustomer.cs b/EasyPost/Models/API/ReferralCustomer.cs index d2b08a8e6..b6fea8fd4 100644 --- a/EasyPost/Models/API/ReferralCustomer.cs +++ b/EasyPost/Models/API/ReferralCustomer.cs @@ -36,7 +36,7 @@ public class ReferralCustomerCollection : PaginatedCollection /// The request size of the next page. /// The type of parameters to construct. /// A TParameters-type parameters set. - protected internal override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) + public override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) { Parameters.ReferralCustomer.All parameters = Filters != null ? (Parameters.ReferralCustomer.All)Filters : new Parameters.ReferralCustomer.All(); diff --git a/EasyPost/Models/API/Refund.cs b/EasyPost/Models/API/Refund.cs index 99fd60112..3c0a1e119 100644 --- a/EasyPost/Models/API/Refund.cs +++ b/EasyPost/Models/API/Refund.cs @@ -52,7 +52,7 @@ public class RefundCollection : PaginatedCollection /// The request size of the next page. /// The type of parameters to construct. /// A TParameters-type parameters set. - protected internal override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) + public override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) { Parameters.Refund.All parameters = Filters != null ? (Parameters.Refund.All)Filters : new Parameters.Refund.All(); diff --git a/EasyPost/Models/API/Report.cs b/EasyPost/Models/API/Report.cs index f339593e0..3636c6a74 100644 --- a/EasyPost/Models/API/Report.cs +++ b/EasyPost/Models/API/Report.cs @@ -55,7 +55,7 @@ public class ReportCollection : PaginatedCollection /// The request size of the next page. /// The type of parameters to construct. /// A TParameters-type parameters set. - protected internal override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) + public override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) { Parameters.Report.All parameters = Filters != null ? (Parameters.Report.All)Filters : new Parameters.Report.All(); diff --git a/EasyPost/Models/API/ScanForm.cs b/EasyPost/Models/API/ScanForm.cs index ce69d8e7c..dfbbbc95e 100644 --- a/EasyPost/Models/API/ScanForm.cs +++ b/EasyPost/Models/API/ScanForm.cs @@ -60,7 +60,7 @@ public class ScanFormCollection : PaginatedCollection /// The request size of the next page. /// The type of parameters to construct. /// A TParameters-type parameters set. - protected internal override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) + public override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) { Parameters.ScanForm.All parameters = Filters != null ? (Parameters.ScanForm.All)Filters : new Parameters.ScanForm.All(); diff --git a/EasyPost/Models/API/Shipment.cs b/EasyPost/Models/API/Shipment.cs index 87c109654..e7f82b704 100644 --- a/EasyPost/Models/API/Shipment.cs +++ b/EasyPost/Models/API/Shipment.cs @@ -124,7 +124,7 @@ public class ShipmentCollection : PaginatedCollection /// The request size of the next page. /// The type of parameters to construct. /// A TParameters-type parameters set. - protected internal override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) + public override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) { Parameters.Shipment.All parameters = Filters != null ? (Parameters.Shipment.All)Filters : new Parameters.Shipment.All(); diff --git a/EasyPost/Models/API/Tracker.cs b/EasyPost/Models/API/Tracker.cs index 1f070b36e..06b72dd7f 100644 --- a/EasyPost/Models/API/Tracker.cs +++ b/EasyPost/Models/API/Tracker.cs @@ -67,7 +67,7 @@ public class TrackerCollection : PaginatedCollection /// The request size of the next page. /// The type of parameters to construct. /// A TParameters-type parameters set. - protected internal override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) + public override TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) { Parameters.Tracker.All parameters = Filters != null ? (Parameters.Tracker.All)Filters : new Parameters.Tracker.All(); diff --git a/EasyPost/Models/Shared/PaginatedCollection.cs b/EasyPost/Models/Shared/PaginatedCollection.cs index d5b4dd76d..054f1d78f 100644 --- a/EasyPost/Models/Shared/PaginatedCollection.cs +++ b/EasyPost/Models/Shared/PaginatedCollection.cs @@ -31,10 +31,10 @@ public abstract class PaginatedCollection : _base.EasyPostObject where /// The results on the current page. Used to determine the API call parameters to retrieve the next page. /// The size of the next page. /// The type of to get the next page of. - /// The type of to construct for the API call. + /// The type of to construct for the API call. /// The next page of a paginated collection. /// Thrown if there is no next page to retrieve. - internal async Task GetNextPage(Func> apiCallFunction, List? currentEntries, int? pageSize = null) where TCollection : PaginatedCollection where TParameters : Parameters.BaseParameters + public async Task GetNextPage(Func> apiCallFunction, List? currentEntries, int? pageSize = null) where TCollection : PaginatedCollection where TParameters : Parameters.BaseParameters { if (currentEntries == null || currentEntries.Count == 0) { @@ -56,10 +56,10 @@ internal async Task GetNextPage(Func /// The entries of the collection. /// The size of the next page. - /// The type of to construct for the API call. + /// The type of to construct for the API call. /// A TParameters-type set of parameters to use for the subsequent API call. /// Thrown if there are no more items to retrieve for the paginated collection. // This method is abstract and must be implemented for each collection. - protected internal abstract TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) where TParameters : Parameters.BaseParameters; + public abstract TParameters BuildNextPageParameters(IEnumerable entries, int? pageSize = null) where TParameters : Parameters.BaseParameters; } } diff --git a/EasyPost/_base/EasyPostClient.cs b/EasyPost/_base/EasyPostClient.cs index 0aee2ab45..43c1486e7 100644 --- a/EasyPost/_base/EasyPostClient.cs +++ b/EasyPost/_base/EasyPostClient.cs @@ -119,7 +119,7 @@ public virtual async Task ExecuteRequest(HttpRequestMessage /// Optional root element for the resultant JSON to begin deserialization at. /// Type of object to deserialize response data into. Must be subclass of . /// An instance of a T-type object. - internal async Task RequestAsync(Method method, string endpoint, ApiVersion apiVersion, CancellationToken cancellationToken, Dictionary? parameters = null, string? rootElement = null) + public async Task RequestAsync(Method method, string endpoint, ApiVersion apiVersion, CancellationToken cancellationToken, Dictionary? parameters = null, string? rootElement = null) where T : class { // Build the request @@ -170,7 +170,7 @@ internal async Task RequestAsync(Method method, string endpoint, ApiVersio /// Optional parameters to use for the request. /// true if the request was successful, false otherwise. // ReSharper disable once UnusedMethodReturnValue.Global - internal async Task RequestAsync(Method method, string endpoint, ApiVersion apiVersion, CancellationToken cancellationToken, Dictionary? parameters = null) + public async Task RequestAsync(Method method, string endpoint, ApiVersion apiVersion, CancellationToken cancellationToken, Dictionary? parameters = null) { // Build the request Dictionary headers = _configuration.GetHeaders(apiVersion);