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

Issue 300 #301

Merged
merged 2 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 93 additions & 1 deletion src/ZendeskApi_v2/Requests/Users.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using ZendeskApi_v2.Extensions;
#if ASYNC
Expand Down Expand Up @@ -27,6 +27,11 @@ public interface IUsers : ICore
#if SYNC
IndividualUserResponse GetCurrentUser();
GroupUserResponse GetAllUsers(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None);
GroupUserResponse GetAllAgents(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None);
GroupUserResponse GetAllAdmins(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None);
GroupUserResponse GetAllEndUsers(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None);
GroupUserResponse GetAllUsersInRoles(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None, bool agents = false, bool endUsers = false, bool admins = false);
GroupUserResponse GetAllUsersInEnterpriseRole(long enterpriseRoleId, int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None);
IndividualUserResponse GetUser(long id);
IndividualUserRelatedInformationResponse GetUserRelatedInformation(long id);
IndividualUserResponse MergeUser(long fromId, long intoId);
Expand Down Expand Up @@ -64,6 +69,11 @@ public interface IUsers : ICore
#if ASYNC
Task<IndividualUserResponse> GetCurrentUserAsync();
Task<GroupUserResponse> GetAllUsersAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None);
Task<GroupUserResponse> GetAllAgentsAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None);
Task<GroupUserResponse> GetAllAdminsAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None);
Task<GroupUserResponse> GetAllEndUsersAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None);
Task<GroupUserResponse> GetAllUsersInRolesAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None, bool agents = false, bool endUsers = false, bool admins = false);
Task<GroupUserResponse> GetAllUsersInEnterpriseRoleAsync(long enterpriseRoleId, int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None);
Task<IndividualUserResponse> GetUserAsync(long id);
Task<IndividualUserRelatedInformationResponse> GetUserRelatedInformationAsync(long id);
Task<IndividualUserResponse> MergeUserAsync(long fromId, long intoId);
Expand Down Expand Up @@ -119,6 +129,52 @@ public GroupUserResponse GetAllUsers(int? perPage = null, int? page = null, User
return GenericPagedGet<GroupUserResponse>(resource, perPage, page);
}

public GroupUserResponse GetAllAgents(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None)
{
string resource = GetResourceStringWithSideLoadOptionsParam("users.json?role=agent", sideLoadOptions);

return GenericPagedGet<GroupUserResponse>(resource, perPage, page);
}

public GroupUserResponse GetAllAdmins(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None)
{
string resource = GetResourceStringWithSideLoadOptionsParam("users.json?role=admin", sideLoadOptions);

return GenericPagedGet<GroupUserResponse>(resource, perPage, page);
}

public GroupUserResponse GetAllEndUsers(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None)
{
string resource = GetResourceStringWithSideLoadOptionsParam("users.json?role=end-user", sideLoadOptions);

return GenericPagedGet<GroupUserResponse>(resource, perPage, page);
}

public GroupUserResponse GetAllUsersInRoles(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None, bool agents = false, bool endUsers = false, bool admins = false)
{
var resourceString = "users.json?";

if (agents)
resourceString += "role[]=agent&";
if (endUsers)
resourceString += "role[]=end-user&";
if (admins)
resourceString += "role[]=admin&";

resourceString = resourceString.TrimEnd('&');

string resource = GetResourceStringWithSideLoadOptionsParam(resourceString, sideLoadOptions);

return GenericPagedGet<GroupUserResponse>(resource, perPage, page);
}

public GroupUserResponse GetAllUsersInEnterpriseRole(long enterpriseRoleId, int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None)
{
string resource = GetResourceStringWithSideLoadOptionsParam($"users.json?permission_set={enterpriseRoleId}", sideLoadOptions);

return GenericPagedGet<GroupUserResponse>(resource, perPage, page);
}

public IndividualUserResponse GetUser(long id)
{
return GenericGet<IndividualUserResponse>($"users/{id}.json");
Expand Down Expand Up @@ -287,6 +343,42 @@ public async Task<GroupUserResponse> GetAllUsersAsync(int? perPage = null, int?
return await GenericPagedGetAsync<GroupUserResponse>("users.json", perPage, page);
}

public async Task<GroupUserResponse> GetAllAgentsAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None)
{
return await GenericPagedGetAsync<GroupUserResponse>("users.json?role=agent", perPage, page);
}

public async Task<GroupUserResponse> GetAllAdminsAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None)
{
return await GenericPagedGetAsync<GroupUserResponse>("users.json?role=admin", perPage, page);
}

public async Task<GroupUserResponse> GetAllEndUsersAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None)
{
return await GenericPagedGetAsync<GroupUserResponse>("users.json?role=end-user", perPage, page);
}

public async Task<GroupUserResponse> GetAllUsersInRolesAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None, bool agents = false, bool endUsers = false, bool admins = false)
{
var resourceString = "users.json?";

if (agents)
resourceString += "role[]=agent&";
if (endUsers)
resourceString += "role[]=end-user&";
if (admins)
resourceString += "role[]=admin&";

resourceString = resourceString.TrimEnd('&');

return await GenericPagedGetAsync<GroupUserResponse>(resourceString, perPage, page);
}

public async Task<GroupUserResponse> GetAllUsersInEnterpriseRoleAsync(long enterpriseRoleId, int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None)
{
return await GenericPagedGetAsync<GroupUserResponse>($"users.json?permission_set={enterpriseRoleId}", perPage, page);
}

public async Task<IndividualUserResponse> GetUserAsync(long id)
{
return await GenericGetAsync<IndividualUserResponse>($"users/{id}.json");
Expand Down
28 changes: 28 additions & 0 deletions test/ZendeskApi_v2.Test/UserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,34 @@ public void CanGetUsers()
var res = api.Users.GetAllUsers();
Assert.True(res.Count > 0);
}

[Test]
public void CanGetAgents()
{
var res = api.Users.GetAllAgents();
Assert.True(res.Count > 0);
}

[Test]
public void CanGetAdmins()
{
var res = api.Users.GetAllAdmins();
Assert.True(res.Count > 0);
}

[Test]
public void CanGetEndUsers()
{
var res = api.Users.GetAllEndUsers();
Assert.True(res.Count > 0);
}

[Test]
public void CanGetAllUsersInRoles()
{
var res = api.Users.GetAllUsersInRoles(agents: true, admins: true);
Assert.True(res.Count > 0);
}

[Test]
public void CanGetUserByCustomField()
Expand Down