Skip to content

Instantly share code, notes, and snippets.

@jensechu
Last active September 21, 2015 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jensechu/90851c184aa5b0ba80f2 to your computer and use it in GitHub Desktop.
Save jensechu/90851c184aa5b0ba80f2 to your computer and use it in GitHub Desktop.
Instagram Feed
InstagramFeed = function() {
var self = this;
self.props = {
$feedContainer: $('#instagram-feed-container'),
IMAGE_TEMPLATE: $('#contest-image-template').html(),
ACCESS_TOKEN: '1711440167.ac32776.52e47348e60a4bdda0b90d79507a08ae',
finalFeed: ''
};
self._setDependencies = function(options) {
$.extend(self.props, options);
self.props.url = 'https://api.instagram.com/v1/tags/' + self.props.hashtag + '/media/recent?access_token=' + self.props.ACCESS_TOKEN + '&count=' + self.props.count;
};
self._gatherPhotos = function() {
$.ajax({
url: self.props.url,
type: 'GET',
dataType: 'jsonp',
error: function(xhr, status, error) {
return;
},
success: function(resp, status) {
self._gatherPhotoData(resp);
}
});
};
self._gatherPhotoData = function(photos) {
$.each(photos.data, function() {
var imageURL = this.images.standard_resolution.url;
var authorURL = this.link;
self._buildPhotoElement(imageURL, authorURL);
});
self._addAllPhotoElements();
};
self._buildPhotoElement = function(imageURL, authorURL) {
var $photoContainer = $(self.props.IMAGE_TEMPLATE);
var $photo = $photoContainer.find('.instagram-photo');
var $photoLink = $photoContainer.find('.instagram-author-link');
$photo.attr('src', imageURL);
$photoLink.attr('href', authorURL);
self._addPhotoElement($photoContainer);
};
self._addPhotoElement = function($photoContainer) {
self.props.finalFeed = self.props.finalFeed + $photoContainer[0].outerHTML;
};
self._addAllPhotoElements = function($photoContainer) {
self.props.$feedContainer.html(self.props.finalFeed);
};
self.init = function(options) {
self._setDependencies(options);
self._gatherPhotos();
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment