Skip to content

Commit

Permalink
Implementation of "Users.GetIncrementalUserExport" and "Users.GetInc…
Browse files Browse the repository at this point in the history
…rementalUserExportNextPage" (+Async versions) (Speedygeek#347)

* Test "CanCreateTicketWithDueDate" can't run on PCs that use dd/MM/yyyy as time format

* Added Code to make tests work

* - Added support for issue Speedygeek#330
- Added support for CRUD operations of Comments on Articles and Posts

* Implementation of "Users.GetIncrementalUserExport" and "Users.GetIncrementalUserExportNextPage" (+Async versions)

* Changes to PR based on @mozts2005’s request

* Changed Assert Style
  • Loading branch information
rwjdk-test authored and mozts2005 committed Jun 23, 2018
1 parent ee639b2 commit 5822e69
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/ZendeskApi_v2/Models/Users/GroupUserExportResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using ZendeskApi_v2.Models.Organizations;

namespace ZendeskApi_v2.Models.Users
{
public class GroupUserExportResponse
{
[JsonProperty("count")]
public long Count { get; set; }

[JsonProperty("end_time")]
[JsonConverter(typeof(UnixDateTimeConverter))]
public DateTimeOffset EndTime { get; set; }

[JsonProperty("next_page")]
public string NextPage { get; set; }

[JsonProperty("organizations")]
public IList<Organization> Organizations { get; set; }

[JsonProperty("identities")]
public IList<UserIdentity> Identities { get; set; }

[JsonProperty("groups")]
public IList<Groups.Group> Groups { get; set; }

[JsonProperty("users")]
public IList<User> Users { get; set; }
}
}
41 changes: 41 additions & 0 deletions src/ZendeskApi_v2/Requests/Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public interface IUsers : ICore

IndividualUserResponse SetUserPhoto(long userId, ZenFile photo);

GroupUserExportResponse GetIncrementalUserExport(DateTimeOffset startTime, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None);

GroupUserExportResponse GetIncrementalUserExportNextPage(string nextPage);
#endif

#if ASYNC
Expand Down Expand Up @@ -183,11 +186,17 @@ public interface IUsers : ICore

Task<IndividualUserResponse> SetUserPhotoAsync(long userId, ZenFile photo);

Task<GroupUserExportResponse> GetIncrementalUserExportAsync(DateTimeOffset startTime, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None);

Task<GroupUserExportResponse> GetIncrementalUserExportNextPageAsync(string nextPage);

#endif
}

public class Users : Core, IUsers
{
private const string _incremental_export = "incremental/users.json?start_time=";

public Users(string yourZendeskUrl, string user, string password, string apiToken, string p_OAuthToken)
: base(yourZendeskUrl, user, password, apiToken, p_OAuthToken)
{
Expand Down Expand Up @@ -426,6 +435,22 @@ public IndividualUserResponse SetUserPhoto(long userId, ZenFile photo)
return GenericPut<IndividualUserResponse>($"users/{userId}.json", null, new Dictionary<string, object> { { "user[photo][uploaded_data]", photo } });
}

public GroupUserExportResponse GetIncrementalUserExport(DateTimeOffset startTime, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None)
{
var resource =
GetResourceStringWithSideLoadOptionsParam(
_incremental_export + startTime.UtcDateTime.GetEpoch(),
sideLoadOptions);

return GenericGet<GroupUserExportResponse>(resource);
}

public GroupUserExportResponse GetIncrementalUserExportNextPage(string nextPage)
{
var resource = nextPage.Replace(ZendeskUrl, string.Empty);

return GenericGet<GroupUserExportResponse>(resource);
}
#endif

#if ASYNC
Expand Down Expand Up @@ -647,6 +672,22 @@ public Task<IndividualUserResponse> SetUserPhotoAsync(long userId, ZenFile photo
return GenericPutAsync<IndividualUserResponse>($"users/{userId}.json", null, new Dictionary<string, object> { { "user[photo][uploaded_data]", photo } });
}

public async Task<GroupUserExportResponse> GetIncrementalUserExportAsync(DateTimeOffset startTime, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None)
{
var resource =
GetResourceStringWithSideLoadOptionsParam(
_incremental_export + startTime.UtcDateTime.GetEpoch(),
sideLoadOptions);

return await GenericGetAsync<GroupUserExportResponse>(resource);
}

public async Task<GroupUserExportResponse> GetIncrementalUserExportNextPageAsync(string nextPage)
{
var resource = nextPage.Replace(ZendeskUrl, string.Empty);

return await GenericGetAsync<GroupUserExportResponse>(resource);
}
#endif

private string GetResourceStringWithSideLoadOptionsParam(string resource, UserSideLoadOptions sideLoadOptions)
Expand Down
64 changes: 64 additions & 0 deletions test/ZendeskApi_v2.Test/UserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,5 +497,69 @@ public void CanBulkDeleteUsers()
Assert.AreEqual(JobStatusCompleted, jobResponse.JobStatus.Status.ToLower());
Assert.AreEqual(users.Count, jobResponse.JobStatus.Total);
}

