From e6d6351d753476904c6505d418733afebab90d63 Mon Sep 17 00:00:00 2001 From: Anders Bjerner Date: Wed, 2 Nov 2016 09:16:38 +0100 Subject: [PATCH] Facebook: Added more logic for the videos endpoint --- .../Endpoints/FacebookVideosEndpoint.cs | 58 +++++++++++++++++++ .../Raw/FacebookVideosRawEndpoint.cs | 2 +- .../Facebook/FacebookService.cs | 6 ++ .../Facebook/OAuth/FacebookOAuthClient.cs | 6 ++ .../Responses/Videos/FacebookVideoResponse.cs | 39 +++++++++++++ src/Skybrud.Social/Skybrud.Social.csproj | 2 + 6 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/Skybrud.Social/Facebook/Endpoints/FacebookVideosEndpoint.cs create mode 100644 src/Skybrud.Social/Facebook/Responses/Videos/FacebookVideoResponse.cs diff --git a/src/Skybrud.Social/Facebook/Endpoints/FacebookVideosEndpoint.cs b/src/Skybrud.Social/Facebook/Endpoints/FacebookVideosEndpoint.cs new file mode 100644 index 0000000..f268ba8 --- /dev/null +++ b/src/Skybrud.Social/Facebook/Endpoints/FacebookVideosEndpoint.cs @@ -0,0 +1,58 @@ +using Skybrud.Social.Facebook.Endpoints.Raw; +using Skybrud.Social.Facebook.Options.Videos; +using Skybrud.Social.Facebook.Responses.Videos; + +namespace Skybrud.Social.Facebook.Endpoints { + + /// + /// Class representing the implementation of the videos endpoint. + /// + public class FacebookVideosEndpoint { + + #region Properties + + /// + /// Gets a reference to the Facebook service. + /// + public FacebookService Service { get; private set; } + + /// + /// Gets a reference to the raw endpoint. + /// + public FacebookVideosRawEndpoint Raw { + get { return Service.Client.Videos; } + } + + #endregion + + #region Constructors + + internal FacebookVideosEndpoint(FacebookService service) { + Service = service; + } + + #endregion + + #region Methods + + /// + /// Gets information about the video with the specified id. + /// + /// The ID of the video. + public FacebookVideoResponse GetVideo(string id) { + return FacebookVideoResponse.ParseResponse(Raw.GetVideo(id)); + } + + /// + /// Gets information about the video matching the specified options. + /// + /// The options for the call to the API. + public FacebookVideoResponse GetVideo(FacebookGetVideoOptions options) { + return FacebookVideoResponse.ParseResponse(Raw.GetVideo(options)); + } + + #endregion + + } + +} \ No newline at end of file diff --git a/src/Skybrud.Social/Facebook/Endpoints/Raw/FacebookVideosRawEndpoint.cs b/src/Skybrud.Social/Facebook/Endpoints/Raw/FacebookVideosRawEndpoint.cs index d90cc78..322c826 100644 --- a/src/Skybrud.Social/Facebook/Endpoints/Raw/FacebookVideosRawEndpoint.cs +++ b/src/Skybrud.Social/Facebook/Endpoints/Raw/FacebookVideosRawEndpoint.cs @@ -41,7 +41,7 @@ public SocialHttpResponse GetVideo(string videoId) { /// Gets information about the video matching the specified options. /// /// The options for the call to the API. - public SocialHttpResponse GetPost(FacebookGetVideoOptions options) { + public SocialHttpResponse GetVideo(FacebookGetVideoOptions options) { if (options == null) throw new ArgumentNullException("options"); return Client.DoAuthenticatedGetRequest("/" + options.Identifier, options); } diff --git a/src/Skybrud.Social/Facebook/FacebookService.cs b/src/Skybrud.Social/Facebook/FacebookService.cs index b3a11a0..41abfc9 100644 --- a/src/Skybrud.Social/Facebook/FacebookService.cs +++ b/src/Skybrud.Social/Facebook/FacebookService.cs @@ -81,6 +81,11 @@ public class FacebookService { /// public FacebookUsersEndpoint Users { get; private set; } + /// + /// Gets a reference to the videos endpoint. + /// + public FacebookVideosEndpoint Videos { get; private set; } + #endregion #region Constructor(s) @@ -99,6 +104,7 @@ private FacebookService() { Photos = new FacebookPhotosEndpoint(this); Posts = new FacebookPostsEndpoint(this); Users = new FacebookUsersEndpoint(this); + Videos = new FacebookVideosEndpoint(this); } #endregion diff --git a/src/Skybrud.Social/Facebook/OAuth/FacebookOAuthClient.cs b/src/Skybrud.Social/Facebook/OAuth/FacebookOAuthClient.cs index b000243..8d87cdc 100644 --- a/src/Skybrud.Social/Facebook/OAuth/FacebookOAuthClient.cs +++ b/src/Skybrud.Social/Facebook/OAuth/FacebookOAuthClient.cs @@ -118,6 +118,11 @@ public class FacebookOAuthClient { /// public FacebookUsersRawEndpoint Users { get; private set; } + /// + /// Gets a reference to the videos endpoint. + /// + public FacebookVideosRawEndpoint Videos { get; private set; } + #endregion #endregion @@ -142,6 +147,7 @@ public FacebookOAuthClient() { Posts = new FacebookPostsRawEndpoint(this); Users = new FacebookUsersRawEndpoint(this); Albums = new FacebookAlbumsRawEndpoint(this); + Videos = new FacebookVideosRawEndpoint(this); } /// diff --git a/src/Skybrud.Social/Facebook/Responses/Videos/FacebookVideoResponse.cs b/src/Skybrud.Social/Facebook/Responses/Videos/FacebookVideoResponse.cs new file mode 100644 index 0000000..b1f169d --- /dev/null +++ b/src/Skybrud.Social/Facebook/Responses/Videos/FacebookVideoResponse.cs @@ -0,0 +1,39 @@ +using Skybrud.Social.Facebook.Objects.Videos; +using Skybrud.Social.Http; +using Skybrud.Social.Json; + +namespace Skybrud.Social.Facebook.Responses.Videos { + + public class FacebookVideoResponse : FacebookResponse { + + #region Constructors + + private FacebookVideoResponse(SocialHttpResponse response) : base(response) { } + + #endregion + + #region Static methods + + public static FacebookVideoResponse ParseResponse(SocialHttpResponse response) { + + if (response == null) return null; + + // Parse the raw JSON response + JsonObject obj = response.GetBodyAsJsonObject(); + if (obj == null) return null; + + // Validate the response + ValidateResponse(response, obj); + + // Initialize the response object + return new FacebookVideoResponse(response) { + Body = FacebookVideo.Parse(obj) + }; + + } + + #endregion + + } + +} \ No newline at end of file diff --git a/src/Skybrud.Social/Skybrud.Social.csproj b/src/Skybrud.Social/Skybrud.Social.csproj index 8f9dbb7..417c76d 100644 --- a/src/Skybrud.Social/Skybrud.Social.csproj +++ b/src/Skybrud.Social/Skybrud.Social.csproj @@ -80,6 +80,7 @@ + @@ -193,6 +194,7 @@ +