diff --git a/Brightcove.Core/Brightcove.Core.csproj b/Brightcove.Core/Brightcove.Core.csproj index 508c665f..313b893d 100644 --- a/Brightcove.Core/Brightcove.Core.csproj +++ b/Brightcove.Core/Brightcove.Core.csproj @@ -55,6 +55,7 @@ + @@ -67,6 +68,8 @@ + + diff --git a/Brightcove.Core/Models/Folder.cs b/Brightcove.Core/Models/Folder.cs new file mode 100644 index 00000000..a5930093 --- /dev/null +++ b/Brightcove.Core/Models/Folder.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Brightcove.Core.Models +{ + public class Folder + { + [JsonProperty("account_id", NullValueHandling = NullValueHandling.Ignore)] + public string AccountId { get; set; } + + [JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)] + public string Id { get; set; } + + [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + public string Name { get; set; } + + [JsonProperty("video_count", NullValueHandling = NullValueHandling.Ignore)] + public int? VideoCount { get; set; } + + [JsonProperty("created_at", NullValueHandling = NullValueHandling.Ignore)] + public DateTime? CreationDate { get; set; } + + [JsonProperty("updated_at", NullValueHandling = NullValueHandling.Ignore)] + public DateTime? UpdatedDate { get; set; } + + [JsonIgnore()] + public DateTime LastSyncTime { get; set; } + + public Folder ShallowCopy() + { + return (Folder)this.MemberwiseClone(); + } + } +} diff --git a/Brightcove.Core/Models/Label.cs b/Brightcove.Core/Models/Label.cs new file mode 100644 index 00000000..83c2cd2b --- /dev/null +++ b/Brightcove.Core/Models/Label.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using System.Linq; + +namespace Brightcove.Core.Models +{ + public class Label + { + [JsonProperty("path", NullValueHandling = NullValueHandling.Ignore)] + public string Path { get; set; } + + [JsonProperty("new_label", NullValueHandling = NullValueHandling.Ignore)] + public string NewLabel { get; set; } + + [JsonIgnore()] + public string SitecoreName { get; set; } + + [JsonIgnore()] + public DateTime LastSyncTime { get; set; } + + public Label() + { + + } + + public Label(string path) + { + Path = AddTrailingSlash(path); + SitecoreName = Path.Replace("/", "_"); + } + + public Label ShallowCopy() + { + return (Label)this.MemberwiseClone(); + } + + public static bool TryParse(string path, out Label label) + { + if(path.Length <= 1) + { + label = null; + return false; + } + + if (path[0] != '/') + { + label = null; + return false; + } + + label = new Label(path); + return true; + } + + public string GetLeafLabel() + { + return Path.Split('/').Last(); + } + + private string AddTrailingSlash(string path) + { + if (path[path.Length - 1] != '/') + { + return path + '/'; + } + + return path; + } + } +} \ No newline at end of file diff --git a/Brightcove.Core/Models/Labels.cs b/Brightcove.Core/Models/Labels.cs new file mode 100644 index 00000000..7d11c8b2 --- /dev/null +++ b/Brightcove.Core/Models/Labels.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Brightcove.Core.Models +{ + public class Labels + { + [JsonProperty("account_id", NullValueHandling = NullValueHandling.Ignore)] + public string AccountId { get; set; } + + [JsonProperty("labels", NullValueHandling = NullValueHandling.Ignore)] + public List Paths { get; set; } + + [JsonProperty("version", NullValueHandling = NullValueHandling.Ignore)] + public int Version { get; set; } + + public Labels ShallowCopy() + { + return (Labels)this.MemberwiseClone(); + } + } +} diff --git a/Brightcove.Core/Models/Video.cs b/Brightcove.Core/Models/Video.cs index 78afafb4..48c2450b 100644 --- a/Brightcove.Core/Models/Video.cs +++ b/Brightcove.Core/Models/Video.cs @@ -47,6 +47,12 @@ public class Video : Asset [JsonProperty("sharing", NullValueHandling = NullValueHandling.Ignore)] public VideoSharing Sharing { get; set; } + [JsonProperty("labels", NullValueHandling = NullValueHandling.Ignore)] + public List Labels { get; set; } + + [JsonProperty("folder_id", NullValueHandling = NullValueHandling.Ignore)] + public string Folder { get; set; } + [JsonIgnore] public string IngestJobId { get; set; } diff --git a/Brightcove.Core/Services/BrightcoveService.cs b/Brightcove.Core/Services/BrightcoveService.cs index ea180e91..0e6c008e 100644 --- a/Brightcove.Core/Services/BrightcoveService.cs +++ b/Brightcove.Core/Services/BrightcoveService.cs @@ -1,16 +1,14 @@ -using Brightcove.Core.Models; +using Brightcove.Core.Exceptions; +using Brightcove.Core.Extensions; +using Brightcove.Core.Models; +using Brightcove.MediaFramework.Brightcove.Entities; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Net.Http; using System.Text; -using System.Threading.Tasks; -using Brightcove.Core.Extensions; -using System.Net.Http.Headers; -using Brightcove.Core.Exceptions; -using System.Net; -using Brightcove.MediaFramework.Brightcove.Entities; namespace Brightcove.Core.Services { @@ -82,6 +80,22 @@ public Video CreateVideo(string name) return video; } + public Folder CreateFolder(string name) + { + Folder folder = new Folder(); + folder.Name = name; + + HttpRequestMessage request = new HttpRequestMessage(); + request.Content = new StringContent(JsonConvert.SerializeObject(folder), Encoding.UTF8, "application/json"); + request.Method = HttpMethod.Post; + request.RequestUri = new Uri($"{cmsBaseUrl}/{accountId}/folders"); + + HttpResponseMessage response = SendRequest(request); + folder = JsonConvert.DeserializeObject(response.Content.ReadAsString()); + + return folder; + } + public PlayList CreatePlaylist(string name) { PlayList playlist = new PlayList(); @@ -99,6 +113,75 @@ public PlayList CreatePlaylist(string name) return playlist; } + public Label CreateLabel(string path) + { + Label label = new Label(); + label.Path = path; + + HttpRequestMessage request = new HttpRequestMessage(); + request.Content = new StringContent(JsonConvert.SerializeObject(label), Encoding.UTF8, "application/json"); + request.Method = HttpMethod.Post; + request.RequestUri = new Uri($"{cmsBaseUrl}/{accountId}/labels"); + + HttpResponseMessage response = SendRequest(request); + label = new Label(JsonConvert.DeserializeObject