diff --git a/Freshdesk/CreateUserRequest.cs b/Freshdesk/CreateUserRequest.cs index 13ac387..25c6115 100644 --- a/Freshdesk/CreateUserRequest.cs +++ b/Freshdesk/CreateUserRequest.cs @@ -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; } + } } diff --git a/Freshdesk/FreshdeskService.cs b/Freshdesk/FreshdeskService.cs index fb81b0c..375bc86 100644 --- a/Freshdesk/FreshdeskService.cs +++ b/Freshdesk/FreshdeskService.cs @@ -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"; @@ -376,6 +376,31 @@ public GetUserResponse CreateUser(CreateUserRequest createUserRequest) } return DoRequest(UriForPath("/contacts.json"), "POST", JsonConvert.SerializeObject(createUserRequest)); } + + /// + /// Update a contact + /// + /// + /// + public void UpdateUser(UpdateUserRequest updateUserRequest, long id) + { + if (updateUserRequest == null) + { + throw new ArgumentNullException("updateUserRequest"); + } + DoRequest(UriForPath(string.Format("/contacts/{0}.json", id)), "PUT", JsonConvert.SerializeObject(updateUserRequest)); + } + + /// + /// Get users + /// + /// + public IEnumerable GetUsers() + { + return DoRequest>(UriForPath("/contacts.json")); + } + + #endregion } diff --git a/Freshdesk/User.cs b/Freshdesk/User.cs index ab2ade2..40c7a1b 100644 --- a/Freshdesk/User.cs +++ b/Freshdesk/User.cs @@ -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 { @@ -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 CustomField { get; set; } } }