Last active
August 29, 2015 14:20
-
-
Save israelst/4bba2ea020b9ec625493 to your computer and use it in GitHub Desktop.
Function that turns Facebook insights into a flat structure.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function preprocess(post){ | |
var flatPost = post.insights.data.reduce(function(post, insight){ | |
post[insight.name] = insight.values[0].value; | |
return post; | |
}, {}); | |
flatPost.likes = post.likes.summary.total_count; | |
flatPost.comments = post.comments.summary.total_count; | |
flatPost.shares = (post.shares || {'count': 0}).count; | |
return flatPost; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment