/// <summary>
        ///     Creates a new content library and returns the created content metadata.
        /// </summary>
        /// <param name="library">Content Library to create</param>
        /// <returns>ContentLibrary</returns>
        /// <exception cref="Exception"></exception>
        /// <exception cref="Exception"></exception>
        public ContentLibrary AddContentLibrary(ContentLibrary library)
        {
            const string resource    = "/libraries/";
            const string contentType = "application/json";

            if (library == null)
            {
                throw new HttpRequestException(new Exception("Parameter 'library' cannot be null"));
            }
            var stringWriter = new StringWriter();

            new JsonSerializer().Serialize(stringWriter, library);

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

            throw new Exception("Request Failed : " + errorMessage);
        }
Beispiel #2
0
        /// <summary>
        ///     Creates a new content library and returns the created content metadata.
        /// </summary>
        /// <param name="library">Content Library object to create</param>
        /// <returns>
        ///     <see cref="ContentLibrary" />
        /// </returns>
        /// <exception cref="Exception">Exception with the appropriate message</exception>
        public ContentLibrary AddContentLibrary(ContentLibrary library)
        {
            const string resource = "/libraries/";
            const string contentType = "application/json";
            if (library == null) throw new HttpRequestException(new Exception("Parameter 'library' cannot be null"));
            var stringWriter = new StringWriter();
            new JsonSerializer().Serialize(stringWriter, library);

            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 ContentLibrary(JsonConvert.DeserializeObject<ApiDictionary>(response.GetBodyAsString()));
            string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString());
            throw new Exception("Request Failed : " + errorMessage);
        }