Skip to content

Commit

Permalink
Facebook: Added more logic for the videos endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
abjerner committed Nov 2, 2016
1 parent 52acbec commit e6d6351
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 1 deletion.
58 changes: 58 additions & 0 deletions src/Skybrud.Social/Facebook/Endpoints/FacebookVideosEndpoint.cs
Original file line number Diff line number Diff line change
@@ -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 {

/// <summary>
/// Class representing the implementation of the videos endpoint.
/// </summary>
public class FacebookVideosEndpoint {

#region Properties

/// <summary>
/// Gets a reference to the Facebook service.
/// </summary>
public FacebookService Service { get; private set; }

/// <summary>
/// Gets a reference to the raw endpoint.
/// </summary>
public FacebookVideosRawEndpoint Raw {
get { return Service.Client.Videos; }
}

#endregion

#region Constructors

internal FacebookVideosEndpoint(FacebookService service) {
Service = service;
}

#endregion

#region Methods

/// <summary>
/// Gets information about the video with the specified <code>id</code>.
/// </summary>
/// <param name="id">The ID of the video.</param>
public FacebookVideoResponse GetVideo(string id) {
return FacebookVideoResponse.ParseResponse(Raw.GetVideo(id));
}

/// <summary>
/// Gets information about the video matching the specified <code>options</code>.
/// </summary>
/// <param name="options">The options for the call to the API.</param>
public FacebookVideoResponse GetVideo(FacebookGetVideoOptions options) {
return FacebookVideoResponse.ParseResponse(Raw.GetVideo(options));
}

#endregion

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public SocialHttpResponse GetVideo(string videoId) {
/// Gets information about the video matching the specified <code>options</code>.
/// </summary>
/// <param name="options">The options for the call to the API.</param>
public SocialHttpResponse GetPost(FacebookGetVideoOptions options) {
public SocialHttpResponse GetVideo(FacebookGetVideoOptions options) {
if (options == null) throw new ArgumentNullException("options");
return Client.DoAuthenticatedGetRequest("/" + options.Identifier, options);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Skybrud.Social/Facebook/FacebookService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public class FacebookService {
/// </summary>
public FacebookUsersEndpoint Users { get; private set; }

/// <summary>
/// Gets a reference to the videos endpoint.
/// </summary>
public FacebookVideosEndpoint Videos { get; private set; }

#endregion

#region Constructor(s)
Expand All @@ -99,6 +104,7 @@ private FacebookService() {
Photos = new FacebookPhotosEndpoint(this);
Posts = new FacebookPostsEndpoint(this);
Users = new FacebookUsersEndpoint(this);
Videos = new FacebookVideosEndpoint(this);
}

#endregion
Expand Down
6 changes: 6 additions & 0 deletions src/Skybrud.Social/Facebook/OAuth/FacebookOAuthClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public class FacebookOAuthClient {
/// </summary>
public FacebookUsersRawEndpoint Users { get; private set; }

/// <summary>
/// Gets a reference to the videos endpoint.
/// </summary>
public FacebookVideosRawEndpoint Videos { get; private set; }

#endregion

#endregion
Expand All @@ -142,6 +147,7 @@ public FacebookOAuthClient() {
Posts = new FacebookPostsRawEndpoint(this);
Users = new FacebookUsersRawEndpoint(this);
Albums = new FacebookAlbumsRawEndpoint(this);
Videos = new FacebookVideosRawEndpoint(this);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<FacebookVideo> {

#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

}

}
2 changes: 2 additions & 0 deletions src/Skybrud.Social/Skybrud.Social.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Compile Include="BitBucket\Responses\User\BitBucketCurrentUserRepositoriesResponse.cs" />
<Compile Include="BitBucket\Responses\BitBucketResponse.cs" />
<Compile Include="BitBucket\Responses\Users\BitBucketUserResponseBody.cs" />
<Compile Include="Facebook\Endpoints\FacebookVideosEndpoint.cs" />
<Compile Include="Facebook\Endpoints\Raw\FacebookVideosRawEndpoint.cs" />
<Compile Include="Facebook\Fields\FacebookField.cs" />
<Compile Include="Facebook\Fields\FacebookFieldsCollection.cs" />
Expand Down Expand Up @@ -193,6 +194,7 @@
<Compile Include="Facebook\Responses\Photos\FacebookPhotoResponse.cs" />
<Compile Include="Facebook\Responses\Photos\FacebookPhotosResponse.cs" />
<Compile Include="Facebook\Responses\Photos\FacebookPostPhotoResponse.cs" />
<Compile Include="Facebook\Responses\Videos\FacebookVideoResponse.cs" />
<Compile Include="Facebook\Responses\Posts\FacebookPostResponse.cs" />
<Compile Include="Facebook\Responses\Posts\FacebookPostsResponse.cs" />
<Compile Include="Facebook\Responses\Users\FacebookUserResponse.cs" />
Expand Down

0 comments on commit e6d6351

Please sign in to comment.