Skip to content

Commit

Permalink
Add support for update user, get all users & custom fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jozsurf committed Apr 14, 2015
1 parent 3b58715 commit 2f1928c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Freshdesk/CreateUserRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ public class CreateUserRequest
[JsonProperty(PropertyName = "user")]
public User User { get; set; }
}

[JsonObject(MemberSerialization.OptIn)]
public class UpdateUserRequest
{
[JsonProperty(PropertyName = "user")]
public User User { get; set; }
}
}
27 changes: 26 additions & 1 deletion Freshdesk/FreshdeskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected virtual WebRequest SetupRequest(string method, Uri uri)

webRequest.Headers["Authorization"] = GetAuthorizationHeader(ApiKey);

if (method == "POST")
if (method == "POST" || method == "PUT")
{
//req.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentType = "application/json";
Expand Down Expand Up @@ -376,6 +376,31 @@ public GetUserResponse CreateUser(CreateUserRequest createUserRequest)
}
return DoRequest<GetUserResponse>(UriForPath("/contacts.json"), "POST", JsonConvert.SerializeObject(createUserRequest));
}

/// <summary>
/// Update a contact
/// </summary>
/// <param name="updateUserRequest"></param>
/// <param name="id"></param>
public void UpdateUser(UpdateUserRequest updateUserRequest, long id)
{
if (updateUserRequest == null)
{
throw new ArgumentNullException("updateUserRequest");
}
DoRequest<string>(UriForPath(string.Format("/contacts/{0}.json", id)), "PUT", JsonConvert.SerializeObject(updateUserRequest));
}

/// <summary>
/// Get users
/// </summary>
/// <returns></returns>
public IEnumerable<GetUserRequest> GetUsers()
{
return DoRequest<IEnumerable<GetUserRequest>>(UriForPath("/contacts.json"));
}


#endregion

}
Expand Down
10 changes: 10 additions & 0 deletions Freshdesk/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@

namespace Freshdesk
{
[JsonObject(MemberSerialization.OptIn)]
public class GetUserRequest
{
[JsonProperty("user")]
public User User { get; set; }
}

[JsonObject(MemberSerialization.OptIn)]
public class User
{
Expand Down Expand Up @@ -87,5 +94,8 @@ public class User

[JsonProperty(PropertyName = "active", NullValueHandling = NullValueHandling.Ignore)]
public bool? Active { get; set; }

[JsonProperty(PropertyName = "custom_field", NullValueHandling = NullValueHandling.Ignore)]
public Dictionary<string, string> CustomField { get; set; }
}
}

0 comments on commit 2f1928c

Please sign in to comment.