Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/fb/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions lib/fb/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions spec/page/posts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down