Пример #1
0
        public MoKeyWord UpdateMoKeyword(MoKeyWord keyword)
        {
            string       resource    = "/keywords/";
            const string contentType = "application/json";

            if (keyword == null)
            {
                throw new Exception("Parameter 'keyword' cannot be null");
            }
            resource += keyword.Id;
            var stringWriter = new StringWriter();

            new JsonSerializer().Serialize(stringWriter, keyword);
            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(new MoKeyWord(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString())));
            }
            string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString());

            throw new Exception("Request Failed : " + errorMessage);
        }
Пример #2
0
 /// <summary>
 ///     Update a keyword . Set the keyword id in the keyword object
 /// </summary>
 /// <param name="keyword">The keyword data <see cref="MoKeyWord" /></param>
 /// <returns>
 ///     <see cref="MoKeyWord" />
 /// </returns>
 /// <exception cref="Exception">Exception with the appropriate message</exception>
 public MoKeyWord UpdateMoKeyword(MoKeyWord keyword)
 {
     string resource = "/keywords/";
     const string contentType = "application/json";
     if (keyword == null) throw new Exception("Parameter 'keyword' cannot be null");
     resource += keyword.Id;
     var stringWriter = new StringWriter();
     new JsonSerializer().Serialize(stringWriter, keyword);
     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 new MoKeyWord(JsonConvert.DeserializeObject<ApiDictionary>(response.GetBodyAsString()));
     string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString());
     throw new Exception("Request Failed : " + errorMessage);
 }