Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Open internal methods #525

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions EasyPost.Integration/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using EasyPost.Models.API;
using EasyPost.Models.Shared;
using Xunit;

namespace EasyPost.Integration;

public class Extensions
{
/// <summary>
/// Test that an end-user can inherit and override the <see cref="PaginatedCollection{T}.BuildNextPageParameters{TParameters}(IEnumerable{T}, int?)"/> method.
/// If this test can be compiled, then the <see cref="PaginatedCollection{T}.BuildNextPageParameters{TParameters}(IEnumerable{T}, int?)"/> method is publicly accessible.
/// </summary>
public class CustomPaginatedCollection : PaginatedCollection<Tracker> // Using Tracker as a placeholder for any type
{
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Tracker> entries, int? pageSize = null) => throw new NotImplementedException();
}

/// <summary>
/// This test simply exists to ensure this file is compiled when the test suite is run.
/// </summary>
[Fact]
public void Compile()
{
Assert.True(true);
}
}
2 changes: 1 addition & 1 deletion EasyPost/Models/API/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public class AddressCollection : PaginatedCollection<Address>
/// <param name="pageSize">The request size of the next page.</param>
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
/// <returns>A TParameters-type parameters set.</returns>
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Address> entries, int? pageSize = null)
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Address> entries, int? pageSize = null)
{
Parameters.Address.All parameters = Filters != null ? (Parameters.Address.All)Filters : new Parameters.Address.All();

Expand Down
2 changes: 1 addition & 1 deletion EasyPost/Models/API/Batch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class BatchCollection : PaginatedCollection<Batch>
/// <param name="pageSize">The request size of the next page.</param>
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
/// <returns>A TParameters-type parameters set.</returns>
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Batch> entries, int? pageSize = null)
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Batch> entries, int? pageSize = null)
{
Parameters.Batch.All parameters = Filters != null ? (Parameters.Batch.All)Filters : new Parameters.Batch.All();

Expand Down
2 changes: 1 addition & 1 deletion EasyPost/Models/API/EndShipper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ public class EndShipperCollection : PaginatedCollection<EndShipper>
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
/// <returns>A TParameters-type parameters set.</returns>
// Cannot currently get the next page of EndShippers, so this is not implemented.
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<EndShipper> entries, int? pageSize = null) => throw new EndOfPaginationError();
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<EndShipper> entries, int? pageSize = null) => throw new EndOfPaginationError();
}
}
2 changes: 1 addition & 1 deletion EasyPost/Models/API/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class EventCollection : PaginatedCollection<Event>
/// <param name="pageSize">The request size of the next page.</param>
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
/// <returns>A TParameters-type parameters set.</returns>
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Event> entries, int? pageSize = null)
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Event> entries, int? pageSize = null)
{
Parameters.Event.All parameters = Filters != null ? (Parameters.Event.All)Filters : new Parameters.Event.All();

Expand Down
2 changes: 1 addition & 1 deletion EasyPost/Models/API/Insurance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public class InsuranceCollection : PaginatedCollection<Insurance>
/// <param name="pageSize">The request size of the next page.</param>
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
/// <returns>A TParameters-type parameters set.</returns>
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Insurance> entries, int? pageSize = null)
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Insurance> entries, int? pageSize = null)
{
Parameters.Insurance.All parameters = Filters != null ? (Parameters.Insurance.All)Filters : new Parameters.Insurance.All();

Expand Down
2 changes: 1 addition & 1 deletion EasyPost/Models/API/Pickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class PickupCollection : PaginatedCollection<Pickup>
/// <param name="pageSize">The request size of the next page.</param>
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
/// <returns>A TParameters-type parameters set.</returns>
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Pickup> entries, int? pageSize = null)
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Pickup> entries, int? pageSize = null)
{
Parameters.Pickup.All parameters = Filters != null ? (Parameters.Pickup.All)Filters : new Parameters.Pickup.All();

Expand Down
2 changes: 1 addition & 1 deletion EasyPost/Models/API/ReferralCustomer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ReferralCustomerCollection : PaginatedCollection<ReferralCustomer>
/// <param name="pageSize">The request size of the next page.</param>
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
/// <returns>A TParameters-type parameters set.</returns>
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<ReferralCustomer> entries, int? pageSize = null)
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<ReferralCustomer> entries, int? pageSize = null)
{
Parameters.ReferralCustomer.All parameters = Filters != null ? (Parameters.ReferralCustomer.All)Filters : new Parameters.ReferralCustomer.All();

Expand Down
2 changes: 1 addition & 1 deletion EasyPost/Models/API/Refund.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class RefundCollection : PaginatedCollection<Refund>
/// <param name="pageSize">The request size of the next page.</param>
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
/// <returns>A TParameters-type parameters set.</returns>
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Refund> entries, int? pageSize = null)
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Refund> entries, int? pageSize = null)
{
Parameters.Refund.All parameters = Filters != null ? (Parameters.Refund.All)Filters : new Parameters.Refund.All();

Expand Down
2 changes: 1 addition & 1 deletion EasyPost/Models/API/Report.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class ReportCollection : PaginatedCollection<Report>
/// <param name="pageSize">The request size of the next page.</param>
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
/// <returns>A TParameters-type parameters set.</returns>
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Report> entries, int? pageSize = null)
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Report> entries, int? pageSize = null)
{
Parameters.Report.All parameters = Filters != null ? (Parameters.Report.All)Filters : new Parameters.Report.All();

Expand Down
2 changes: 1 addition & 1 deletion EasyPost/Models/API/ScanForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class ScanFormCollection : PaginatedCollection<ScanForm>
/// <param name="pageSize">The request size of the next page.</param>
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
/// <returns>A TParameters-type parameters set.</returns>
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<ScanForm> entries, int? pageSize = null)
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<ScanForm> entries, int? pageSize = null)
{
Parameters.ScanForm.All parameters = Filters != null ? (Parameters.ScanForm.All)Filters : new Parameters.ScanForm.All();

Expand Down
2 changes: 1 addition & 1 deletion EasyPost/Models/API/Shipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class ShipmentCollection : PaginatedCollection<Shipment>
/// <param name="pageSize">The request size of the next page.</param>
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
/// <returns>A TParameters-type parameters set.</returns>
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Shipment> entries, int? pageSize = null)
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Shipment> entries, int? pageSize = null)
{
Parameters.Shipment.All parameters = Filters != null ? (Parameters.Shipment.All)Filters : new Parameters.Shipment.All();

Expand Down
2 changes: 1 addition & 1 deletion EasyPost/Models/API/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class TrackerCollection : PaginatedCollection<Tracker>
/// <param name="pageSize">The request size of the next page.</param>
/// <typeparam name="TParameters">The type of parameters to construct.</typeparam>
/// <returns>A TParameters-type parameters set.</returns>
protected internal override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Tracker> entries, int? pageSize = null)
public override TParameters BuildNextPageParameters<TParameters>(IEnumerable<Tracker> entries, int? pageSize = null)
{
Parameters.Tracker.All parameters = Filters != null ? (Parameters.Tracker.All)Filters : new Parameters.Tracker.All();

Expand Down
8 changes: 4 additions & 4 deletions EasyPost/Models/Shared/PaginatedCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public abstract class PaginatedCollection<TEntries> : _base.EasyPostObject where
/// <param name="currentEntries">The results on the current page. Used to determine the API call parameters to retrieve the next page.</param>
/// <param name="pageSize">The size of the next page.</param>
/// <typeparam name="TCollection">The type of <see cref="PaginatedCollection{TCollection}"/> to get the next page of.</typeparam>
/// <typeparam name="TParameters">The type of <see cref="Parameters.BaseParameters"/> to construct for the API call.</typeparam>
/// <typeparam name="TParameters">The type of <see cref="Parameters.BaseParameters{TEntries}"/> to construct for the API call.</typeparam>
/// <returns>The next page of a paginated collection.</returns>
/// <exception cref="EndOfPaginationError">Thrown if there is no next page to retrieve.</exception>
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>
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>
{
if (currentEntries == null || currentEntries.Count == 0)
{
Expand All @@ -56,10 +56,10 @@ internal async Task<TCollection> GetNextPage<TCollection, TParameters>(Func<TPar
/// </summary>
/// <param name="entries">The entries of the collection.</param>
/// <param name="pageSize">The size of the next page.</param>
/// <typeparam name="TParameters">The type of <see cref="Parameters.BaseParameters"/> to construct for the API call.</typeparam>
/// <typeparam name="TParameters">The type of <see cref="Parameters.BaseParameters{TEntries}"/> to construct for the API call.</typeparam>
/// <returns>A TParameters-type set of parameters to use for the subsequent API call.</returns>
/// <exception cref="EndOfPaginationError">Thrown if there are no more items to retrieve for the paginated collection.</exception>
// This method is abstract and must be implemented for each collection.
protected internal abstract TParameters BuildNextPageParameters<TParameters>(IEnumerable<TEntries> entries, int? pageSize = null) where TParameters : Parameters.BaseParameters<TEntries>;
public abstract TParameters BuildNextPageParameters<TParameters>(IEnumerable<TEntries> entries, int? pageSize = null) where TParameters : Parameters.BaseParameters<TEntries>;
}
}
4 changes: 2 additions & 2 deletions EasyPost/_base/EasyPostClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public virtual async Task<HttpResponseMessage> ExecuteRequest(HttpRequestMessage
/// <param name="rootElement">Optional root element for the resultant JSON to begin deserialization at.</param>
/// <typeparam name="T">Type of object to deserialize response data into. Must be subclass of <see cref="EasyPostObject"/>.</typeparam>
/// <returns>An instance of a T-type object.</returns>
internal async Task<T> RequestAsync<T>(Method method, string endpoint, ApiVersion apiVersion, CancellationToken cancellationToken, Dictionary<string, object>? parameters = null, string? rootElement = null)
public async Task<T> RequestAsync<T>(Method method, string endpoint, ApiVersion apiVersion, CancellationToken cancellationToken, Dictionary<string, object>? parameters = null, string? rootElement = null)
where T : class
{
// Build the request
Expand Down Expand Up @@ -170,7 +170,7 @@ internal async Task<T> RequestAsync<T>(Method method, string endpoint, ApiVersio
/// <param name="parameters">Optional parameters to use for the request.</param>
/// <returns><c>true</c> if the request was successful, <c>false</c> otherwise.</returns>
// ReSharper disable once UnusedMethodReturnValue.Global
internal async Task<bool> RequestAsync(Method method, string endpoint, ApiVersion apiVersion, CancellationToken cancellationToken, Dictionary<string, object>? parameters = null)
public async Task<bool> RequestAsync(Method method, string endpoint, ApiVersion apiVersion, CancellationToken cancellationToken, Dictionary<string, object>? parameters = null)
{
// Build the request
Dictionary<string, string> headers = _configuration.GetHeaders(apiVersion);
Expand Down
Loading