diff --git a/src/ZendeskApi_v2/Requests/Users.cs b/src/ZendeskApi_v2/Requests/Users.cs index 94bf9d83..50989863 100644 --- a/src/ZendeskApi_v2/Requests/Users.cs +++ b/src/ZendeskApi_v2/Requests/Users.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using ZendeskApi_v2.Extensions; #if ASYNC @@ -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); @@ -64,6 +69,11 @@ public interface IUsers : ICore #if ASYNC Task GetCurrentUserAsync(); Task GetAllUsersAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None); + Task GetAllAgentsAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None); + Task GetAllAdminsAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None); + Task GetAllEndUsersAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None); + Task GetAllUsersInRolesAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None, bool agents = false, bool endUsers = false, bool admins = false); + Task GetAllUsersInEnterpriseRoleAsync(long enterpriseRoleId, int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None); Task GetUserAsync(long id); Task GetUserRelatedInformationAsync(long id); Task MergeUserAsync(long fromId, long intoId); @@ -119,6 +129,52 @@ public GroupUserResponse GetAllUsers(int? perPage = null, int? page = null, User return GenericPagedGet(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(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(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(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(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(resource, perPage, page); + } + public IndividualUserResponse GetUser(long id) { return GenericGet($"users/{id}.json"); @@ -287,6 +343,42 @@ public async Task GetAllUsersAsync(int? perPage = null, int? return await GenericPagedGetAsync("users.json", perPage, page); } + public async Task GetAllAgentsAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None) + { + return await GenericPagedGetAsync("users.json?role=agent", perPage, page); + } + + public async Task GetAllAdminsAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None) + { + return await GenericPagedGetAsync("users.json?role=admin", perPage, page); + } + + public async Task GetAllEndUsersAsync(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None) + { + return await GenericPagedGetAsync("users.json?role=end-user", perPage, page); + } + + public async Task 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(resourceString, perPage, page); + } + + public async Task GetAllUsersInEnterpriseRoleAsync(long enterpriseRoleId, int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None) + { + return await GenericPagedGetAsync($"users.json?permission_set={enterpriseRoleId}", perPage, page); + } + public async Task GetUserAsync(long id) { return await GenericGetAsync($"users/{id}.json"); diff --git a/test/ZendeskApi_v2.Test/UserTests.cs b/test/ZendeskApi_v2.Test/UserTests.cs index 96a9f9da..dc939582 100644 --- a/test/ZendeskApi_v2.Test/UserTests.cs +++ b/test/ZendeskApi_v2.Test/UserTests.cs @@ -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()