-
Notifications
You must be signed in to change notification settings - Fork 86
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
[RED-1966] Adds support to an iterator and more CBP endpoints #322
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ac7f6df
adds support to CBP request on TicketAudits
fbvilela f28acfe
adds support to CBP requests on JobStatusResource
fbvilela f3484a6
adds support to CBP on Request resources
fbvilela 1ef97bd
add support to an iterator
fbvilela 1914506
Merge branch 'develop' into fvilela/iterator
fbvilela ad30118
Merge branch 'develop' into fvilela/iterator
fbvilela 69f86c3
remove PaginatedResource and insert ApiClient dependency into the Cur…
fbvilela ee80494
Merge branch 'develop' into fvilela/iterator
fbvilela 8d03f2e
wip
fbvilela 5d26c02
Refactor Iterator factory and add to the list of registered services
fbvilela ab87126
small refactoring, addressing comments
fbvilela 0af94f4
address comments and add new factory to the tests
fbvilela 12dab12
bump version
fbvilela 20dd4ae
fix tests regarding mmethod that had been made obsolete which caused …
fbvilela File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,4 @@ public interface IZendeskClient | |
ILocaleResource Locales { get; } | ||
ITagsResource Tags { get; } | ||
} | ||
} | ||
} |
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,74 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using ZendeskApi.Client; | ||
using ZendeskApi.Client.Responses; | ||
|
||
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)); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a namespace to this class? And then move it into the Pagination folder?