Skip to content

Instantly share code, notes, and snippets.

@joshuarule
Last active August 29, 2015 14:27
Show Gist options
  • Save joshuarule/ebabc05ca35e9cd0b4c4 to your computer and use it in GitHub Desktop.
Save joshuarule/ebabc05ca35e9cd0b4c4 to your computer and use it in GitHub Desktop.
facebookHelper.prototype.getMedia = function (post) {
console.log(post.type);
console.log(post.caption);
var imageUrl = post.type == "link" ? (post.picture ? this.cleanImageUrl(post.picture.match(/(url=)(.+)$/)[2]) : null) : (this.fbFeedUrl + "{objectId}/picture?type=normal&redirect=true&access_token={token}"
.replace("{objectId}", post.object_id)
.replace("{token}", this.accessToken));
if (post.type == "link" || post.type == "photo" || post.type == "event") {
return imageUrl ? this.imgTemplate.replace(/{url}/g, imageUrl).replace(/{description}/g, post.description) : ""
+ (post.type == "link" ?
this.linkTemplate.replace(/{linkText}/g, post.name ? post.name : post.story).replace(/{href}/g, post.link) + (post.description ? this.descriptionTemplate.replace(/{description}/g, post.description) : '')
: ""
);
}
// videos that have no caption
else if (post.type == "video" && post.caption == undefined) {
return imageUrl ? this.imgTemplate.replace(/{url}/g, imageUrl).replace(/{description}/g, post.description) : ""
+ (post.type == "link" ?
this.linkTemplate.replace(/{linkText}/g, post.name ? post.name : post.story).replace(/{href}/g, post.link) + (post.description ? this.descriptionTemplate.replace(/{description}/g, post.description) : '')
: ""
);
}
// any video that the caption isn't soundcloud
else if (post.type == "video" && post.caption != "soundcloud.com") {
var videoId = post.link.split('/');
videoId = videoId[videoId.length - 1];
return this.videoTemplate.replace(/{videoId}/g, videoId)
} else {
return this.soundCloudTemplate.replace(/{soundCloudUrl}/g, this.getSoundCloudUrl(post.source))
}
}
facebookHelper.prototype.cleanImageUrl = function (url) {
var imageUrl = decodeURIComponent(url);
return (imageUrl.indexOf('&') != -1 ? imageUrl.split('&')[0] : imageUrl);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment