Skip to content

Commit

Permalink
Merge pull request #317 from justeat/develop
Browse files Browse the repository at this point in the history
develop -> master
  • Loading branch information
mikerogers123 authored Oct 19, 2023
2 parents cb1a855 + 6bb6c88 commit 4e562eb
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/ZendeskApi.Build/ZendeskApi.Commons.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>

<RepositoryType>git</RepositoryType>
<RepositoryUrl>$(PackageProjectUrl).git</RepositoryUrl>
</PropertyGroup>
<PropertyGroup>
<Major>7</Major>
<Minor>0</Minor>
<Revision>0</Revision>
<Revision>1</Revision>
<PackageVersion>$(Major).$(Minor).$(Revision)</PackageVersion>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public async Task<ZendeskRequestException> Build()

if (error?.Error != null && error.Description != null)
{
message.AppendLine($"{error.Error}: {error.Description}.");
var detail = Environment.NewLine + JsonConvert.SerializeObject(error.Details, Formatting.Indented);
message.AppendLine($"{error.Error}: {error.Description}. {detail}");
}
}

Expand Down
17 changes: 12 additions & 5 deletions src/ZendeskApi.Client/Extensions/HttpClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ZendeskApi.Client.Extensions
{
public static class HttpClientExtensions
{
public static Task<HttpResponseMessage> GetAsync(this HttpClient client, string requestUri, PagerParameters parameters = null,
public static Task<HttpResponseMessage> GetAsync(this HttpClient client, string requestUri, PagerParameters parameters = null,
CancellationToken cancellationToken = default)
{
var pager = new Pager(parameters?.Page, parameters?.PageSize, 100);
Expand All @@ -30,10 +30,10 @@ public static Task<HttpResponseMessage> GetAsync(this HttpClient client, string
/// https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_audits/#pagination
public static Task<HttpResponseMessage> GetAsync(this HttpClient client, string requestUri, CursorPagerVariant pager,
CancellationToken cancellationToken = default)
{
{
if (pager == null)
pager = new CursorPagerVariant();

if (!string.IsNullOrEmpty(pager.Cursor))
{
var encodedCursor = Uri.EscapeDataString(pager.Cursor);
Expand All @@ -56,13 +56,20 @@ public static Task<HttpResponseMessage> GetAsync(this HttpClient client, string
public static Task<HttpResponseMessage> GetAsync(this HttpClient client, string requestUri, CursorPager pager,
CancellationToken cancellationToken = default)
{
if (pager == null)
pager = new CursorPager();
if (pager == null) pager = new CursorPager();

if (requestUri.Contains("?"))
{
requestUri += $"&page[size]={pager.Size}";
}
else
{
requestUri += $"?page[size]={pager.Size}";
}

if (!string.IsNullOrEmpty(pager.AfterCursor)) requestUri += $"&page[after]={pager.AfterCursor}";

if (!string.IsNullOrEmpty(pager.BeforeCursor)) requestUri += $"&page[before]={pager.BeforeCursor}";

return client.GetAsync(requestUri, cancellationToken);
}
Expand Down
3 changes: 3 additions & 0 deletions src/ZendeskApi.Client/Models/CursorPager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ namespace ZendeskApi.Client.Models
public class CursorPager
{
public int Size { get; set; } = 100;
public string BeforeCursor { get; set; }
public string AfterCursor { get; set; }

}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
Expand Down Expand Up @@ -37,7 +38,7 @@ public async Task GetAllAsync_WhenCalledWithCursorPagination_ShouldReturnSpecifi
var results = await client
.Tickets.GetAllAsync(new CursorPager()
{
Size=10
Size = 10
});

Assert.NotNull(results);
Expand Down Expand Up @@ -67,5 +68,29 @@ public async Task GetAllByOrganizationIdAsync_WhenCalledWithCursorPagination_Sho
await client.Tickets.DeleteAsync(createdTicket.Ticket.Id);
}
}

[Fact]
public async Task GetAllAsync_WhenCalledWithCursorPagination_ShouldBePaginatable()
{
var client = _clientFactory.GetClient();

var cursorPager = new CursorPager { Size = 5 };
var ticketsPageOne = await client
.Tickets.GetAllAsync(cursorPager);

Assert.NotNull(ticketsPageOne);
Assert.Equal(5, ticketsPageOne.Count());
Assert.True(ticketsPageOne.Meta.HasMore);

cursorPager.AfterCursor = ticketsPageOne.Meta.AfterCursor;

var ticketsPageTwo = await client.Tickets.GetAllAsync(cursorPager);
Assert.NotNull(ticketsPageTwo);
Assert.Equal(5, ticketsPageTwo.Count());

var ticketIdsPageOne = ticketsPageOne.Select(ticket => ticket.Id).ToList();
var ticketIdsPageTwo = ticketsPageTwo.Select(ticket => ticket.Id).ToList();
Assert.NotEqual(ticketIdsPageOne, ticketIdsPageTwo);
}
}
}

0 comments on commit 4e562eb

Please sign in to comment.