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

[SDK-2548] Support unpaginated requests for some endpoints #525

Merged
merged 1 commit into from
Sep 21, 2021
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
27 changes: 15 additions & 12 deletions src/Auth0.ManagementApi/Clients/ClientGrantsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,25 @@ public Task DeleteAsync(string id, CancellationToken cancellationToken = default
/// <param name="pagination">Specifies <see cref="PaginationInfo"/> to use in requesting paged results.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>A <see cref="IPagedList{ClientGrant}"/> containing the client grants requested.</returns>
public Task<IPagedList<ClientGrant>> GetAllAsync(GetClientGrantsRequest request, PaginationInfo pagination, CancellationToken cancellationToken = default)
public Task<IPagedList<ClientGrant>> GetAllAsync(GetClientGrantsRequest request, PaginationInfo pagination = null, CancellationToken cancellationToken = default)
{
if (request == null)
throw new ArgumentNullException(nameof(request));
if (pagination == null)
throw new ArgumentNullException(nameof(pagination));

return Connection.GetAsync<IPagedList<ClientGrant>>(BuildUri("client-grants",
new Dictionary<string, string>
{
{"audience", request.Audience},
{"client_id", request.ClientId},
{"page", pagination.PageNo.ToString()},
{"per_page", pagination.PerPage.ToString()},
{"include_totals", pagination.IncludeTotals.ToString().ToLower()}
}), DefaultHeaders, converters, cancellationToken);
var queryStrings = new Dictionary<string, string>
{
{"audience", request.Audience},
{"client_id", request.ClientId},
};

if (pagination != null)
{
queryStrings["page"] = pagination.PageNo.ToString();
queryStrings["per_page"] = pagination.PerPage.ToString();
queryStrings["include_totals"] = pagination.IncludeTotals.ToString().ToLower();
}

return Connection.GetAsync<IPagedList<ClientGrant>>(BuildUri("client-grants", queryStrings), DefaultHeaders, converters, cancellationToken);
}

/// <summary>
Expand Down
16 changes: 9 additions & 7 deletions src/Auth0.ManagementApi/Clients/ClientsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,26 @@ public Task DeleteAsync(string id, CancellationToken cancellationToken = default
/// <param name="pagination">Specifies pagination info to use when requesting paged results.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="IPagedList{Client}"/> containing the clients.</returns>
public Task<IPagedList<Client>> GetAllAsync(GetClientsRequest request, PaginationInfo pagination, CancellationToken cancellationToken = default)
public Task<IPagedList<Client>> GetAllAsync(GetClientsRequest request, PaginationInfo pagination = null, CancellationToken cancellationToken = default)
{
if (request == null)
throw new ArgumentNullException(nameof(request));
if (pagination == null)
throw new ArgumentNullException(nameof(pagination));

var queryStrings = new Dictionary<string, string>
{
{"fields", request.Fields},
{"include_fields", request.IncludeFields?.ToString().ToLower()},
{"is_global", request.IsGlobal?.ToString().ToLower()},
{"is_first_party", request.IsFirstParty?.ToString().ToLower()},
{"page", pagination.PageNo.ToString()},
{"per_page", pagination.PerPage.ToString()},
{"include_totals", pagination.IncludeTotals.ToString().ToLower()},
{"is_first_party", request.IsFirstParty?.ToString().ToLower()}
};

if (pagination != null)
{
queryStrings["page"] = pagination.PageNo.ToString();
queryStrings["per_page"] = pagination.PerPage.ToString();
queryStrings["include_totals"] = pagination.IncludeTotals.ToString().ToLower();
}

if (request.AppType != null)
queryStrings.Add("app_type", string.Join(",", request.AppType.Select(ExtensionMethods.ToEnumString)));

Expand Down
14 changes: 8 additions & 6 deletions src/Auth0.ManagementApi/Clients/ConnectionsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,25 @@ public Task<Connection> GetAsync(string id, string fields = null, bool includeFi
/// <param name="pagination">Specifies pagination info to use when requesting paged results.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="IPagedList{Connection}"/> containing the list of connections.</returns>
public Task<IPagedList<Connection>> GetAllAsync(GetConnectionsRequest request, PaginationInfo pagination, CancellationToken cancellationToken = default)
public Task<IPagedList<Connection>> GetAllAsync(GetConnectionsRequest request, PaginationInfo pagination = null, CancellationToken cancellationToken = default)
{
if (request == null)
throw new ArgumentNullException(nameof(request));
if (pagination == null)
throw new ArgumentNullException(nameof(pagination));

var queryStrings = new Dictionary<string, string>
{
{"fields", request.Fields},
{"include_fields", request.IncludeFields?.ToString().ToLower()},
{"name", request.Name},
{"page", pagination.PageNo.ToString()},
{"per_page", pagination.PerPage.ToString()},
{"include_totals", pagination.IncludeTotals.ToString().ToLower()}
};

if (pagination != null)
{
queryStrings["page"] = pagination.PageNo.ToString();
queryStrings["per_page"] = pagination.PerPage.ToString();
queryStrings["include_totals"] = pagination.IncludeTotals.ToString().ToLower();
}

// Add each strategy as a separate querystring
if (request.Strategy != null)
{
Expand Down
15 changes: 8 additions & 7 deletions src/Auth0.ManagementApi/Clients/DeviceCredentialsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,27 @@ public Task<IList<DeviceCredential>> GetAllAsync(string fields = null, bool incl
/// <param name="pagination">Specifies <see cref="PaginationInfo"/> to use in requesting paged results.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>A list of <see cref="DeviceCredential"/> which conforms to the criteria specified.</returns>
public Task<IPagedList<DeviceCredential>> GetAllAsync(GetDeviceCredentialsRequest request, PaginationInfo pagination, CancellationToken cancellationToken = default)
public Task<IPagedList<DeviceCredential>> GetAllAsync(GetDeviceCredentialsRequest request, PaginationInfo pagination = null, CancellationToken cancellationToken = default)
{
if (request == null)
throw new ArgumentNullException(nameof(request));

if (pagination == null)
throw new ArgumentNullException(nameof(pagination));

var queryStrings = new Dictionary<string, string>
{
{"fields", request.Fields},
{"include_fields", request.IncludeFields.ToString().ToLower()},
{"user_id", request.UserId},
{"client_id", request.ClientId},
{"type", request.Type},
{"page", pagination.PageNo.ToString()},
{"per_page", pagination.PerPage.ToString()},
{"include_totals", pagination.IncludeTotals.ToString().ToLower()}
};

if (pagination != null)
{
queryStrings["page"] = pagination.PageNo.ToString();
queryStrings["per_page"] = pagination.PerPage.ToString();
queryStrings["include_totals"] = pagination.IncludeTotals.ToString().ToLower();
}

return Connection.GetAsync<IPagedList<DeviceCredential>>(BuildUri("device-credentials", queryStrings), DefaultHeaders, converters, cancellationToken);
}

Expand Down
28 changes: 16 additions & 12 deletions src/Auth0.ManagementApi/Clients/HooksClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,27 @@ public Task DeleteAsync(string id, CancellationToken cancellationToken = default
/// <param name="pagination">Specifies pagination info to use when requesting paged results.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="IPagedList{T}"/> containing the hooks requested.</returns>
public Task<IPagedList<Hook>> GetAllAsync(GetHooksRequest request, PaginationInfo pagination, CancellationToken cancellationToken = default)
public Task<IPagedList<Hook>> GetAllAsync(GetHooksRequest request, PaginationInfo pagination = null, CancellationToken cancellationToken = default)
{
if (request == null)
throw new ArgumentNullException(nameof(request));
if (pagination == null)
throw new ArgumentNullException(nameof(pagination));

var queryStrings = new Dictionary<string, string>
{
{"enabled", request.Enabled?.ToString().ToLower()},
{"fields", request.Fields},
{"triggerId", request.TriggerId},
};

if (pagination != null)
{
queryStrings["page"] = pagination.PageNo.ToString();
queryStrings["per_page"] = pagination.PerPage.ToString();
queryStrings["include_totals"] = pagination.IncludeTotals.ToString().ToLower();
}

return Connection.GetAsync<IPagedList<Hook>>(BuildUri("hooks",
new Dictionary<string, string>
{
{"enabled", request.Enabled?.ToString().ToLower()},
{"fields", request.Fields},
{"triggerId", request.TriggerId },
{"page", pagination.PageNo.ToString()},
{"per_page", pagination.PerPage.ToString()},
{"include_totals", pagination.IncludeTotals.ToString().ToLower()}
}), DefaultHeaders, hooksConverters, cancellationToken);
queryStrings), DefaultHeaders, hooksConverters, cancellationToken);
}

/// <summary>
Expand Down
35 changes: 19 additions & 16 deletions src/Auth0.ManagementApi/Clients/LogsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,29 @@ public LogsClient(IManagementConnection connection, Uri baseUri, IDictionary<str
/// <param name="pagination">Specifies pagination info to use when requesting paged results.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="IPagedList{LogEntry}"/> containing the list of log entries.</returns>
public Task<IPagedList<LogEntry>> GetAllAsync(GetLogsRequest request, PaginationInfo pagination, CancellationToken cancellationToken = default)
public Task<IPagedList<LogEntry>> GetAllAsync(GetLogsRequest request, PaginationInfo pagination = null, CancellationToken cancellationToken = default)
{
if (request == null)
throw new ArgumentNullException(nameof(request));
if (pagination == null)
throw new ArgumentNullException(nameof(pagination));

return Connection.GetAsync<IPagedList<LogEntry>>(BuildUri("logs",
new Dictionary<string, string>
{
{"sort", request.Sort},
{"fields", request.Fields},
{"include_fields", request.IncludeFields?.ToString().ToLower()},
{"from", request.From},
{"take", request.Take?.ToString().ToLower()},
{"q", request.Query},
{"page", pagination.PageNo.ToString()},
{"per_page", pagination.PerPage.ToString()},
{"include_totals", pagination.IncludeTotals.ToString().ToLower()}
}), DefaultHeaders, converters, cancellationToken);
var queryStrings = new Dictionary<string, string>
{
{"sort", request.Sort},
{"fields", request.Fields},
{"include_fields", request.IncludeFields?.ToString().ToLower()},
{"from", request.From},
{"take", request.Take?.ToString().ToLower()},
{"q", request.Query},
};

if (pagination != null)
{
queryStrings["page"] = pagination.PageNo.ToString();
queryStrings["per_page"] = pagination.PerPage.ToString();
queryStrings["include_totals"] = pagination.IncludeTotals.ToString().ToLower();
}

return Connection.GetAsync<IPagedList<LogEntry>>(BuildUri("logs", queryStrings), DefaultHeaders, converters, cancellationToken);
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Auth0.ManagementApi/Clients/ResourceServersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public Task<ResourceServer> GetAsync(string id, CancellationToken cancellationTo
/// <param name="pagination">Specifies pagination info to use when requesting paged results.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>A <see cref="IPagedList{ResourceServer}"/> containing the list of resource servers.</returns>
public Task<IPagedList<ResourceServer>> GetAllAsync(PaginationInfo pagination, CancellationToken cancellationToken = default)
public Task<IPagedList<ResourceServer>> GetAllAsync(PaginationInfo pagination = null, CancellationToken cancellationToken = default)
{
return Connection.GetAsync<IPagedList<ResourceServer>>(BuildUri("resource-servers",
new Dictionary<string, string>
pagination != null ? new Dictionary<string, string>
{
{"page", pagination.PageNo.ToString()},
{"per_page", pagination.PerPage.ToString()},
{"include_totals", pagination.IncludeTotals.ToString().ToLower()}
}), DefaultHeaders, converters, cancellationToken);
} : null), DefaultHeaders, converters, cancellationToken);
}

/// <summary>
Expand Down
31 changes: 17 additions & 14 deletions src/Auth0.ManagementApi/Clients/RulesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,27 @@ public Task DeleteAsync(string id, CancellationToken cancellationToken = default
/// <param name="pagination">Specifies pagination info to use when requesting paged results.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="IPagedList{Rule}"/> containing the rules requested.</returns>
public Task<IPagedList<Rule>> GetAllAsync(GetRulesRequest request, PaginationInfo pagination, CancellationToken cancellationToken = default)
public Task<IPagedList<Rule>> GetAllAsync(GetRulesRequest request, PaginationInfo pagination = null, CancellationToken cancellationToken = default)
{
if (request == null)
throw new ArgumentNullException(nameof(request));
if (pagination == null)
throw new ArgumentNullException(nameof(pagination));

return Connection.GetAsync<IPagedList<Rule>>(BuildUri("rules",
new Dictionary<string, string>
{
{"enabled", request.Enabled?.ToString().ToLower()},
{"fields", request.Fields},
{"include_fields", request.IncludeFields?.ToString().ToLower()},
{"stage", request.Stage},
{"page", pagination.PageNo.ToString()},
{"per_page", pagination.PerPage.ToString()},
{"include_totals", pagination.IncludeTotals.ToString().ToLower()}
}), DefaultHeaders, rulesConverters, cancellationToken);
var queryStrings = new Dictionary<string, string>
{
{"enabled", request.Enabled?.ToString().ToLower()},
{"fields", request.Fields},
{"include_fields", request.IncludeFields?.ToString().ToLower()},
{"stage", request.Stage}
};

if (pagination != null)
{
queryStrings["page"] = pagination.PageNo.ToString();
queryStrings["per_page"] = pagination.PerPage.ToString();
queryStrings["include_totals"] = pagination.IncludeTotals.ToString().ToLower();
}

return Connection.GetAsync<IPagedList<Rule>>(BuildUri("rules", queryStrings), DefaultHeaders, rulesConverters, cancellationToken);
}

/// <summary>
Expand Down
Loading