Skip to content

Commit 3d6ff21

Browse files
authored
[chore] Open internal methods (#525)
- Make base GetNextPage public - Make RequestAsync public - Make BuildNextPageParameters public
1 parent 30df9fc commit 3d6ff21

15 files changed

+44
-18
lines changed

EasyPost.Integration/Extensions.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using EasyPost.Models.API;
2+
using EasyPost.Models.Shared;
3+
using Xunit;
4+
5+
namespace EasyPost.Integration;
6+
7+
public class Extensions
8+
{
9+
/// <summary>
10+
/// Test that an end-user can inherit and override the <see cref="PaginatedCollection{T}.BuildNextPageParameters{TParameters}(IEnumerable{T}, int?)"/> method.
11+
/// If this test can be compiled, then the <see cref="PaginatedCollection{T}.BuildNextPageParameters{TParameters}(IEnumerable{T}, int?)"/> method is publicly accessible.
12+
/// </summary>
13+
public class CustomPaginatedCollection : PaginatedCollection<Tracker> // Using Tracker as a placeholder for any type
14+
{
15+
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Tracker> entries, int? pageSize = null) => throw new NotImplementedException();
16+
}
17+
18+
/// <summary>
19+
/// This test simply exists to ensure this file is compiled when the test suite is run.
20+
/// </summary>
21+
[Fact]
22+
public void Compile()
23+
{
24+
Assert.True(true);
25+
}
26+
}

EasyPost/Models/API/Address.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public class AddressCollection : PaginatedCollection<Address>
142142
/// <param name="pageSize">The request size of the next page.</param>
143143
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
144144
/// <returns>A TParameters-type parameters set.</returns>
145-
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Address> entries, int? pageSize = null)
145+
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Address> entries, int? pageSize = null)
146146
{
147147
Parameters.Address.All parameters = Filters != null ? (Parameters.Address.All)Filters : new Parameters.Address.All();
148148

EasyPost/Models/API/Batch.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public class BatchCollection : PaginatedCollection<Batch>
110110
/// <param name="pageSize">The request size of the next page.</param>
111111
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
112112
/// <returns>A TParameters-type parameters set.</returns>
113-
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Batch> entries, int? pageSize = null)
113+
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Batch> entries, int? pageSize = null)
114114
{
115115
Parameters.Batch.All parameters = Filters != null ? (Parameters.Batch.All)Filters : new Parameters.Batch.All();
116116

EasyPost/Models/API/EndShipper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,6 @@ public class EndShipperCollection : PaginatedCollection<EndShipper>
115115
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
116116
/// <returns>A TParameters-type parameters set.</returns>
117117
// Cannot currently get the next page of EndShippers, so this is not implemented.
118-
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<EndShipper> entries, int? pageSize = null) => throw new EndOfPaginationError();
118+
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<EndShipper> entries, int? pageSize = null) => throw new EndOfPaginationError();
119119
}
120120
}

