diff --git a/lib/fb/page.rb b/lib/fb/page.rb index c1d1bdd..6b6d828 100644 --- a/lib/fb/page.rb +++ b/lib/fb/page.rb @@ -117,7 +117,8 @@ def posts_params {}.tap do |params| params[:access_token] = @access_token params[:limit] = 100 - params[:fields]= %i(id message permalink_url created_time type properties).join ',' + params[:fields]= ['id', 'message', 'permalink_url', 'created_time', 'type', 'properties', + 'comments.limit(0).summary(true)', 'likes.limit(0).summary(true)', 'reactions.limit(0).summary(true)'].join(',') end end diff --git a/lib/fb/post.rb b/lib/fb/post.rb index 18a8f41..d15c46c 100644 --- a/lib/fb/post.rb +++ b/lib/fb/post.rb @@ -39,6 +39,15 @@ class Post # @option [Integer] the total number of milliseconds your video was watched. attr_reader :video_view_time + # @return [Integer] the number of comments of the post. + attr_reader :comment_count + + # @return [Integer] the number of likes of the post. + attr_reader :like_count + + # @return [Integer] the number of reactions of the post. + attr_reader :reaction_count + # @param [Hash] options the options to initialize an instance of Fb::Post. # @option [String] :id The post id. # @option [String] :message The status message in the post or post story. @@ -65,6 +74,10 @@ def initialize(options = {}) @video_views_organic = options[:post_video_views_organic] if options[:post_video_views_organic] @video_views_paid = options[:post_video_views_paid] if options[:post_video_views_paid] @video_view_time = options[:post_video_view_time] if options[:post_video_view_time] + + @comment_count = options[:comments]['summary']['total_count'] if options[:comments] + @reaction_count = options[:reactions]['summary']['total_count'] if options[:reactions] + @like_count = options[:likes]['summary']['total_count'] if options[:likes] end # @return [String] the representation of the post. diff --git a/spec/page/posts_spec.rb b/spec/page/posts_spec.rb index 730f53c..b9db3a3 100644 --- a/spec/page/posts_spec.rb +++ b/spec/page/posts_spec.rb @@ -14,6 +14,10 @@ expect(page.posts.map &:type).to all(be_a String) expect(page.posts.map &:created_at).to all(be_a Time) expect(page.posts.map &:length).to all(be_a String) + + expect(page.posts.map &:comment_count).to all(be_a Integer) + expect(page.posts.map &:like_count).to all(be_a Integer) + expect(page.posts.map &:reaction_count).to all(be_a Integer) end end