diff --git a/src/Skybrud.Social.Facebook/Endpoints/FacebookPostsEndpoint.cs b/src/Skybrud.Social.Facebook/Endpoints/FacebookPostsEndpoint.cs index 53d7d3d..066e956 100644 --- a/src/Skybrud.Social.Facebook/Endpoints/FacebookPostsEndpoint.cs +++ b/src/Skybrud.Social.Facebook/Endpoints/FacebookPostsEndpoint.cs @@ -10,7 +10,7 @@ namespace Skybrud.Social.Facebook.Endpoints { /// Class representing the implementation of the posts endpoint. /// /// - /// https://developers.facebook.com/docs/graph-api/reference/v2.8/page/feed + /// https://developers.facebook.com/docs/graph-api/reference/v16.0/page/feed /// public class FacebookPostsEndpoint { @@ -36,15 +36,24 @@ internal FacebookPostsEndpoint(FacebookHttpService service) { #endregion - #region Methods + #region Member methods + + /// + /// Publishes a new post to the feed matching the specified . + /// + /// The options for the call to the API. + /// An instance of representing the response. + public FacebookPostResponse CreatePost(FacebookCreatePostOptions options) { + return new FacebookPostResponse(Raw.CreatePost(options)); + } /// /// Gets information about the post with the specified . /// /// The identifier (ID) of the post. - /// An instance of representing the response. - public FacebookGetPostResponse GetPost(string identifier) { - return FacebookGetPostResponse.ParseResponse(Raw.GetPost(identifier)); + /// An instance of representing the response. + public FacebookPostResponse GetPost(string identifier) { + return new FacebookPostResponse(Raw.GetPost(identifier)); } /// @@ -52,27 +61,27 @@ public FacebookGetPostResponse GetPost(string identifier) { /// /// The identifier (ID) of the post. /// A collection of the fields that should be returned by the API. - /// An instance of representing the response. - public FacebookGetPostResponse GetPost(string identifier, FacebookFieldList fields) { - return FacebookGetPostResponse.ParseResponse(Raw.GetPost(identifier, fields)); + /// An instance of representing the response. + public FacebookPostResponse GetPost(string identifier, FacebookFieldList fields) { + return new FacebookPostResponse(Raw.GetPost(identifier, fields)); } /// /// Gets information about the post matching the specified . /// /// The options for the call to the API. - /// An instance of representing the response. - public FacebookGetPostResponse GetPost(FacebookGetPostOptions options) { - return FacebookGetPostResponse.ParseResponse(Raw.GetPost(options)); + /// An instance of representing the response. + public FacebookPostResponse GetPost(FacebookGetPostOptions options) { + return new FacebookPostResponse(Raw.GetPost(options)); } /// /// Gets a list of posts of the user or page with the specified . /// /// The identifier (ID or alias) of the user or page. - /// An instance of representing the response. - public FacebookGetPostsResponse GetPosts(string identifier) { - return FacebookGetPostsResponse.ParseResponse(Raw.GetPosts(identifier)); + /// An instance of representing the response. + public FacebookPostListResponse GetPosts(string identifier) { + return new FacebookPostListResponse(Raw.GetPosts(identifier)); } /// @@ -80,9 +89,9 @@ public FacebookGetPostsResponse GetPosts(string identifier) { /// /// The identifier (ID or alias) of the user or page. /// A collection of the fields that should be returned by the API. - /// An instance of representing the response. - public FacebookGetPostsResponse GetPosts(string identifier, FacebookFieldList fields) { - return FacebookGetPostsResponse.ParseResponse(Raw.GetPosts(identifier, fields)); + /// An instance of representing the response. + public FacebookPostListResponse GetPosts(string identifier, FacebookFieldList fields) { + return new FacebookPostListResponse(Raw.GetPosts(identifier, fields)); } /// @@ -90,9 +99,9 @@ public FacebookGetPostsResponse GetPosts(string identifier, FacebookFieldList fi /// /// The identifier (ID or alias) of the user or page. /// The maximum amount of posts to be returned on each page. - /// An instance of representing the response. - public FacebookGetPostsResponse GetPosts(string identifier, int limit) { - return FacebookGetPostsResponse.ParseResponse(Raw.GetPosts(identifier, limit)); + /// An instance of representing the response. + public FacebookPostListResponse GetPosts(string identifier, int limit) { + return new FacebookPostListResponse(Raw.GetPosts(identifier, limit)); } /// @@ -101,39 +110,18 @@ public FacebookGetPostsResponse GetPosts(string identifier, int limit) { /// The identifier (ID or alias) of the user or page. /// /// A collection of the fields that should be returned by the API. - /// An instance of representing the response. - public FacebookGetPostsResponse GetPosts(string identifier, int limit, FacebookFieldList fields) { - return FacebookGetPostsResponse.ParseResponse(Raw.GetPosts(identifier, limit, fields)); - } - - /// - /// Gets a list of posts of the user or page with the specified . - /// - /// The identifier (ID or alias) of the user or page. - /// The maximum amount of posts to be returned on each page. - /// A timestamp that points to the start of the range of time-based data. - /// A collection of the fields that should be returned by the API. - /// An instance of representing the response. - public FacebookGetPostsResponse GetPosts(string identifier, int limit, EssentialsTime until, FacebookFieldList fields) { - return FacebookGetPostsResponse.ParseResponse(Raw.GetPosts(identifier, limit, until, fields)); + /// An instance of representing the response. + public FacebookPostListResponse GetPosts(string identifier, int limit, FacebookFieldList fields) { + return new FacebookPostListResponse(Raw.GetPosts(identifier, limit, fields)); } /// /// Gets a list of posts of the user or page matching the specified . /// /// The options for the call to the API. - /// An instance of representing the response. - public FacebookGetPostsResponse GetPosts(FacebookGetPostsOptions options) { - return FacebookGetPostsResponse.ParseResponse(Raw.GetPosts(options)); - } - - /// - /// Publishes a new post to the feed matching the specified . - /// - /// The options for the call to the API. - /// An instance of representing the response. - public FacebookCreatePostResponse CreatePost(FacebookCreatePostOptions options) { - return FacebookCreatePostResponse.ParseResponse(Raw.CreatePost(options)); + /// An instance of representing the response. + public FacebookPostListResponse GetPosts(FacebookGetPostsOptions options) { + return new FacebookPostListResponse(Raw.GetPosts(options)); } #endregion diff --git a/src/Skybrud.Social.Facebook/Endpoints/Raw/FacebookPostsRawEndpoint.cs b/src/Skybrud.Social.Facebook/Endpoints/Raw/FacebookPostsRawEndpoint.cs index bbb5892..69b43fd 100644 --- a/src/Skybrud.Social.Facebook/Endpoints/Raw/FacebookPostsRawEndpoint.cs +++ b/src/Skybrud.Social.Facebook/Endpoints/Raw/FacebookPostsRawEndpoint.cs @@ -12,7 +12,7 @@ namespace Skybrud.Social.Facebook.Endpoints.Raw { /// Class representing the raw implementation of the posts endpoint. /// /// - /// https://developers.facebook.com/docs/graph-api/reference/v2.8/page/feed + /// https://developers.facebook.com/docs/graph-api/reference/v16.0/page/feed /// public class FacebookPostsRawEndpoint { @@ -35,6 +35,17 @@ internal FacebookPostsRawEndpoint(FacebookOAuthClient client) { #region Methods + /// + /// Publishes a new post to the feed matching the specified . + /// + /// The options for the call to the API. + /// An instance of representing the raw response. + 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); + } + /// /// Gets information about the post with the specified . /// @@ -51,7 +62,7 @@ public IHttpResponse GetPost(string identifier) { /// The identifier (ID) of the post. /// A collection of the fields that should be returned by the API. /// An instance of representing the raw response. - 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)); } @@ -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); } /// @@ -83,7 +94,7 @@ public IHttpResponse GetPosts(string identifier) { /// The identifier (ID or alias) of the user or page. /// A collection of the fields that should be returned by the API. /// An instance of representing the raw response. - 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)); } @@ -94,7 +105,7 @@ public IHttpResponse GetPosts(string identifier, FacebookFieldList fields) { /// The identifier (ID or alias) of the user or page. /// The maximum amount of posts to be returned on each page. /// An instance of representing the raw response. - 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)); } @@ -106,24 +117,11 @@ public IHttpResponse GetPosts(string identifier, int limit) { /// /// A collection of the fields that should be returned by the API. /// An instance of representing the raw response. - 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)); } - /// - /// Gets a list of posts of the user or page with the specified . - /// - /// The identifier (ID or alias) of the user or page. - /// The maximum amount of posts to be returned on each page. - /// A timestamp that points to the start of the range of time-based data. - /// A collection of the fields that should be returned by the API. - /// An instance of representing the raw response. - 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)); - } - /// /// Gets a list of posts of the user or page matching the specified . /// @@ -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); - } - - /// - /// Publishes a new post to the feed matching the specified . - /// - /// The options for the call to the API. - /// An instance of representing the raw response. - 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 diff --git a/src/Skybrud.Social.Facebook/Models/Common/IFacebookList.cs b/src/Skybrud.Social.Facebook/Models/Common/IFacebookList.cs index 3d1ef95..11c50c0 100644 --- a/src/Skybrud.Social.Facebook/Models/Common/IFacebookList.cs +++ b/src/Skybrud.Social.Facebook/Models/Common/IFacebookList.cs @@ -11,7 +11,7 @@ public interface IFacebookList { /// /// Gets an array of the returned in the response. /// - public abstract IReadOnlyCollection Data { get; } + public abstract IReadOnlyList Data { get; } } diff --git a/src/Skybrud.Social.Facebook/Models/Pages/FacebookPageList.cs b/src/Skybrud.Social.Facebook/Models/Pages/FacebookPageList.cs index f66b933..c97ab98 100644 --- a/src/Skybrud.Social.Facebook/Models/Pages/FacebookPageList.cs +++ b/src/Skybrud.Social.Facebook/Models/Pages/FacebookPageList.cs @@ -20,7 +20,7 @@ public class FacebookPageList : FacebookObject, IFacebookList { /// /// Gets an array of the returned in the response. /// - public IReadOnlyCollection Data { get; } + public IReadOnlyList Data { get; } /// /// Gets pagination information about the response. diff --git a/src/Skybrud.Social.Facebook/Models/Posts/FacebookCreatePostSummary.cs b/src/Skybrud.Social.Facebook/Models/Posts/FacebookCreatePostSummary.cs deleted file mode 100644 index 0914cfc..0000000 --- a/src/Skybrud.Social.Facebook/Models/Posts/FacebookCreatePostSummary.cs +++ /dev/null @@ -1,47 +0,0 @@ -using Newtonsoft.Json.Linq; -using Skybrud.Essentials.Json.Newtonsoft.Extensions; - -namespace Skybrud.Social.Facebook.Models.Posts { - - /// - /// Class representing a summary about a created post. - /// - public class FacebookCreatePostSummary : FacebookObject { - - #region Properties - - /// - /// Gets the ID of the post. - /// - public string Id { get; } - - #endregion - - #region Constructors - - /// - /// Initializes a new instance based on the specified . - /// - /// The instance of representing the event. - private FacebookCreatePostSummary(JObject obj) : base(obj) { - Id = obj.GetString("id"); - } - - #endregion - - #region Static methods - - /// - /// Parses the specified into an instance of . - /// - /// The instance of to be parsed. - /// An instance of . - public static FacebookCreatePostSummary Parse(JObject obj) { - return obj == null ? null : new FacebookCreatePostSummary(obj); - } - - #endregion - - } - -} \ No newline at end of file diff --git a/src/Skybrud.Social.Facebook/Models/Posts/FacebookPost.cs b/src/Skybrud.Social.Facebook/Models/Posts/FacebookPost.cs index 1f74327..326efea 100644 --- a/src/Skybrud.Social.Facebook/Models/Posts/FacebookPost.cs +++ b/src/Skybrud.Social.Facebook/Models/Posts/FacebookPost.cs @@ -1,6 +1,9 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json.Linq; using Skybrud.Essentials.Json.Newtonsoft.Extensions; using Skybrud.Essentials.Time; +using Skybrud.Social.Facebook.Extensions; using Skybrud.Social.Facebook.Fields; using Skybrud.Social.Facebook.Models.Applications; using Skybrud.Social.Facebook.Models.Comments; @@ -29,305 +32,160 @@ public class FacebookPost : FacebookObject { /// /// Gets information about the app or business that created the post. Applies to pages only. /// - public FacebookEntity AdminCreator { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasAdminCreator => AdminCreator != null; + public FacebookEntity? AdminCreator { get; } /// /// Gets information about the app the post was published by. /// - public FacebookApplication Application { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasApplication => Application != null; + public FacebookApplication? Application { get; } /// /// Gets a collection of the attachments of the post. Not all posts have attachments. /// - public FacebookPostAttachments Attachments { get; } - - /// - /// Gets whether the response for the post included any attachments. - /// - public bool HasAttachments => Attachments != null && Attachments.Count > 0; + public FacebookPostAttachments? Attachments { get; } // TODO: Add support for the "call_to_action" property /// /// Gets the link caption in post that appears below name. /// - public string Caption { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasCaption => string.IsNullOrWhiteSpace(Caption) == false; + public string? Caption { get; } /// /// Gets the time the post was initially published. For a post about a life event, this will be the date and /// time of the life event. /// - public EssentialsTime CreatedTime { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasCreatedTime => CreatedTime != null; + public EssentialsTime? CreatedTime { get; } /// /// Gets a description of a link in the post (appears beneath the ). /// - public string Description { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasDescription => string.IsNullOrWhiteSpace(Description) == false; + public string? Description { get; } /// /// Gets information about the profile that posted the message. /// - public FacebookProfile From { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasFrom => From != null; + public FacebookProfile? From { get; } /// /// Gets the URL to a full-sized version of the photo published in the post or scraped from a link in the post. /// If the photo's largest dimension exceeds 720 pixels, it will be resized, with the largest dimension set to /// 720. /// - public string FullPicture { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasFullPicture => string.IsNullOrWhiteSpace(FullPicture) == false; + public string? FullPicture { get; } /// /// Gets a link to an icon representing the type of this post. /// - public string Icon { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasIcon => string.IsNullOrWhiteSpace(Icon) == false; + public string? Icon { get; } // TODO: Add support for the "instagram_eligibility" property /// /// Gets whether this post is marked as hidden (Applies to Pages only). /// - public bool IsHidden { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasIsHidden => HasJsonProperty(FacebookPostFields.IsHidden.Alias); + public bool? IsHidden { get; } // TODO: Add support for the "is_instagram_eligible" property /// /// Gets whether this post is marked as hidden (Applies to Pages only). /// - public bool IsPublished { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasIsPublished => HasJsonProperty("is_published"); + public bool? IsPublished { get; } /// /// Gets the link attached to this post. /// - public string Link { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasLink => string.IsNullOrWhiteSpace(Link) == false; + public string? Link { get; } /// /// Gets the status message in the post. /// - public string Message { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasMessage => string.IsNullOrWhiteSpace(Message) == false; + public string? Message { get; } /// /// Gets an array of the profiles tagged in the property. /// - public FacebookProfileTag[] MessageTags { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasMessageTags => MessageTags.Length > 0; + public IReadOnlyList? MessageTags { get; } /// /// Gets the name of the . /// - public string Name { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasName => string.IsNullOrWhiteSpace(Name) == false; + public string? Name { get; } /// /// Gets the ID of any uploaded photo or video attached to the post. /// - public string ObjectId { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasObjectId => string.IsNullOrWhiteSpace(ObjectId) == false; + public string? ObjectId { get; } /// /// Gets the ID of a parent post for this post, if it exists. For example, if this story is a /// 'Your Page was mentioned in a post' story, the will be the original post where the /// mention happened. /// - public string ParentId { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasParentId => string.IsNullOrWhiteSpace(ParentId) == false; + public string? ParentId { get; } /// /// Gets the URL to the permalink page of the post. /// - public string PermalinkUrl { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasPermalinkUrl => string.IsNullOrWhiteSpace(PermalinkUrl) == false; + public string? PermalinkUrl { get; } /// /// Gets the picture scraped from any included with the post. /// - public string Picture { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasPicture => string.IsNullOrWhiteSpace(Picture) == false; + public string? Picture { get; } /// /// Gets any location information attached to the post. /// - public FacebookPlace Place { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasPlace => Place != null; + public FacebookPlace? Place { get; } /// /// Gets the privacy settings of the post. /// - public FacebookPostPrivacy Privacy { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasPrivacy => Privacy != null; + public FacebookPostPrivacy? Privacy { get; } /// /// Gets a list of properties for any attached video, for example, the length of the video. /// - public FacebookPostProperty[] Properties { get; } - - /// - /// Gets whether the post has any . - /// - public bool HasProperties => Properties.Length > 0; + public IReadOnlyList? Properties { get; } /// /// Gets information about how many times the post has been shared. If the post hasn't yet /// been shared, this property will return null. /// - public FacebookShares Shares { get; } - - /// - /// Gets whether the property has a value. - /// - public bool HasShares => Shares != null; + public FacebookShares? Shares { get; } /// /// Gets an object with information about how the entry has been liked. /// - public FacebookLikesCollection Likes { get; } - - /// - /// Gets whether the property has a value. - /// - public bool HasLikes => Likes != null; + public FacebookLikesCollection? Likes { get; } /// /// Gets an object with information about how the entry has been commented. /// - public FacebookCommentsCollection Comments { get; } - - /// - /// Gets whether the property has a value. - /// - public bool HasComments => Comments != null; + public FacebookCommentsCollection? Comments { get; } /// /// Gets a URL to any Flash movie or video file attached to the post. /// - public string Source { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasSource => string.IsNullOrWhiteSpace(Source) == false; + public string? Source { get; } /// /// Gets the type of a status update. /// - public FacebookPostStatusType StatusType { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasStatusType => StatusType == FacebookPostStatusType.NotSpecified; + public FacebookPostStatusType? StatusType { get; } /// /// Gets text from stories not intentionally generated by users, such as those generated when two people become /// friends, or when someone else posts on the person's wall. /// - public string Story { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasStory => string.IsNullOrWhiteSpace(Story) == false; + public string? Story { get; } /// /// Gets an array of the profiles tagged in the property. /// - public FacebookProfileTag[] StoryTags { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasStoryTags => StoryTags.Length > 0; + public IReadOnlyList? StoryTags { get; } // TODO: Add support for the "targeting" property @@ -336,12 +194,7 @@ public class FacebookPost : FacebookObject { /// /// Gets the object type of this post. /// - public FacebookPostType Type { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasType => Type == FacebookPostType.NotSpecified; + public FacebookPostType? Type { get; } /// /// Gets the time when the post was created, last edited or the time of the last comment that was left on the @@ -349,12 +202,7 @@ public class FacebookPost : FacebookObject { /// /// For a post about a life event, this will be the date and time of the life event. /// - public EssentialsTime UpdatedTime { get; } - - /// - /// Gets whether the property was included in the response. - /// - public bool HasUpdatedTime => UpdatedTime != null; + public EssentialsTime? UpdatedTime { get; } // TODO: Add support for the "with_tags" property @@ -362,46 +210,46 @@ public class FacebookPost : FacebookObject { #region Constructors - private FacebookPost(JObject obj) : base(obj) { - Id = obj.GetString("id"); - AdminCreator = obj.GetObject("admin_creator", FacebookEntity.Parse); - Application = obj.GetObject("application", FacebookApplication.Parse); - Attachments = obj.GetObject("attachments", FacebookPostAttachments.Parse); + private FacebookPost(JObject json) : base(json) { + Id = json.GetString("id")!; + AdminCreator = json.GetObject("admin_creator", FacebookEntity.Parse); + Application = json.GetObject("application", FacebookApplication.Parse); + Attachments = json.GetObject("attachments", FacebookPostAttachments.Parse); // TODO: Add support for the "call_to_action" property // TODO: Add support for the "can_reply_privately" property - Caption = obj.GetString("caption"); - CreatedTime = obj.GetString("created_time", EssentialsTime.Parse); - Description = obj.GetString("description"); + Caption = json.GetString("caption"); + CreatedTime = json.GetString("created_time", EssentialsTime.Parse); + Description = json.GetString("description"); // TODO: Add support for the "feed_targeting" property - From = obj.GetObject("from", FacebookProfile.Parse); - FullPicture = obj.GetString("full_picture"); - Icon = obj.GetString("icon"); + From = json.GetObject("from", FacebookProfile.Parse); + FullPicture = json.GetString("full_picture"); + Icon = json.GetString("icon"); // TODO: Add support for the "instagram_eligibility" property - IsHidden = obj.GetBoolean(FacebookPostFields.IsHidden.Alias); + IsHidden = json.GetBooleanOrNull(FacebookPostFields.IsHidden.Alias); // TODO: Add support for the "is_instagram_eligible" property - IsPublished = obj.GetBoolean("is_published"); - Link = obj.GetString("link"); - Message = obj.GetString("message"); - MessageTags = obj.GetArrayItems("message_tags", FacebookProfileTag.Parse); - Name = obj.GetString("name"); - ObjectId = obj.GetString("object_id"); - ParentId = obj.GetString("parent_id"); - PermalinkUrl = obj.GetString("permalink_url"); - Picture = obj.GetString("picture"); - Place = obj.GetObject("place", FacebookPlace.Parse); - Privacy = obj.GetObject("privacy", FacebookPostPrivacy.Parse); - Properties = obj.GetArray("properties", FacebookPostProperty.Parse) ?? new FacebookPostProperty[0]; - Shares = obj.GetObject("shares", FacebookShares.Parse); - Likes = obj.GetObject("likes", FacebookLikesCollection.Parse); - Comments = obj.GetObject("comments", FacebookCommentsCollection.Parse); - Source = obj.GetString("source"); - StatusType = obj.GetEnum("status_type", FacebookPostStatusType.NotSpecified); - Story = obj.GetString("story"); - StoryTags = obj.GetArrayItems("story_tags", FacebookProfileTag.Parse); + IsPublished = json.GetBooleanOrNull("is_published"); + Link = json.GetString("link"); + Message = json.GetString("message"); + MessageTags = json.GetArray("message_tags", FacebookProfileTag.Parse); + Name = json.GetString("name"); + ObjectId = json.GetString("object_id"); + ParentId = json.GetString("parent_id"); + PermalinkUrl = json.GetString("permalink_url"); + Picture = json.GetString("picture"); + Place = json.GetObject("place", FacebookPlace.Parse); + Privacy = json.GetObject("privacy", FacebookPostPrivacy.Parse); + Properties = json.GetArray("properties", FacebookPostProperty.Parse); + Shares = json.GetObject("shares", FacebookShares.Parse); + Likes = json.GetObject("likes", FacebookLikesCollection.Parse); + Comments = json.GetObject("comments", FacebookCommentsCollection.Parse); + Source = json.GetString("source"); + StatusType = json.GetEnumOrDefault("status_type"); + Story = json.GetString("story"); + StoryTags = json.GetArray("story_tags", FacebookProfileTag.Parse); // TODO: Add support for the "targeting" property // TODO: Add support for the "to" property - Type = obj.GetEnum("type", FacebookPostType.NotSpecified); - UpdatedTime = obj.GetString("updated_time", EssentialsTime.Parse); + Type = json.GetEnumOrDefault("type"); + UpdatedTime = json.GetString("updated_time", EssentialsTime.Parse); // TODO: Add support for the "with_tags" property } @@ -410,12 +258,13 @@ private FacebookPost(JObject obj) : base(obj) { #region Static methods /// - /// Parses the specified into an instance of . + /// Parses the specified into an instance of . /// - /// The instance of to be parsed. + /// The instance of to be parsed. /// An instance of . - public static FacebookPost Parse(JObject obj) { - return obj == null ? null : new FacebookPost(obj); + [return: NotNullIfNotNull("json")] + public static FacebookPost? Parse(JObject? json) { + return json == null ? null : new FacebookPost(json); } #endregion diff --git a/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostList.cs b/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostList.cs new file mode 100644 index 0000000..72c9e29 --- /dev/null +++ b/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostList.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json.Linq; +using Skybrud.Essentials.Json.Newtonsoft.Extensions; +using Skybrud.Social.Facebook.Models.Common; +using Skybrud.Social.Facebook.Models.Pagination; + +namespace Skybrud.Social.Facebook.Models.Posts { + + /// + /// Class representing a collection of Facebook posts. + /// + public class FacebookPostList : FacebookObject, IFacebookList { + + #region Properties + + /// + /// Gets an array of representing the posts. + /// + public IReadOnlyList Data { get; } + + /// + /// Gets pagination information about the response. + /// + public FacebookCursorBasedPagination Paging { get; } + + #endregion + + #region Constructors + + private FacebookPostList(JObject obj) : base(obj) { + Data = obj.GetArrayItems("data", FacebookPost.Parse); + Paging = obj.GetObject("paging", FacebookCursorBasedPagination.Parse)!; + } + + #endregion + + #region Static methods + + /// + /// Parses the specified object into an instance of . + /// + /// The instance of to be parsed. + /// An instance of . + [return: NotNullIfNotNull("json")] + public static FacebookPostList? Parse(JObject? json) { + return json == null ? null : new FacebookPostList(json); + } + + #endregion + + } + +} \ No newline at end of file diff --git a/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostPrivacyValue.cs b/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostPrivacyValue.cs index f4fd4c4..2ef8f61 100644 --- a/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostPrivacyValue.cs +++ b/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostPrivacyValue.cs @@ -1,12 +1,20 @@ -using Skybrud.Social.Facebook.Models.Posts; +using Newtonsoft.Json; +using Skybrud.Essentials.Json.Converters.Enums; +using Skybrud.Essentials.Strings; namespace Skybrud.Social.Facebook.Models.Posts { /// /// Enum class representing the privacy setting of a . /// + [JsonConverter(typeof(EnumStringConverter), TextCasing.Underscore)] public enum FacebookPostPrivacyValue { + /// + /// Indiciates a value that is currently not supported by this package. + /// + Unknown, + /// /// Indicates that everyone can see the post. /// diff --git a/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostStatusType.cs b/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostStatusType.cs index dfc4435..d9f7e00 100644 --- a/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostStatusType.cs +++ b/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostStatusType.cs @@ -1,26 +1,44 @@ -namespace Skybrud.Social.Facebook.Models.Posts { +using Newtonsoft.Json; +using Skybrud.Essentials.Json.Converters.Enums; +using Skybrud.Essentials.Strings; + +#pragma warning disable CS1591 + +namespace Skybrud.Social.Facebook.Models.Posts { /// /// Enum class indicating the status type of a Facebook post. /// + [JsonConverter(typeof(EnumStringConverter), TextCasing.Underscore)] public enum FacebookPostStatusType { /// - /// Indicates that the status_type property wasn't part of the response from the Facebook Graph API. + /// Indiciates a value that is currently not supported by this package. /// - NotSpecified, + Unknown, MobileStatusUpdate, + CreatedNote, + AddedPhotos, + AddedVideo, + SharedStory, + CreatedGroup, + CreatedEvent, + WallPost, + AppCreatedStory, + PublishedStory, + TaggedInPhoto, + ApprovedFriend } diff --git a/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostType.cs b/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostType.cs index 92c8d12..c44d571 100644 --- a/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostType.cs +++ b/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostType.cs @@ -1,19 +1,30 @@ -namespace Skybrud.Social.Facebook.Models.Posts { +using Newtonsoft.Json; +using Skybrud.Essentials.Json.Converters.Enums; +using Skybrud.Essentials.Strings; + +#pragma warning disable CS1591 + +namespace Skybrud.Social.Facebook.Models.Posts { /// /// Enum class indicating the type of a Facebook post. /// + [JsonConverter(typeof(EnumStringConverter), TextCasing.Underscore)] public enum FacebookPostType { /// - /// Indicates that the type property wasn't part of the response from the Facebook Graph API. + /// Indiciates a value that is currently not supported by this package. /// - NotSpecified, + Unknown, Link, + Status, + Photo, + Video, + Offer } diff --git a/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostsCollection.cs b/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostsCollection.cs deleted file mode 100644 index 0c63ded..0000000 --- a/src/Skybrud.Social.Facebook/Models/Posts/FacebookPostsCollection.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Newtonsoft.Json.Linq; -using Skybrud.Essentials.Json.Newtonsoft.Extensions; -using Skybrud.Social.Facebook.Models.Pagination; - -namespace Skybrud.Social.Facebook.Models.Posts { - - /// - /// Class representing a collection of Facebook posts. - /// - public class FacebookPostsCollection : FacebookObject { - - #region Properties - - /// - /// Gets an array of representing the posts. - /// - public FacebookPost[] Data { get; } - - /// - /// Gets pagination information about the response. - /// - public FacebookPaging Paging { get; } - - #endregion - - #region Constructors - - private FacebookPostsCollection(JObject obj) : base(obj) { - Data = obj.GetArray("data", FacebookPost.Parse); - Paging = obj.GetObject("paging", FacebookPaging.Parse); - } - - #endregion - - #region Static methods - - /// - /// Parses the specified into an instance of . - /// - /// The instance of to be parsed. - /// An instance of . - public static FacebookPostsCollection Parse(JObject obj) { - return obj == null ? null : new FacebookPostsCollection(obj); - } - - #endregion - - } - -} \ No newline at end of file diff --git a/src/Skybrud.Social.Facebook/OAuth/FacebookOAuthClient.cs b/src/Skybrud.Social.Facebook/OAuth/FacebookOAuthClient.cs index 36588ac..dee139c 100644 --- a/src/Skybrud.Social.Facebook/OAuth/FacebookOAuthClient.cs +++ b/src/Skybrud.Social.Facebook/OAuth/FacebookOAuthClient.cs @@ -42,7 +42,7 @@ public class FacebookOAuthClient : HttpClient { #endregion /// - /// Gets or sets the version of the Facebook Graph API to be used. Defaults to v3.2. + /// Gets or sets the version of the Facebook Graph API to be used. Defaults to v16.0. /// public string Version { get; set; } @@ -123,7 +123,7 @@ public class FacebookOAuthClient : HttpClient { /// Initializes an OAuth client with empty information. /// public FacebookOAuthClient() { - Version = "v3.2"; + Version = "v16.0"; Accounts = new FacebookAccountsRawEndpoint(this); Applications = new FacebookApplicationsRawEndpoint(this); Debug = new FacebookDebugRawEndpoint(this); diff --git a/src/Skybrud.Social.Facebook/Options/Common/Pagination/FacebookTimeBasedPaginationOptions.cs b/src/Skybrud.Social.Facebook/Options/Common/Pagination/FacebookTimeBasedPaginationOptions.cs index e3e4ce8..464e7e2 100644 --- a/src/Skybrud.Social.Facebook/Options/Common/Pagination/FacebookTimeBasedPaginationOptions.cs +++ b/src/Skybrud.Social.Facebook/Options/Common/Pagination/FacebookTimeBasedPaginationOptions.cs @@ -18,17 +18,17 @@ public class FacebookTimeBasedPaginationOptions : IHttpGetOptions { /// /// Gets or sets the number of individual objects that are returned in each page. /// - public int Limit { get; set; } + public int? Limit { get; set; } /// /// Gets or sets the timestamp that points to the start of the range of time-based data. /// - public EssentialsTime Since { get; set; } + public EssentialsTime? Since { get; set; } /// /// Gets or sets the timestamp that points to the end of the range of time-based data. /// - public EssentialsTime Until { get; set; } + public EssentialsTime? Until { get; set; } #endregion @@ -37,9 +37,7 @@ public class FacebookTimeBasedPaginationOptions : IHttpGetOptions { /// /// Initializes a new instance with default values. /// - protected FacebookTimeBasedPaginationOptions() { - Limit = -1; - } + protected FacebookTimeBasedPaginationOptions() { } #endregion @@ -49,10 +47,10 @@ protected FacebookTimeBasedPaginationOptions() { /// Gets an instance of representing the GET parameters. /// public virtual IHttpQueryString GetQueryString() { - HttpQueryString query = new HttpQueryString(); + HttpQueryString query = new(); if (Limit >= 0) query.Set("limit", Limit); - if (Since != null && Since.UnixTimestamp > 0) query.Set("since", Since.UnixTimestamp); - if (Until != null && Until.UnixTimestamp > 0) query.Set("until", Until.UnixTimestamp); + if (Since != null && Since.UnixTimeSeconds > 0) query.Set("since", Since.UnixTimeSeconds); + if (Until != null && Until.UnixTimeSeconds > 0) query.Set("until", Until.UnixTimeSeconds); return query; } diff --git a/src/Skybrud.Social.Facebook/Options/Posts/FacebookCreatePostOptions.cs b/src/Skybrud.Social.Facebook/Options/Posts/FacebookCreatePostOptions.cs index 5bd90d6..6ff13f2 100644 --- a/src/Skybrud.Social.Facebook/Options/Posts/FacebookCreatePostOptions.cs +++ b/src/Skybrud.Social.Facebook/Options/Posts/FacebookCreatePostOptions.cs @@ -1,5 +1,10 @@ -using Skybrud.Essentials.Http.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using Skybrud.Essentials.Common; +using Skybrud.Essentials.Http; +using Skybrud.Essentials.Http.Collections; using Skybrud.Essentials.Http.Options; +using Skybrud.Social.Facebook.Fields; namespace Skybrud.Social.Facebook.Options.Posts { @@ -9,60 +14,64 @@ namespace Skybrud.Social.Facebook.Options.Posts { /// /// https://developers.facebook.com/docs/graph-api/reference/v2.8/page/feed#publish /// - public class FacebookCreatePostOptions : IHttpPostOptions { + public class FacebookCreatePostOptions : IHttpRequestOptions { #region Properties /// /// Gets or sets the identifier (ID or alias) of the page, user or similar. /// - public string Identifier { get; set; } +#if NET7_0_OR_GREATER + public required string Identifier { get; set; } +#else + public string? Identifier { get; set; } +#endif /// /// Gets or sets the main body of the post, otherwise called the status message. Either or /// must be supplied. The message can contain mentions of Facebook Pages using the /// following syntax: @[page-id] /// - public string Message { get; set; } + public string? Message { get; set; } /// /// Gets or sets the URL of a link to attach to the post. Either or /// must be supplied. /// - public string Link { get; set; } + public string? Link { get; set; } /// /// Gets or sets the preview image associated with the link. /// - public string Picture { get; set; } + public string? Picture { get; set; } /// /// Gets or sets the title of the link preview. /// - public string Name { get; set; } + public string? Name { get; set; } /// /// Gets or sets the caption under the title in the link preview. /// - public string Caption { get; set; } + public string? Caption { get; set; } /// /// Gets or sets the description in the link preview. /// - public string Description { get; set; } + public string? Description { get; set; } // TODO: Add support for the "actions" parameter /// /// Gets or sets the page ID of a location associated with this post. /// - public string Place { get; set; } + public string? Place { get; set; } /// /// Gets or sets an array of user IDs of people tagged in this post. You cannot specify this field without also /// specifying a . /// - public string[] Tags { get; set; } + public List Tags { get; set; } = new(); // TODO: Add support for the "object_attachment" parameter @@ -84,31 +93,70 @@ public class FacebookCreatePostOptions : IHttpPostOptions { // TODO: Add support for the "multi_share_end_card" parameter + /// + /// Gets or sets the fields to be returned. + /// + public FacebookFieldList Fields { get; set; } + #endregion - #region Member methods + #region Constructors /// - /// Gets an instance of representing the GET parameters. + /// Initializes a new instance with default options. /// - public IHttpQueryString GetQueryString() { - return new HttpQueryString(); + public FacebookCreatePostOptions() { + Fields = new FacebookFieldList(); } /// - /// Gets an instance of representing the POST parameters. + /// Initializes a new instance with the specified . /// - public IHttpPostData GetPostData() { + /// The identifier (ID or alias) of the page. +#if NET7_0_OR_GREATER + [SetsRequiredMembers] +#endif + public FacebookCreatePostOptions(string identifier) : this() { + Identifier = identifier; + } + + /// + /// Initializes a new instance with the specified and . + /// + /// The identifier (ID or alias) of the page. + /// A collection of the fields that should be returned by the API. +#if NET7_0_OR_GREATER + [SetsRequiredMembers] +#endif + public FacebookCreatePostOptions(string identifier, FacebookFieldList? fields) { + Identifier = identifier; + Fields = fields ?? new FacebookFieldList(); + } + + #endregion + + #region Member methods + + /// + public IHttpRequest GetRequest() { + + // Validate required properties + if (string.IsNullOrWhiteSpace(Identifier)) throw new PropertyNotSetException(nameof(Identifier)); + + // Initialize the POST data IHttpPostData postData = new HttpPostData(); - if (string.IsNullOrWhiteSpace(Message) == false) postData.Add("message", Message); - if (string.IsNullOrWhiteSpace(Link) == false) postData.Add("link", Link); - if (string.IsNullOrWhiteSpace(Picture) == false) postData.Add("picture", Picture); - if (string.IsNullOrWhiteSpace(Name) == false) postData.Add("name", Name); - if (string.IsNullOrWhiteSpace(Caption) == false) postData.Add("caption", Caption); - if (string.IsNullOrWhiteSpace(Description) == false) postData.Add("description", Description); - if (string.IsNullOrWhiteSpace(Place) == false) postData.Add("place", Place); - if (Tags != null && Tags.Length > 0) postData.Add("tags", string.Join(",", Tags)); - return postData; + if (!string.IsNullOrWhiteSpace(Message)) postData.Add("message", Message!); + if (!string.IsNullOrWhiteSpace(Link)) postData.Add("link", Link!); + if (!string.IsNullOrWhiteSpace(Picture)) postData.Add("picture", Picture!); + if (!string.IsNullOrWhiteSpace(Name)) postData.Add("name", Name!); + if (!string.IsNullOrWhiteSpace(Caption)) postData.Add("caption", Caption!); + if (!string.IsNullOrWhiteSpace(Description)) postData.Add("description", Description!); + if (!string.IsNullOrWhiteSpace(Place)) postData.Add("place", Place!); + if (Tags is {Count: > 0}) postData.Add("tags", string.Join(",", Tags)); + + // Initialize a new GET request + return HttpRequest.Post($"/{Identifier}/feed", postData); + } #endregion diff --git a/src/Skybrud.Social.Facebook/Options/Posts/FacebookGetPostOptions.cs b/src/Skybrud.Social.Facebook/Options/Posts/FacebookGetPostOptions.cs index eb09cdd..4d676b0 100644 --- a/src/Skybrud.Social.Facebook/Options/Posts/FacebookGetPostOptions.cs +++ b/src/Skybrud.Social.Facebook/Options/Posts/FacebookGetPostOptions.cs @@ -1,4 +1,7 @@ -using Skybrud.Essentials.Http.Collections; +using System.Diagnostics.CodeAnalysis; +using Skybrud.Essentials.Common; +using Skybrud.Essentials.Http; +using Skybrud.Essentials.Http.Collections; using Skybrud.Essentials.Http.Options; using Skybrud.Social.Facebook.Fields; @@ -7,14 +10,18 @@ namespace Skybrud.Social.Facebook.Options.Posts { /// /// Class representing the options for a call to the Facebook Graph API to get information about a single post. /// - public class FacebookGetPostOptions : IHttpGetOptions { + public class FacebookGetPostOptions : IHttpRequestOptions { #region Properties /// /// Gets or sets the identifier (ID) of the post. /// - public string Identifier { get; set; } +#if NET7_0_OR_GREATER + public required string Identifier { get; set; } +#else + public string? Identifier { get; set; } +#endif /// /// Gets or sets the fields to be returned. @@ -36,8 +43,12 @@ public FacebookGetPostOptions() { /// Initializes an instance with the specified . /// /// The identifier (ID) of the post. - public FacebookGetPostOptions(string identifier) : this() { +#if NET7_0_OR_GREATER + [SetsRequiredMembers] +#endif + public FacebookGetPostOptions(string identifier) { Identifier = identifier; + Fields = new FacebookFieldList(); } /// @@ -46,7 +57,10 @@ public FacebookGetPostOptions(string identifier) : this() { /// /// The identifier (ID) of the post. /// A collection of the fields that should be returned by the API. - public FacebookGetPostOptions(string identifier, FacebookFieldList fields) : this() { +#if NET7_0_OR_GREATER + [SetsRequiredMembers] +#endif + public FacebookGetPostOptions(string identifier, FacebookFieldList? fields) { Identifier = identifier; Fields = fields ?? new FacebookFieldList(); } @@ -55,19 +69,18 @@ public FacebookGetPostOptions(string identifier, FacebookFieldList fields) : thi #region Member methods - /// - /// Gets an instance of representing the GET parameters. - /// - public IHttpQueryString GetQueryString() { + /// + public IHttpRequest GetRequest() { - // Convert the collection of fields to a string - string fields = (Fields == null ? string.Empty : Fields.ToString()).Trim(); + // Validate required properties + if (string.IsNullOrWhiteSpace(Identifier)) throw new PropertyNotSetException(nameof(Identifier)); - // Construct the query string - HttpQueryString query = new HttpQueryString(); - if (string.IsNullOrWhiteSpace(fields) == false) query.Set("fields", fields); + // Initialize the query string + HttpQueryString query = new(); + if (Fields is { Count: > 0 }) query.Set("fields", Fields); - return query; + // Initialize a new GET request + return HttpRequest.Get($"/{Identifier}", query); } diff --git a/src/Skybrud.Social.Facebook/Options/Posts/FacebookGetPostsOptions.cs b/src/Skybrud.Social.Facebook/Options/Posts/FacebookGetPostsOptions.cs index eb4c0ca..c9b4c5a 100644 --- a/src/Skybrud.Social.Facebook/Options/Posts/FacebookGetPostsOptions.cs +++ b/src/Skybrud.Social.Facebook/Options/Posts/FacebookGetPostsOptions.cs @@ -1,5 +1,8 @@ -using Skybrud.Essentials.Http.Collections; -using Skybrud.Essentials.Time; +using System.Diagnostics.CodeAnalysis; +using Skybrud.Essentials.Common; +using Skybrud.Essentials.Http; +using Skybrud.Essentials.Http.Collections; +using Skybrud.Essentials.Http.Options; using Skybrud.Social.Facebook.Fields; using Skybrud.Social.Facebook.Options.Common.Pagination; @@ -8,14 +11,18 @@ namespace Skybrud.Social.Facebook.Options.Posts { /// /// Class representing the options for a call to the Facebook Graph API to get a list of posts. /// - public class FacebookGetPostsOptions : FacebookTimeBasedPaginationOptions { + public class FacebookGetPostsOptions : FacebookCursorBasedPaginationOptions, IHttpRequestOptions { #region Properties /// /// Gets or sets the identifier (ID) of the page or user. /// - public string Identifier { get; set; } +#if NET7_0_OR_GREATER + public required string Identifier { get; set; } +#else + public string? Identifier { get; set; } +#endif /// /// Gets or sets the fields to be returned. @@ -26,7 +33,7 @@ public class FacebookGetPostsOptions : FacebookTimeBasedPaginationOptions { /// Gets or sets whether or not to include any posts that were hidden by the Page. Defaults to /// false. /// - public bool IncludeHidden { get; set; } + public bool? IncludeHidden { get; set; } #endregion @@ -43,7 +50,10 @@ public FacebookGetPostsOptions() { /// Initializes a new instance based on the specified . /// /// The identifier (ID) of the page or user. - public FacebookGetPostsOptions(string identifier) : this() { +#if NET7_0_OR_GREATER + [SetsRequiredMembers] +#endif + public FacebookGetPostsOptions(string identifier) { Identifier = identifier; Fields = new FacebookFieldList(); } @@ -54,7 +64,10 @@ public FacebookGetPostsOptions(string identifier) : this() { /// /// The identifier (ID) of the page or user. /// A collection of the fields that should be returned by the API. - public FacebookGetPostsOptions(string identifier, FacebookFieldList fields) : this() { +#if NET7_0_OR_GREATER + [SetsRequiredMembers] +#endif + public FacebookGetPostsOptions(string identifier, FacebookFieldList? fields) { Identifier = identifier; Fields = fields ?? new FacebookFieldList(); } @@ -65,26 +78,15 @@ public FacebookGetPostsOptions(string identifier, FacebookFieldList fields) : th /// /// The identifier (ID) of the page or user. /// The maximum amount of items to be returned per page. - public FacebookGetPostsOptions(string identifier, int limit) { +#if NET7_0_OR_GREATER + [SetsRequiredMembers] +#endif + public FacebookGetPostsOptions(string identifier, int? limit) { Identifier = identifier; Limit = limit; Fields = new FacebookFieldList(); } - /// - /// Initializes a new instance based on the specified , - /// and . - /// - /// The identifier (ID) of the page or user. - /// The maximum amount of items to be returned per page. - /// The timestamp that points to the end of the range of time-based data. - public FacebookGetPostsOptions(string identifier, int limit, EssentialsTime until) { - Identifier = identifier; - Limit = limit; - Until = until; - Fields = new FacebookFieldList(); - } - /// /// Initializes a new instance based on the specified , /// and collection of . @@ -92,27 +94,15 @@ public FacebookGetPostsOptions(string identifier, int limit, EssentialsTime unti /// The identifier (ID) of the page or user. /// The maximum amount of items to be returned per page. /// A collection of the fields that should be returned by the API. - public FacebookGetPostsOptions(string identifier, int limit, FacebookFieldList fields) : this() { +#if NET7_0_OR_GREATER + [SetsRequiredMembers] +#endif + public FacebookGetPostsOptions(string identifier, int? limit, FacebookFieldList? fields) { Identifier = identifier; Limit = limit; Fields = fields ?? new FacebookFieldList(); } - /// - /// Initializes an instance with the specified , , - /// and collection of . - /// - /// The identifier (ID) of the page or user. - /// The maximum amount of items to be returned per page. - /// The timestamp that points to the end of the range of time-based data. - /// A collection of the fields that should be returned by the API. - public FacebookGetPostsOptions(string identifier, int limit, EssentialsTime until, FacebookFieldList fields) : this() { - Identifier = identifier; - Limit = limit; - Until = until; - Fields = fields ?? new FacebookFieldList(); - } - #endregion #region Member methods @@ -125,17 +115,28 @@ public override IHttpQueryString GetQueryString() { // Get the query string IHttpQueryString query = base.GetQueryString(); - // Convert the collection of fields to a string - string fields = (Fields == null ? string.Empty : Fields.ToString()).Trim(); - // Update the query string - if (string.IsNullOrWhiteSpace(fields) == false) query.Set("fields", fields); - if (IncludeHidden) query.Add("include_hidden", "true"); + if (Fields is { Count: > 0 }) query.Set("fields", Fields); + if (IncludeHidden is not null) query.Add("include_hidden", IncludeHidden); return query; } + /// + public IHttpRequest GetRequest() { + + // Validate required properties + if (string.IsNullOrWhiteSpace(Identifier)) throw new PropertyNotSetException(nameof(Identifier)); + + // Initialize the query string + IHttpQueryString query = GetQueryString(); + + // Initialize a new GET request + return HttpRequest.Get($"/{Identifier}/posts", query); + + } + #endregion } diff --git a/src/Skybrud.Social.Facebook/Responses/Feed/FacebookGetFeedResponse.cs b/src/Skybrud.Social.Facebook/Responses/Feed/FacebookGetFeedResponse.cs index c27383b..a295259 100644 --- a/src/Skybrud.Social.Facebook/Responses/Feed/FacebookGetFeedResponse.cs +++ b/src/Skybrud.Social.Facebook/Responses/Feed/FacebookGetFeedResponse.cs @@ -7,7 +7,7 @@ namespace Skybrud.Social.Facebook.Responses.Feed { /// Class representing a response of a request to get a collection of of a Facebook /// feed. /// - public class FacebookGetFeedResponse : FacebookResponse { + public class FacebookGetFeedResponse : FacebookResponse { #region Constructors @@ -17,7 +17,7 @@ private FacebookGetFeedResponse(IHttpResponse response) : base(response) { ValidateResponse(response); // Parse the response body - Body = ParseJsonObject(response.Body, FacebookPostsCollection.Parse); + Body = ParseJsonObject(response.Body, FacebookPostList.Parse); } diff --git a/src/Skybrud.Social.Facebook/Responses/Posts/FacebookCreatePostResponse.cs b/src/Skybrud.Social.Facebook/Responses/Posts/FacebookCreatePostResponse.cs deleted file mode 100644 index 2b3e08b..0000000 --- a/src/Skybrud.Social.Facebook/Responses/Posts/FacebookCreatePostResponse.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Skybrud.Essentials.Http; -using Skybrud.Social.Facebook.Models.Posts; - -namespace Skybrud.Social.Facebook.Responses.Posts { - - /// - /// Class representing the options for creating a Facebook post. - /// - public class FacebookCreatePostResponse : FacebookResponse { - - #region Constructors - - private FacebookCreatePostResponse(IHttpResponse response) : base(response) { - - // Validate the response - ValidateResponse(response); - - // Parse the response body - Body = ParseJsonObject(response.Body, FacebookCreatePostSummary.Parse); - - } - - #endregion - - #region Static methods - - /// - /// Parses the specified into an instance of . - /// - /// The instance of representing the raw response. - /// An instance of representing the response. - public static FacebookCreatePostResponse ParseResponse(IHttpResponse response) { - return response == null ? null : new FacebookCreatePostResponse(response); - } - - #endregion - - } - -} \ No newline at end of file diff --git a/src/Skybrud.Social.Facebook/Responses/Posts/FacebookGetPostResponse.cs b/src/Skybrud.Social.Facebook/Responses/Posts/FacebookGetPostResponse.cs deleted file mode 100644 index 9854c59..0000000 --- a/src/Skybrud.Social.Facebook/Responses/Posts/FacebookGetPostResponse.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Skybrud.Essentials.Http; -using Skybrud.Social.Facebook.Models.Posts; - -namespace Skybrud.Social.Facebook.Responses.Posts { - - /// - /// Class representing a response of a request to get information about a single . - /// - public class FacebookGetPostResponse : FacebookResponse { - - #region Constructors - - private FacebookGetPostResponse(IHttpResponse response) : base(response) { - - // Validate the response - ValidateResponse(response); - - // Parse the response body - Body = ParseJsonObject(response.Body, FacebookPost.Parse); - - } - - #endregion - - #region Static methods - - /// - /// Parses the specified into an instance of . - /// - /// The instance of representing the raw response. - /// An instance of representing the response. - public static FacebookGetPostResponse ParseResponse(IHttpResponse response) { - return response == null ? null : new FacebookGetPostResponse(response); - } - - #endregion - - } - -} \ No newline at end of file diff --git a/src/Skybrud.Social.Facebook/Responses/Posts/FacebookGetPostsResponse.cs b/src/Skybrud.Social.Facebook/Responses/Posts/FacebookGetPostsResponse.cs deleted file mode 100644 index e2cadbc..0000000 --- a/src/Skybrud.Social.Facebook/Responses/Posts/FacebookGetPostsResponse.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Skybrud.Essentials.Http; -using Skybrud.Social.Facebook.Models.Posts; - -namespace Skybrud.Social.Facebook.Responses.Posts { - - /// - /// Class representing a response for getting a collection of . - /// - public class FacebookGetPostsResponse : FacebookResponse { - - #region Constructors - - private FacebookGetPostsResponse(IHttpResponse response) : base(response) { - - // Validate the response - ValidateResponse(response); - - // Parse the response body - Body = ParseJsonObject(response.Body, FacebookPostsCollection.Parse); - - } - - #endregion - - #region Static methods - - /// - /// Parses the specified into an instance of . - /// - /// The instance of representing the raw response. - /// An instance of representing the response. - public static FacebookGetPostsResponse ParseResponse(IHttpResponse response) { - return response == null ? null : new FacebookGetPostsResponse(response); - } - - #endregion - - } - -} \ No newline at end of file diff --git a/src/Skybrud.Social.Facebook/Responses/Posts/FacebookPostListResponse.cs b/src/Skybrud.Social.Facebook/Responses/Posts/FacebookPostListResponse.cs new file mode 100644 index 0000000..fd47939 --- /dev/null +++ b/src/Skybrud.Social.Facebook/Responses/Posts/FacebookPostListResponse.cs @@ -0,0 +1,27 @@ +using Skybrud.Essentials.Http; +using Skybrud.Social.Facebook.Models.Posts; + +namespace Skybrud.Social.Facebook.Responses.Posts { + + /// + /// Class representing a response for getting a collection of . + /// + public class FacebookPostListResponse : FacebookResponse { + + /// + /// Initializes a new instance based on the specified . + /// + /// The raw response the instance should be based on. + public FacebookPostListResponse(IHttpResponse response) : base(response) { + + // Validate the response + ValidateResponse(response); + + // Parse the response body + Body = ParseJsonObject(response.Body, FacebookPostList.Parse); + + } + + } + +} \ No newline at end of file diff --git a/src/Skybrud.Social.Facebook/Responses/Posts/FacebookPostResponse.cs b/src/Skybrud.Social.Facebook/Responses/Posts/FacebookPostResponse.cs new file mode 100644 index 0000000..444e91f --- /dev/null +++ b/src/Skybrud.Social.Facebook/Responses/Posts/FacebookPostResponse.cs @@ -0,0 +1,27 @@ +using Skybrud.Essentials.Http; +using Skybrud.Social.Facebook.Models.Posts; + +namespace Skybrud.Social.Facebook.Responses.Posts { + + /// + /// Class representing a response of a request to get information about a single . + /// + public class FacebookPostResponse : FacebookResponse { + + /// + /// Initializes a new instance based on the specified . + /// + /// The raw response the instance should be based on. + public FacebookPostResponse(IHttpResponse response) : base(response) { + + // Validate the response + ValidateResponse(response); + + // Parse the response body + Body = ParseJsonObject(response.Body, FacebookPost.Parse); + + } + + } + +} \ No newline at end of file