EasyPost/Models/API/Event.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class EventCollection : PaginatedCollection<Event>
9090
/// <param name="pageSize">The request size of the next page.</param>
9191
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
9292
/// <returns>A TParameters-type parameters set.</returns>
93-
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Event> entries, int? pageSize = null)
93+
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Event> entries, int? pageSize = null)
9494
{
9595
Parameters.Event.All parameters = Filters != null ? (Parameters.Event.All)Filters : new Parameters.Event.All();
9696

EasyPost/Models/API/Insurance.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public class InsuranceCollection : PaginatedCollection<Insurance>
113113
/// <param name="pageSize">The request size of the next page.</param>
114114
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
115115
/// <returns>A TParameters-type parameters set.</returns>
116-
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Insurance> entries, int? pageSize = null)
116+
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Insurance> entries, int? pageSize = null)
117117
{
118118
Parameters.Insurance.All parameters = Filters != null ? (Parameters.Insurance.All)Filters : new Parameters.Insurance.All();
119119

EasyPost/Models/API/Pickup.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public class PickupCollection : PaginatedCollection<Pickup>
8686
/// <param name="pageSize">The request size of the next page.</param>
8787
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
8888
/// <returns>A TParameters-type parameters set.</returns>
89-
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Pickup> entries, int? pageSize = null)
89+
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Pickup> entries, int? pageSize = null)
9090
{
9191
Parameters.Pickup.All parameters = Filters != null ? (Parameters.Pickup.All)Filters : new Parameters.Pickup.All();
9292

EasyPost/Models/API/ReferralCustomer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class ReferralCustomerCollection : PaginatedCollection<ReferralCustomer>
3636
/// <param name="pageSize">The request size of the next page.</param>
3737
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
3838
/// <returns>A TParameters-type parameters set.</returns>
39-
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<ReferralCustomer> entries, int? pageSize = null)
39+
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<ReferralCustomer> entries, int? pageSize = null)
4040
{
4141
Parameters.ReferralCustomer.All parameters = Filters != null ? (Parameters.ReferralCustomer.All)Filters : new Parameters.ReferralCustomer.All();
4242

EasyPost/Models/API/Refund.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class RefundCollection : PaginatedCollection<Refund>
5252
/// <param name="pageSize">The request size of the next page.</param>
5353
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
5454
/// <returns>A TParameters-type parameters set.</returns>
55-
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Refund> entries, int? pageSize = null)
55+
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Refund> entries, int? pageSize = null)
5656
{
5757
Parameters.Refund.All parameters = Filters != null ? (Parameters.Refund.All)Filters : new Parameters.Refund.All();
5858

EasyPost/Models/API/Report.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class ReportCollection : PaginatedCollection<Report>
5555
/// <param name="pageSize">The request size of the next page.</param>
5656
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
5757
/// <returns>A TParameters-type parameters set.</returns>
58-
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Report> entries, int? pageSize = null)
58+
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Report> entries, int? pageSize = null)
5959
{
6060
Parameters.Report.All parameters = Filters != null ? (Parameters.Report.All)Filters : new Parameters.Report.All();
6161

EasyPost/Models/API/ScanForm.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class ScanFormCollection : PaginatedCollection<ScanForm>
6060
/// <param name="pageSize">The request size of the next page.</param>
6161
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
6262
/// <returns>A TParameters-type parameters set.</returns>
63-
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<ScanForm> entries, int? pageSize = null)
63+
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<ScanForm> entries, int? pageSize = null)
6464
{
6565
Parameters.ScanForm.All parameters = Filters != null ? (Parameters.ScanForm.All)Filters : new Parameters.ScanForm.All();
6666

EasyPost/Models/API/Shipment.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public class ShipmentCollection : PaginatedCollection<Shipment>
124124
/// <param name="pageSize">The request size of the next page.</param>
125125
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
126126
/// <returns>A TParameters-type parameters set.</returns>
127-
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Shipment> entries, int? pageSize = null)
127+
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Shipment> entries, int? pageSize = null)
128128
{
129129
Parameters.Shipment.All parameters = Filters != null ? (Parameters.Shipment.All)Filters : new Parameters.Shipment.All();
130130

EasyPost/Models/API/Tracker.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class TrackerCollection : PaginatedCollection<Tracker>
6767
/// <param name="pageSize">The request size of the next page.</param>
6868
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
6969
/// <returns>A TParameters-type parameters set.</returns>
70-
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Tracker> entries, int? pageSize = null)
70+
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Tracker> entries, int? pageSize = null)
7171
{
7272
Parameters.Tracker.All parameters = Filters != null ? (Parameters.Tracker.All)Filters : new Parameters.Tracker.All();
7373

EasyPost/Models/Shared/PaginatedCollection.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ public abstract class PaginatedCollection<TEntries> : _base.EasyPostObject where
3131
/// <param name="currentEntries">The results on the current page. Used to determine the API call parameters to retrieve the next page.</param>
3232
/// <param name="pageSize">The size of the next page.</param>
3333
/// <typeparam name="TCollection">The type of <see cref="PaginatedCollection{TCollection}"/> to get the next page of.</typeparam>
34-
/// <typeparam name="TParameters">The type of <see cref="Parameters.BaseParameters"/> to construct for the API call.</typeparam>
34+
/// <typeparam name="TParameters">The type of <see cref="Parameters.BaseParameters{TEntries}"/> to construct for the API call.</typeparam>
3535
/// <returns>The next page of a paginated collection.</returns>
3636
/// <exception cref="EndOfPaginationError">Thrown if there is no next page to retrieve.</exception>
37-
internal async Task<TCollection> GetNextPage<TCollection, TParameters>(Func<TParameters, Task<TCollection>> apiCallFunction, List<TEntries>? currentEntries, int? pageSize = null) where TCollection : PaginatedCollection<TEntries> where TParameters : Parameters.BaseParameters<TEntries>
37+
public async Task<TCollection> GetNextPage<TCollection, TParameters>(Func<TParameters, Task<TCollection>> apiCallFunction, List<TEntries>? currentEntries, int? pageSize = null) where TCollection : PaginatedCollection<TEntries> where TParameters : Parameters.BaseParameters<TEntries>
3838
{
3939
if (currentEntries == null || currentEntries.Count == 0)
4040
{
@@ -56,10 +56,10 @@ internal async Task<TCollection> GetNextPage<TCollection, TParameters>(Func<TPar
5656
/// </summary>
5757
/// <param name="entries">The entries of the collection.</param>
5858
/// <param name="pageSize">The size of the next page.</param>
59-
/// <typeparam name="TParameters">The type of <see cref="Parameters.BaseParameters"/> to construct for the API call.</typeparam>
59+
/// <typeparam name="TParameters">The type of <see cref="Parameters.BaseParameters{TEntries}"/> to construct for the API call.</typeparam>
6060
/// <returns>A TParameters-type set of parameters to use for the subsequent API call.</returns>
6161
/// <exception cref="EndOfPaginationError">Thrown if there are no more items to retrieve for the paginated collection.</exception>
6262
// This method is abstract and must be implemented for each collection.
63-
protected internal abstract TParameters BuildNextPageParameters<TParameters>(IEnumerable<TEntries> entries, int? pageSize = null) where TParameters : Parameters.BaseParameters<TEntries>;
63+
public abstract TParameters BuildNextPageParameters<TParameters>(IEnumerable<TEntries> entries, int? pageSize = null) where TParameters : Parameters.BaseParameters<TEntries>;
6464
}
6565
}

EasyPost/_base/EasyPostClient.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public virtual async Task<HttpResponseMessage> ExecuteRequest(HttpRequestMessage
119119
/// <param name="rootElement">Optional root element for the resultant JSON to begin deserialization at.</param>
120120
/// <typeparam name="T">Type of object to deserialize response data into. Must be subclass of <see cref="EasyPostObject"/>.</typeparam>
121121
/// <returns>An instance of a T-type object.</returns>
122-
internal async Task<T> RequestAsync<T>(Method method, string endpoint, ApiVersion apiVersion, CancellationToken cancellationToken, Dictionary<string, object>? parameters = null, string? rootElement = null)
122+
public async Task<T> RequestAsync<T>(Method method, string endpoint, ApiVersion apiVersion, CancellationToken cancellationToken, Dictionary<string, object>? parameters = null, string? rootElement = null)
123123
where T : class
124124
{
125125
// Build the request
@@ -170,7 +170,7 @@ internal async Task<T> RequestAsync<T>(Method method, string endpoint, ApiVersio
170170
/// <param name="parameters">Optional parameters to use for the request.</param>
171171
/// <returns><c>true</c> if the request was successful, <c>false</c> otherwise.</returns>
172172
// ReSharper disable once UnusedMethodReturnValue.Global
173-
internal async Task<bool> RequestAsync(Method method, string endpoint, ApiVersion apiVersion, CancellationToken cancellationToken, Dictionary<string, object>? parameters = null)
173+
public async Task<bool> RequestAsync(Method method, string endpoint, ApiVersion apiVersion, CancellationToken cancellationToken, Dictionary<string, object>? parameters = null)
174174
{
175175
// Build the request
176176
Dictionary<string, string> headers = _configuration.GetHeaders(apiVersion);

0 commit comments

Comments
 (0)