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

develop -> master (#319 #316) #320

Merged
merged 11 commits into from
Nov 15, 2023
2 changes: 1 addition & 1 deletion src/ZendeskApi.Build/ZendeskApi.Commons.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PropertyGroup>
<Major>7</Major>
<Minor>0</Minor>
<Revision>2</Revision>
<Revision>5</Revision>
<PackageVersion>$(Major).$(Minor).$(Revision)</PackageVersion>
</PropertyGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/ZendeskApi.Client/IZendeskClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public interface IZendeskClient
IServiceStatusResource ServiceStatus { get; }
IHelpCenterResource HelpCenter { get; }
ILocaleResource Locales { get; }
ITagsResource Tags { get; }
}
}
12 changes: 12 additions & 0 deletions src/ZendeskApi.Client/Models/Tag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;
namespace ZendeskApi.Client.Models
{
public class Tag
{
[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("count")]
public int Count { get; set; }
}
}
6 changes: 6 additions & 0 deletions src/ZendeskApi.Client/Requests/Ticket/TicketUpdateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,11 @@ public TicketUpdateRequest(long id)

[JsonProperty("brand_id")]
public long? BrandId { get; set; }

/// <summary>
/// The id of the ticket form to use. Only applicable for enterprise accounts
/// </summary>
[JsonProperty("ticket_form_id")]
public long? FormId { get; set; }
}
}
21 changes: 21 additions & 0 deletions src/ZendeskApi.Client/Resources/Interfaces/ITagsResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Threading;
using System.Threading.Tasks;
using ZendeskApi.Client.Models;
using ZendeskApi.Client.Responses;

namespace ZendeskApi.Client.Resources.Interfaces
{
public interface ITagsResource
{
#region List
/// <summary>
/// Lists all tags. This request is paginated.
/// </summary>
Task<ICursorPagination<Tag>> GetAllAsync(
CursorPager cursor,
CancellationToken cancellationToken = default(CancellationToken));

#endregion
}
}

28 changes: 28 additions & 0 deletions src/ZendeskApi.Client/Resources/TagsResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using ZendeskApi.Client.Models;
using ZendeskApi.Client.Resources.Interfaces;
using ZendeskApi.Client.Responses;

namespace ZendeskApi.Client.Resources
{
public class TagsResource : AbstractBaseResource<TagsResource>, ITagsResource
{
private static string ResourceUri = "/api/v2/tags";
public TagsResource(IZendeskApiClient apiClient, ILogger logger) : base(apiClient, logger, "tags")
{
}

public async Task<ICursorPagination<Tag>> GetAllAsync(CursorPager cursor, CancellationToken cancellationToken = default)
{
return await GetAsync<TagResponse>(
ResourceUri,
"list-tags",
"ListAsync",
cursor,
cancellationToken: cancellationToken);
}
}
}

15 changes: 15 additions & 0 deletions src/ZendeskApi.Client/Responses/Tag/TagResponse.cs
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 TagResponse : CursorPaginationResponse<Tag>
{
[JsonProperty("tags")]
public IEnumerable<Tag> Tags { get; set; }

protected override IEnumerable<Tag> Enumerable => Tags;
}
}
3 changes: 3 additions & 0 deletions src/ZendeskApi.Client/ZendeskClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,8 @@ public ZendeskClient(IZendeskApiClient apiClient, ILogger logger = null)
private Lazy<ILocaleResource> LocalesLazy =>
new Lazy<ILocaleResource>(() => new LocaleResource(_apiClient, _logger));
public ILocaleResource Locales => LocalesLazy.Value;

private Lazy<ITagsResource> TagsLazy => new Lazy<ITagsResource>(() => new TagsResource(_apiClient, _logger));
public ITagsResource Tags => TagsLazy.Value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using ZendeskApi.Client.IntegrationTests.Factories;
using ZendeskApi.Client.Models;

namespace ZendeskApi.Client.IntegrationTests.Resources
{
public class TagsResourceTest : IClassFixture<ZendeskClientFactory>
{
private readonly ZendeskClientFactory _clientFactory;

public TagsResourceTest(
ZendeskClientFactory clientFactory)
{
_clientFactory = clientFactory;
}


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

try
{
var cursorPager = new CursorPager { Size = 2 };
var tagsPageOne = await client
.Tags.GetAllAsync(cursorPager);

Assert.NotNull(tagsPageOne);
Assert.Equal(2, tagsPageOne.Count());
Assert.True(tagsPageOne.Meta.HasMore);

cursorPager.AfterCursor = tagsPageOne.Meta.AfterCursor;

var tagsPageTwo = await client.Tags.GetAllAsync(cursorPager);
Assert.NotNull(tagsPageTwo);
Assert.Equal(2, tagsPageTwo.Count());

var tagIdsPageOne = tagsPageOne.Select(tag => tag.Name).ToList();
var tagIdsPageTwo = tagsPageTwo.Select(tag => tag.Name).ToList();
Assert.NotEqual(tagIdsPageOne, tagIdsPageTwo);
}
finally
{
await CleanupTicketAsync(client, ticket);
}

}

private async Task<Ticket> CreateTicketWithTagsAsync(IZendeskClient client)
{
var ticketResponse = await client.Tickets.CreateAsync(new Requests.TicketCreateRequest {
Tags = new List<string> { "apac", "shipping", "sales", "important", "sla" },
Comment = new TicketComment { Body = "This is a ticket with 5 of tags" },
Subject = "Test ticket"
}
);
return ticketResponse.Ticket;
}

private async Task CleanupTicketAsync(IZendeskClient client, Ticket ticket)
{
await client.Tickets.DeleteAsync(ticket.Id);
}
}
}