Exemple #1
0
 /// <summary>
 ///     Updae a contact group
 /// </summary>
 /// <param name="data">The contact group data <see cref="ContactGroup" /></param>
 /// <returns>true when successful.</returns>
 /// <exception cref="Exception">Exception with the appropriate message</exception>
 public bool UpdateContactGroup(ContactGroup data)
 {
     string resource = "/contacts/groups/";
     const string contentType = "application/json";
     if (data == null) throw new Exception("Parameter 'data' cannot be null");
     resource += data.GroupId;
     var stringWriter = new StringWriter();
     new JsonSerializer().Serialize(stringWriter, data);
     HttpResponse response = RestClient.Put(resource, contentType, Encoding.UTF8.GetBytes(stringWriter.ToString()));
     if (response == null) throw new Exception("Request Failed. Unable to get server response");
     if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) return true;
     string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString());
     throw new Exception("Request Failed : " + errorMessage);
 }
Exemple #2
0
 /// <summary>
 ///     Add a contact group
 /// </summary>
 /// <param name="group">The contact group object</param>
 /// <returns>A <see cref="ContactGroup" /> object.</returns>
 /// <exception cref="Exception">Exception with the appropriate message</exception>
 public ContactGroup AddContactGroup(ContactGroup group)
 {
     const string resource = "/contacts/groups/";
     const string contentType = "application/json";
     if (group == null) throw new HttpRequestException(new Exception("Parameter 'group' cannot be null"));
     var stringWriter = new StringWriter();
     new JsonSerializer().Serialize(stringWriter, group);
     HttpResponse response = RestClient.Post(resource, contentType, Encoding.UTF8.GetBytes(stringWriter.ToString()));
     if (response == null) throw new Exception("Request Failed. Unable to get server response");
     if (response.Status == Convert.ToInt32(HttpStatusCode.Created)) return new ContactGroup(JsonConvert.DeserializeObject<ApiDictionary>(response.GetBodyAsString()));
     string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString());
     throw new Exception("Request Failed : " + errorMessage);
 }