From ebf3dd9232ab1dc004ca44706e14611096825d36 Mon Sep 17 00:00:00 2001 From: Joseph Poh Date: Thu, 14 May 2015 10:44:48 +1200 Subject: [PATCH] GetUsers needs to support querystrings Mainly for pagination and filters --- Freshdesk/FreshdeskService.cs | 40 +++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/Freshdesk/FreshdeskService.cs b/Freshdesk/FreshdeskService.cs index 375bc86..8872b69 100644 --- a/Freshdesk/FreshdeskService.cs +++ b/Freshdesk/FreshdeskService.cs @@ -30,7 +30,6 @@ using System.Linq; using System.Net; using System.Text; -using System.Threading.Tasks; namespace Freshdesk { @@ -217,12 +216,16 @@ protected virtual string DoMultipartFormRequest(Uri uri, object body, IEnumerabl return GetResponseAsString(response); } - protected virtual Uri UriForPath(string path) - { - UriBuilder uriBuilder = new UriBuilder(this.ApiUri); - uriBuilder.Path = path; - return uriBuilder.Uri; - } + protected virtual Uri UriForPath(string path, string query = null) + { + UriBuilder uriBuilder = new UriBuilder(this.ApiUri); + uriBuilder.Path = path; + if (!string.IsNullOrEmpty(query)) + { + uriBuilder.Query = query; + } + return uriBuilder.Uri; + } private static Dictionary GetStringsContent(object instance) { @@ -395,10 +398,25 @@ public void UpdateUser(UpdateUserRequest updateUserRequest, long id) /// Get users /// /// - public IEnumerable GetUsers() - { - return DoRequest>(UriForPath("/contacts.json")); - } + public IEnumerable GetUsers() + { + var users = new List(); + var page = 1; + while (true) + { + var paginatedUsers = DoRequest>(UriForPath("/contacts.json", string.Format("page={0}", page))).ToList(); + if (paginatedUsers.Any()) + { + users.AddRange(paginatedUsers); + page++; + } + else + { + break; + } + } + return users; + } #endregion