-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from justeat/develop
develop -> master ([RED-2026])
- Loading branch information
Showing
24 changed files
with
450 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,4 @@ public interface IZendeskClient | |
ILocaleResource Locales { get; } | ||
ITagsResource Tags { get; } | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/ZendeskApi.Client/Pagination/CursorPaginatedIterator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using ZendeskApi.Client.Responses; | ||
|
||
namespace ZendeskApi.Client.Pagination; | ||
public class CursorPaginatedIterator<T> : IEnumerable<T> | ||
{ | ||
|
||
public ICursorPagination<T> Response { get; set; } | ||
|
||
private IZendeskApiClient client; | ||
|
||
|
||
private string ResponseType { get; } | ||
|
||
public CursorPaginatedIterator(ICursorPagination<T> response, IZendeskApiClient client) | ||
{ | ||
Response = response; | ||
this.client = client; | ||
ResponseType = response.GetType().FullName; | ||
} | ||
|
||
public bool HasMore() => Response.Meta.HasMore; | ||
|
||
public IEnumerator<T> GetEnumerator() | ||
{ | ||
return Response.GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return Response.GetEnumerator(); | ||
} | ||
|
||
|
||
public async Task NextPage() | ||
{ | ||
await ExecuteRequest(Response.Links.Next); | ||
} | ||
|
||
public async Task PrevPage() | ||
{ | ||
await ExecuteRequest(Response.Links.Prev); | ||
} | ||
|
||
public async IAsyncEnumerable<T> All() | ||
{ | ||
foreach (var item in Response) | ||
{ | ||
yield return item; | ||
} | ||
while (HasMore()) | ||
{ | ||
await NextPage(); | ||
foreach (var item in Response) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
yield break; | ||
} | ||
|
||
private async Task ExecuteRequest(string requestUrl) | ||
{ | ||
var httpResponseMessage = await client.CreateClient().GetAsync(requestUrl); | ||
var responseBody = await httpResponseMessage.Content.ReadAsStringAsync(); | ||
Response = (ICursorPagination<T>)JsonConvert.DeserializeObject(responseBody, Type.GetType(ResponseType)); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/ZendeskApi.Client/Pagination/CursorPaginatedIteratorFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using ZendeskApi.Client.Responses; | ||
|
||
namespace ZendeskApi.Client.Pagination | ||
{ | ||
public interface ICursorPaginatedIteratorFactory | ||
{ | ||
CursorPaginatedIterator<T> Create<T>(ICursorPagination<T> response); | ||
} | ||
|
||
public class CursorPaginatedIteratorFactory : ICursorPaginatedIteratorFactory | ||
{ | ||
private readonly IZendeskApiClient zendeskApiClient; | ||
|
||
public CursorPaginatedIteratorFactory(IZendeskApiClient _zendeskApiClient) | ||
{ | ||
zendeskApiClient = _zendeskApiClient; | ||
} | ||
|
||
public CursorPaginatedIterator<T> Create<T>(ICursorPagination<T> response) | ||
{ | ||
return new CursorPaginatedIterator<T>(response, zendeskApiClient); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
15 changes: 15 additions & 0 deletions
15
src/ZendeskApi.Client/Responses/JobStatus/JobStatusListCursorResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using ZendeskApi.Client.Models; | ||
|
||
namespace ZendeskApi.Client.Responses | ||
{ | ||
[JsonObject] | ||
public class JobStatusListCursorResponse : CursorPaginationResponse<JobStatusResponse> | ||
{ | ||
[JsonProperty("job_statuses")] | ||
public IEnumerable<JobStatusResponse> JobStatuses { get; set; } | ||
|
||
protected override IEnumerable<JobStatusResponse> Enumerable => JobStatuses; | ||
} | ||
} |
Oops, something went wrong.