Skip to content

Commit

Permalink
Merge pull request #18 from JSkimming/max-per-page
Browse files Browse the repository at this point in the history
Zone paging is a maximum of 50 per page
  • Loading branch information
JSkimming committed Sep 3, 2015
2 parents 523a2ed + 15b3836 commit 2c86117
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Binary file modified src/CloudFlare.NET/CloudFlare.NET.v2.ncrunchproject
Binary file not shown.
5 changes: 4 additions & 1 deletion src/CloudFlare.NET/CloudFlareClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public Task<IEnumerable<Zone>> GetAllZonesAsync(
_client.GetZonesAsync,
cancellationToken,
auth ?? _auth,
50,
parameters);
}

Expand Down Expand Up @@ -196,13 +197,15 @@ public Task<IEnumerable<DnsRecord>> GetAllDnsRecordsAsync(
(ct, a, p) => _client.GetDnsRecordsAsync(zoneId, ct, a, p),
cancellationToken,
auth ?? _auth,
100,
parameters);
}

private static async Task<IEnumerable<TResult>> GetAllPagedResultsAsync<TResult, TParams, TOrder>(
Func<CancellationToken, CloudFlareAuth, TParams, Task<CloudFlareResponse<IReadOnlyList<TResult>>>> request,
CancellationToken cancellationToken,
CloudFlareAuth auth,
int maxPerPage,
TParams parameters = null)
where TResult : class
where TParams : PagedParameters<TOrder>
Expand All @@ -217,7 +220,7 @@ private static async Task<IEnumerable<TResult>> GetAllPagedResultsAsync<TResult,
++page;

// Create the paged parameters;
JObject jsonParams = JObject.FromObject(new { page, per_page = 100 });
JObject jsonParams = JObject.FromObject(new { page, per_page = maxPerPage });

// If parameters have been supplied use them, but override the paged parameters into them.
if (parameters != null)
Expand Down
12 changes: 6 additions & 6 deletions src/Tests/CloudFlare.NET.Tests/ZoneClientSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public class When_getting_all_zones : GetAllResultsContext<Zone>

Establish context = () =>
{
string firstParams = new PagedZoneParameters(page: 1, perPage: 100).ToQuery();
string secondParams = new PagedZoneParameters(page: 2, perPage: 100).ToQuery();
string lastParams = new PagedZoneParameters(page: 3, perPage: 100).ToQuery();
string firstParams = new PagedZoneParameters(page: 1, perPage: 50).ToQuery();
string secondParams = new PagedZoneParameters(page: 2, perPage: 50).ToQuery();
string lastParams = new PagedZoneParameters(page: 3, perPage: 50).ToQuery();

_expectedFirstRequestUri = new Uri(CloudFlareConstants.BaseUri, "zones?" + firstParams);
_expectedSecondRequestUri = new Uri(CloudFlareConstants.BaseUri, "zones?" + secondParams);
Expand Down Expand Up @@ -123,15 +123,15 @@ public class When_getting_all_zones_with_parameters : GetAllResultsContext<Zone>
_parameters = _fixture.Create<PagedZoneParameters>();

JObject first = JObject.FromObject(_parameters);
first.Merge(JObject.FromObject(new { page = 1, per_page = 100 }));
first.Merge(JObject.FromObject(new { page = 1, per_page = 50 }));
string firstParams = first.ToObject<PagedZoneParameters>().ToQuery();

JObject second = JObject.FromObject(_parameters);
second.Merge(JObject.FromObject(new { page = 2, per_page = 100 }));
second.Merge(JObject.FromObject(new { page = 2, per_page = 50 }));
string secondParams = second.ToObject<PagedZoneParameters>().ToQuery();

JObject last = JObject.FromObject(_parameters);
last.Merge(JObject.FromObject(new { page = 3, per_page = 100 }));
last.Merge(JObject.FromObject(new { page = 3, per_page = 50 }));
string lastParams = last.ToObject<PagedZoneParameters>().ToQuery();

_expectedFirstRequestUri = new Uri(CloudFlareConstants.BaseUri, "zones?" + firstParams);
Expand Down

0 comments on commit 2c86117

Please sign in to comment.