Repository URL to install this package:
Version:
0.9.12 ▾
|
# frozen_string_literal: true
module ActionSprout::Facebook
module Services
class ParsePublicPost
method_object :post
def call
parsed_post
end
private
def parsed_post
{
"facebook_post_id" => post["id"],
"created_time" => post["created_time"],
"created_at" => created_time,
"updated_time" => post["updated_time"],
"updated_at" => updated_time,
"message" => post["message"],
"permalink_url" => post["permalink_url"],
"name" => post["name"],
"description" => post["description"],
"attachment_title" => attachment_title,
"attachment_description" => attachment_description,
"caption" => post["caption"],
"type" => post_type,
"status_type" => post["status_type"],
"link" => post["link"],
"picture" => post["picture"],
"full_picture" => post["full_picture"],
"reaction_count" => reaction_count,
"comment_count" => comment_count,
"share_count" => share_count,
"engagement_count" => engagement_count,
}
end
def created_time
Time.parse(post["created_time"]).to_i if post["created_time"]
end
def updated_time
Time.parse(post["updated_time"]).to_i if post["updated_time"]
end
def attachment_title
attachments["title"]
end
def attachment_description
attachments["description"]
end
def post_type
attachments["type"] == "note" ? "note" : post["type"]
end
def reaction_count
@_reaction_count ||= post.dig("reactions", "summary", "total_count") || 0
end
def comment_count
@_comment_count ||= post.dig("comments", "summary", "total_count") || 0
end
def share_count
@_share_count ||= post.dig("shares", "count") || 0
end
def engagement_count
@_engagement_count ||= reaction_count + comment_count + share_count
end
def attachments
@_attachments ||= post.dig("attachments", "data", 0) || {}
end
end
end
end