Skip to content

Commit

Permalink
Misc code improvements - primarily around posts
Browse files Browse the repository at this point in the history
  • Loading branch information
abjerner committed Feb 13, 2023
1 parent 2e2a050 commit c52e02f
Show file tree
Hide file tree
Showing 22 changed files with 436 additions and 624 deletions.
82 changes: 35 additions & 47 deletions src/Skybrud.Social.Facebook/Endpoints/FacebookPostsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Skybrud.Social.Facebook.Endpoints {
/// Class representing the implementation of the posts endpoint.
/// </summary>
/// <see>
/// <cref>https://developers.facebook.com/docs/graph-api/reference/v2.8/page/feed</cref>
/// <cref>https://developers.facebook.com/docs/graph-api/reference/v16.0/page/feed</cref>
/// </see>
public class FacebookPostsEndpoint {

Expand All @@ -36,63 +36,72 @@ internal FacebookPostsEndpoint(FacebookHttpService service) {

#endregion

#region Methods
#region Member methods

/// <summary>
/// Publishes a new post to the feed matching the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the call to the API.</param>
/// <returns>An instance of <see cref="FacebookPostResponse"/> representing the response.</returns>
public FacebookPostResponse CreatePost(FacebookCreatePostOptions options) {
return new FacebookPostResponse(Raw.CreatePost(options));
}

/// <summary>
/// Gets information about the post with the specified <paramref name="identifier"/>.
/// </summary>
/// <param name="identifier">The identifier (ID) of the post.</param>
/// <returns>An instance of <see cref="FacebookGetPostResponse"/> representing the response.</returns>
public FacebookGetPostResponse GetPost(string identifier) {
return FacebookGetPostResponse.ParseResponse(Raw.GetPost(identifier));
/// <returns>An instance of <see cref="FacebookPostResponse"/> representing the response.</returns>
public FacebookPostResponse GetPost(string identifier) {
return new FacebookPostResponse(Raw.GetPost(identifier));
}

/// <summary>
/// Gets information about the post with the specified <paramref name="identifier"/>.
/// </summary>
/// <param name="identifier">The identifier (ID) of the post.</param>
/// <param name="fields">A collection of the fields that should be returned by the API.</param>
/// <returns>An instance of <see cref="FacebookGetPostResponse"/> representing the response.</returns>
public FacebookGetPostResponse GetPost(string identifier, FacebookFieldList fields) {
return FacebookGetPostResponse.ParseResponse(Raw.GetPost(identifier, fields));
/// <returns>An instance of <see cref="FacebookPostResponse"/> representing the response.</returns>
public FacebookPostResponse GetPost(string identifier, FacebookFieldList fields) {
return new FacebookPostResponse(Raw.GetPost(identifier, fields));
}

/// <summary>
/// Gets information about the post matching the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the call to the API.</param>
/// <returns>An instance of <see cref="FacebookGetPostResponse"/> representing the response.</returns>
public FacebookGetPostResponse GetPost(FacebookGetPostOptions options) {
return FacebookGetPostResponse.ParseResponse(Raw.GetPost(options));
/// <returns>An instance of <see cref="FacebookPostResponse"/> representing the response.</returns>
public FacebookPostResponse GetPost(FacebookGetPostOptions options) {
return new FacebookPostResponse(Raw.GetPost(options));
}

/// <summary>
/// Gets a list of posts of the user or page with the specified <paramref name="identifier"/>.
/// </summary>
/// <param name="identifier">The identifier (ID or alias) of the user or page.</param>
/// <returns>An instance of <see cref="FacebookGetPostsResponse"/> representing the response.</returns>
public FacebookGetPostsResponse GetPosts(string identifier) {
return FacebookGetPostsResponse.ParseResponse(Raw.GetPosts(identifier));
/// <returns>An instance of <see cref="FacebookPostListResponse"/> representing the response.</returns>
public FacebookPostListResponse GetPosts(string identifier) {
return new FacebookPostListResponse(Raw.GetPosts(identifier));
}

/// <summary>
/// Gets a list of posts of the user or page with the specified <paramref name="identifier"/>.
/// </summary>
/// <param name="identifier">The identifier (ID or alias) of the user or page.</param>
/// <param name="fields">A collection of the fields that should be returned by the API.</param>
/// <returns>An instance of <see cref="FacebookGetPostsResponse"/> representing the response.</returns>
public FacebookGetPostsResponse GetPosts(string identifier, FacebookFieldList fields) {
return FacebookGetPostsResponse.ParseResponse(Raw.GetPosts(identifier, fields));
/// <returns>An instance of <see cref="FacebookPostListResponse"/> representing the response.</returns>
public FacebookPostListResponse GetPosts(string identifier, FacebookFieldList fields) {
return new FacebookPostListResponse(Raw.GetPosts(identifier, fields));
}

/// <summary>
/// Gets a list of posts of the user or page with the specified <paramref name="identifier"/>.
/// </summary>
/// <param name="identifier">The identifier (ID or alias) of the user or page.</param>
/// <param name="limit">The maximum amount of posts to be returned on each page.</param>
/// <returns>An instance of <see cref="FacebookGetPostsResponse"/> representing the response.</returns>
public FacebookGetPostsResponse GetPosts(string identifier, int limit) {
return FacebookGetPostsResponse.ParseResponse(Raw.GetPosts(identifier, limit));
/// <returns>An instance of <see cref="FacebookPostListResponse"/> representing the response.</returns>
public FacebookPostListResponse GetPosts(string identifier, int limit) {
return new FacebookPostListResponse(Raw.GetPosts(identifier, limit));
}

/// <summary>
Expand All @@ -101,39 +110,18 @@ public FacebookGetPostsResponse GetPosts(string identifier, int limit) {
/// <param name="identifier">The identifier (ID or alias) of the user or page.</param>
/// <param name="limit"></param>
/// <param name="fields">A collection of the fields that should be returned by the API.</param>
/// <returns>An instance of <see cref="FacebookGetPostsResponse"/> representing the response.</returns>
public FacebookGetPostsResponse GetPosts(string identifier, int limit, FacebookFieldList fields) {
return FacebookGetPostsResponse.ParseResponse(Raw.GetPosts(identifier, limit, fields));
}

/// <summary>
/// Gets a list of posts of the user or page with the specified <paramref name="identifier"/>.
/// </summary>
/// <param name="identifier">The identifier (ID or alias) of the user or page.</param>
/// <param name="limit">The maximum amount of posts to be returned on each page.</param>
/// <param name="until">A timestamp that points to the start of the range of time-based data.</param>
/// <param name="fields">A collection of the fields that should be returned by the API.</param>
/// <returns>An instance of <see cref="FacebookGetPostsResponse"/> representing the response.</returns>
public FacebookGetPostsResponse GetPosts(string identifier, int limit, EssentialsTime until, FacebookFieldList fields) {
return FacebookGetPostsResponse.ParseResponse(Raw.GetPosts(identifier, limit, until, fields));
/// <returns>An instance of <see cref="FacebookPostListResponse"/> representing the response.</returns>
public FacebookPostListResponse GetPosts(string identifier, int limit, FacebookFieldList fields) {
return new FacebookPostListResponse(Raw.GetPosts(identifier, limit, fields));
}

/// <summary>
/// Gets a list of posts of the user or page matching the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the call to the API.</param>
/// <returns>An instance of <see cref="FacebookGetPostsResponse"/> representing the response.</returns>
public FacebookGetPostsResponse GetPosts(FacebookGetPostsOptions options) {
return FacebookGetPostsResponse.ParseResponse(Raw.GetPosts(options));
}

/// <summary>
/// Publishes a new post to the feed matching the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the call to the API.</param>
/// <returns>An instance of <see cref="FacebookCreatePostResponse"/> representing the response.</returns>
public FacebookCreatePostResponse CreatePost(FacebookCreatePostOptions options) {
return FacebookCreatePostResponse.ParseResponse(Raw.CreatePost(options));
/// <returns>An instance of <see cref="FacebookPostListResponse"/> representing the response.</returns>
public FacebookPostListResponse GetPosts(FacebookGetPostsOptions options) {
return new FacebookPostListResponse(Raw.GetPosts(options));
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Skybrud.Social.Facebook.Endpoints.Raw {
/// Class representing the raw implementation of the posts endpoint.
/// </summary>
/// <see>
/// <cref>https://developers.facebook.com/docs/graph-api/reference/v2.8/page/feed</cref>
/// <cref>https://developers.facebook.com/docs/graph-api/reference/v16.0/page/feed</cref>
/// </see>
public class FacebookPostsRawEndpoint {

Expand All @@ -35,6 +35,17 @@ internal FacebookPostsRawEndpoint(FacebookOAuthClient client) {

#region Methods

/// <summary>
/// Publishes a new post to the feed matching the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the call to the API.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
public IHttpResponse CreatePost(FacebookCreatePostOptions options) {
if (options == null) throw new ArgumentNullException(nameof(options));
if (string.IsNullOrWhiteSpace(options.Identifier)) throw new PropertyNotSetException(nameof(options.Identifier), "A Facebook identifier (ID or alias) must be specified.");
return Client.GetResponse(options);
}

/// <summary>
/// Gets information about the post with the specified <paramref name="identifier"/>.
/// </summary>
Expand All @@ -51,7 +62,7 @@ public IHttpResponse GetPost(string identifier) {
/// <param name="identifier">The identifier (ID) of the post.</param>
/// <param name="fields">A collection of the fields that should be returned by the API.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
public IHttpResponse GetPost(string identifier, FacebookFieldList fields) {
public IHttpResponse GetPost(string identifier, FacebookFieldList? fields) {
if (string.IsNullOrWhiteSpace(identifier)) throw new ArgumentNullException(nameof(identifier));
return GetPost(new FacebookGetPostOptions(identifier, fields));
}
Expand All @@ -64,7 +75,7 @@ public IHttpResponse GetPost(string identifier, FacebookFieldList fields) {
public IHttpResponse GetPost(FacebookGetPostOptions options) {
if (options == null) throw new ArgumentNullException(nameof(options));
if (string.IsNullOrWhiteSpace(options.Identifier)) throw new PropertyNotSetException(nameof(options.Identifier), "A Facebook identifier (ID) must be specified.");
return Client.DoHttpGetRequest("/" + options.Identifier, options);
return Client.GetResponse(options);
}

/// <summary>
Expand All @@ -83,7 +94,7 @@ public IHttpResponse GetPosts(string identifier) {
/// <param name="identifier">The identifier (ID or alias) of the user or page.</param>
/// <param name="fields">A collection of the fields that should be returned by the API.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
public IHttpResponse GetPosts(string identifier, FacebookFieldList fields) {
public IHttpResponse GetPosts(string identifier, FacebookFieldList? fields) {
if (string.IsNullOrWhiteSpace(identifier)) throw new ArgumentNullException(nameof(identifier), "A Facebook identifier (ID or alias) must be specified.");
return GetPosts(new FacebookGetPostsOptions(identifier, fields));
}
Expand All @@ -94,7 +105,7 @@ public IHttpResponse GetPosts(string identifier, FacebookFieldList fields) {
/// <param name="identifier">The identifier (ID or alias) of the user or page.</param>
/// <param name="limit">The maximum amount of posts to be returned on each page.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
public IHttpResponse GetPosts(string identifier, int limit) {
public IHttpResponse GetPosts(string identifier, int? limit) {
if (string.IsNullOrWhiteSpace(identifier)) throw new ArgumentNullException(nameof(identifier), "A Facebook identifier (ID or alias) must be specified.");
return GetPosts(new FacebookGetPostsOptions(identifier, limit));
}
Expand All @@ -106,24 +117,11 @@ public IHttpResponse GetPosts(string identifier, int limit) {
/// <param name="limit"></param>
/// <param name="fields">A collection of the fields that should be returned by the API.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
public IHttpResponse GetPosts(string identifier, int limit, FacebookFieldList fields) {
public IHttpResponse GetPosts(string identifier, int? limit, FacebookFieldList? fields) {
if (string.IsNullOrWhiteSpace(identifier)) throw new ArgumentNullException(nameof(identifier), "A Facebook identifier (ID or alias) must be specified.");
return GetPosts(new FacebookGetPostsOptions(identifier, limit, fields));
}

/// <summary>
/// Gets a list of posts of the user or page with the specified <paramref name="identifier"/>.
/// </summary>
/// <param name="identifier">The identifier (ID or alias) of the user or page.</param>
/// <param name="limit">The maximum amount of posts to be returned on each page.</param>
/// <param name="until">A timestamp that points to the start of the range of time-based data.</param>
/// <param name="fields">A collection of the fields that should be returned by the API.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
public IHttpResponse GetPosts(string identifier, int limit, EssentialsTime until, FacebookFieldList fields) {
if (string.IsNullOrWhiteSpace(identifier)) throw new ArgumentNullException(nameof(identifier), "A Facebook identifier (ID or alias) must be specified.");
return GetPosts(new FacebookGetPostsOptions(identifier, limit, until, fields));
}

/// <summary>
/// Gets a list of posts of the user or page matching the specified <paramref name="options"/>.
/// </summary>
Expand All @@ -132,18 +130,7 @@ public IHttpResponse GetPosts(string identifier, int limit, EssentialsTime until
public IHttpResponse GetPosts(FacebookGetPostsOptions options) {
if (options == null) throw new ArgumentNullException(nameof(options));
if (string.IsNullOrWhiteSpace(options.Identifier)) throw new PropertyNotSetException(nameof(options.Identifier), "A Facebook identifier (ID or alias) must be specified.");
return Client.DoHttpGetRequest("/" + options.Identifier + "/posts", options);
}

/// <summary>
/// Publishes a new post to the feed matching the specified <paramref name="options"/>.
/// </summary>
/// <param name="options">The options for the call to the API.</param>
/// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
public IHttpResponse CreatePost(FacebookCreatePostOptions options) {
if (options == null) throw new ArgumentNullException(nameof(options));
if (string.IsNullOrWhiteSpace(options.Identifier)) throw new PropertyNotSetException(nameof(options.Identifier), "A Facebook identifier (ID or alias) must be specified.");
return Client.DoHttpPostRequest("/" + options.Identifier + "/feed", options);
return Client.GetResponse(options);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion src/Skybrud.Social.Facebook/Models/Common/IFacebookList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IFacebookList<out T> {
/// <summary>
/// Gets an array of the <typeparamref name="T"/> returned in the response.
/// </summary>
public abstract IReadOnlyCollection<T> Data { get; }
public abstract IReadOnlyList<T> Data { get; }

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class FacebookPageList : FacebookObject, IFacebookList<FacebookPage> {
/// <summary>
/// Gets an array of the <see cref="FacebookPage"/> returned in the response.
/// </summary>
public IReadOnlyCollection<FacebookPage> Data { get; }
public IReadOnlyList<FacebookPage> Data { get; }

/// <summary>
/// Gets pagination information about the response.
Expand Down

This file was deleted.

Loading

0 comments on commit c52e02f

Please sign in to comment.