[Test]
public void CanGetIncrementalUserExport()
{
var incrementalUserExport = api.Users.GetIncrementalUserExport(DateTimeOffset.MinValue);
Assert.That(incrementalUserExport.Users.Count, Is.GreaterThan(0));
Assert.That(incrementalUserExport.Organizations, Is.Null);
Assert.That(incrementalUserExport.Identities, Is.Null);
Assert.That(incrementalUserExport.Groups, Is.Null);

var incrementalUserExportNextPage = api.Users.GetIncrementalUserExportNextPage(incrementalUserExport.NextPage);
Assert.That(incrementalUserExportNextPage.Users.Count, Is.GreaterThan(0));
Assert.That(incrementalUserExportNextPage.Organizations, Is.Null);
Assert.That(incrementalUserExportNextPage.Identities, Is.Null);
Assert.That(incrementalUserExportNextPage.Groups, Is.Null);
}

[Test]
public void CanGetIncrementalUserExportWithSideLoadOptions()
{
var incrementalUserExport = api.Users.GetIncrementalUserExport(DateTimeOffset.MinValue, UserSideLoadOptions.Organizations | UserSideLoadOptions.Groups | UserSideLoadOptions.Identities);
Assert.That(incrementalUserExport.Users.Count, Is.GreaterThan(0));
Assert.That(incrementalUserExport.Organizations, Is.Not.Null);
Assert.That(incrementalUserExport.Identities, Is.Not.Null);
Assert.That(incrementalUserExport.Groups, Is.Not.Null);

var incrementalUserExportNextPage = api.Users.GetIncrementalUserExportNextPage(incrementalUserExport.NextPage);
Assert.That(incrementalUserExportNextPage.Users.Count, Is.GreaterThan(0));
Assert.That(incrementalUserExportNextPage.Organizations, Is.Not.Null);
Assert.That(incrementalUserExportNextPage.Identities, Is.Not.Null);
Assert.That(incrementalUserExportNextPage.Groups, Is.Not.Null);
}

[Test]
public async Task CanGetIncrementalUserExportAsync()
{
var incrementalUserExport = await api.Users.GetIncrementalUserExportAsync(DateTimeOffset.MinValue);
Assert.That(incrementalUserExport.Users.Count, Is.GreaterThan(0));
Assert.That(incrementalUserExport.Organizations, Is.Null);
Assert.That(incrementalUserExport.Identities, Is.Null);
Assert.That(incrementalUserExport.Groups, Is.Null);

var incrementalUserExportNextPage = await api.Users.GetIncrementalUserExportNextPageAsync(incrementalUserExport.NextPage);
Assert.That(incrementalUserExportNextPage.Users.Count, Is.GreaterThan(0));
Assert.That(incrementalUserExportNextPage.Organizations, Is.Null);
Assert.That(incrementalUserExportNextPage.Identities, Is.Null);
Assert.That(incrementalUserExportNextPage.Groups, Is.Null);
}

[Test]
public async Task CanGetIncrementalUserExportAsyncWithSideLoadOptions()
{
var incrementalUserExport = await api.Users.GetIncrementalUserExportAsync(DateTimeOffset.MinValue, UserSideLoadOptions.Organizations | UserSideLoadOptions.Groups | UserSideLoadOptions.Identities);
Assert.That(incrementalUserExport.Users.Count > 0);
Assert.That(incrementalUserExport.Organizations, Is.Not.Null);
Assert.That(incrementalUserExport.Identities, Is.Not.Null);
Assert.That(incrementalUserExport.Groups, Is.Not.Null);

var incrementalUserExportNextPage = await api.Users.GetIncrementalUserExportNextPageAsync(incrementalUserExport.NextPage);
Assert.That(incrementalUserExportNextPage.Users.Count > 0);
Assert.That(incrementalUserExportNextPage.Organizations, Is.Not.Null);
Assert.That(incrementalUserExportNextPage.Identities, Is.Not.Null);
Assert.That(incrementalUserExportNextPage.Groups, Is.Not.Null);
}
}
}

0 comments on commit 5822e69

Please sign in to comment.