Skip to content

Commit

Permalink
Merge pull request #5 from jozsurf/master
Browse files Browse the repository at this point in the history
GetUsers needs to support querystrings
  • Loading branch information
jjb3rd committed Aug 10, 2015
2 parents a58c335 + ebf3dd9 commit f5460f6
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions Freshdesk/FreshdeskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Freshdesk
{
Expand Down Expand Up @@ -218,12 +217,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<string, string> GetStringsContent(object instance)
{
Expand Down Expand Up @@ -396,10 +399,25 @@ public void UpdateUser(UpdateUserRequest updateUserRequest, long id)
/// Get users
/// </summary>
/// <returns></returns>
public IEnumerable<GetUserRequest> GetUsers()
{
return DoRequest<IEnumerable<GetUserRequest>>(UriForPath("/contacts.json"));
}
public IEnumerable<GetUserRequest> GetUsers()
{
var users = new List<GetUserRequest>();
var page = 1;
while (true)
{
var paginatedUsers = DoRequest<IEnumerable<GetUserRequest>>(UriForPath("/contacts.json", string.Format("page={0}", page))).ToList();
if (paginatedUsers.Any())
{
users.AddRange(paginatedUsers);
page++;
}
else
{
break;
}
}
return users;
}


#endregion
Expand Down

0 comments on commit f5460f6

Please sign in to comment.