/// <summary> /// Add a content media /// </summary> /// <param name="mediaInfo">The content media data <see cref="MediaInfo" /></param> /// <returns> /// <see cref="ContentMedia" /> /// </returns> /// <exception cref="Exception">Exception with the appropriate message</exception> public ContentMedia AddContentMedia(MediaInfo mediaInfo) { const string resource = "/media/"; if (mediaInfo == null) throw new Exception("Parameter 'mediaRequest' cannot be null."); ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("ContentName", mediaInfo.ContentName) .Set("LibraryId", mediaInfo.LibraryId.ToString()) .Set("DestinationFolder", mediaInfo.DestinationFolder ?? string.Empty) .Set("Preference", mediaInfo.Preference) .Set("ContentText", mediaInfo.ContentText ?? string.Empty) .Set("DisplayText", mediaInfo.DisplayText ?? string.Empty) .Set("Tags", mediaInfo.Tags != null && mediaInfo.Tags.Count > 0 ? JsonConvert.SerializeObject(mediaInfo.Tags) : string.Empty); HttpResponse response = RestClient.Post(resource, parameterMap); if (response == null) throw new Exception("Request Failed. Unable to get server response"); if (response.Status == Convert.ToInt32(HttpStatusCode.Created)) return new ContentMedia(JsonConvert.DeserializeObject<ApiDictionary>(response.GetBodyAsString())); string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
/// <summary> /// Updates an existing content media and returns the updated content media /// </summary> /// <param name="contentMediaId">The Content Media ID</param> /// <param name="mediaInfo">Content Media Info <see cref="MediaInfo" /></param> /// <returns> /// <see cref="ContentMedia" /> /// </returns> /// <exception cref="Exception">Exception with the appropriate message.</exception> public ContentMedia UpdateContentMedia(string contentMediaId, MediaInfo mediaInfo) { string resource = "/media/"; if (!contentMediaId.IsGuid()) throw new HttpRequestException(new Exception("contentMediaId must not be null and be a valid UUID")); resource += contentMediaId.Replace("-", ""); ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("ContentName", mediaInfo.ContentName) .Set("LibraryId", mediaInfo.LibraryId.ToString()) .Set("DestinationFolder", mediaInfo.DestinationFolder ?? string.Empty) .Set("Preference", mediaInfo.Preference) .Set("ContentText", mediaInfo.ContentText ?? string.Empty) .Set("DisplayText", mediaInfo.DisplayText ?? string.Empty) .Set("DrmProtect", mediaInfo.DrmProtect ? "true" : "false") .Set("Tags", mediaInfo.Tags != null && mediaInfo.Tags.Count > 0 ? JsonConvert.SerializeObject(mediaInfo.Tags) : string.Empty); HttpResponse response = RestClient.Put(resource, parameterMap); if (response == null) throw new Exception("Request Failed. Unable to get server response"); if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) return new ContentMedia(JsonConvert.DeserializeObject<ApiDictionary>(response.GetBodyAsString())); string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
/// <summary> /// Upload a new content media file with content media metadata /// </summary> /// <param name="filePath">Content Media file</param> /// <param name="mediaInfo">Content Media Info</param> /// <returns> /// <see cref="ContentMedia" /> /// </returns> /// <exception cref="Exception">Exception with the appropriate message.</exception> public ContentMedia AddContentMedia(string filePath, MediaInfo mediaInfo) { const string resource = "/media/"; if (mediaInfo == null) throw new Exception("Parameter 'mediaInfo' cannot be null."); ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("ContentName", mediaInfo.ContentName) .Set("LibraryId", mediaInfo.LibraryId.ToString()) .Set("DestinationFolder", mediaInfo.DestinationFolder ?? string.Empty) .Set("Preference", mediaInfo.Preference) .Set("Width", Convert.ToString(mediaInfo.Width)) .Set("Height", Convert.ToString(mediaInfo.Height)) .Set("DrmProtect", mediaInfo.DrmProtect ? "true" : "false") .Set("Streamable", mediaInfo.Streamable ? "true" : "false") .Set("DisplayText", mediaInfo.DisplayText ?? string.Empty) .Set("ContentText", mediaInfo.ContentText ?? string.Empty) .Set("Tags", mediaInfo.Tags != null && mediaInfo.Tags.Count > 0 ? JsonConvert.SerializeObject(mediaInfo.Tags) : string.Empty); // Let us build the upload file var mediaFile = new UploadFile(filePath, "MediaFile", FileExtensionMimeTypeMapping.GetMimeType(Path.GetExtension(filePath))); UploadFile[] files = {mediaFile}; HttpResponse response = RestClient.PostFiles(resource, files, parameterMap); if (response == null) throw new Exception("Request Failed. Unable to get server response"); if (response.Status == Convert.ToInt32(HttpStatusCode.Created)) return new ContentMedia(JsonConvert.DeserializeObject<ApiDictionary>(response.GetBodyAsString())); string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }