Last active
August 29, 2015 13:57
-
-
Save schmidtsonian/9925730 to your computer and use it in GitHub Desktop.
Get latest post youtube
This file contains hidden or 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
var Youtube = (function() { | |
'use strict'; | |
function Youtube( args ) { | |
// enforces new | |
if (!(this instanceof Youtube)) { | |
return new Youtube( args ); | |
} | |
this.settings = { | |
results : 3, | |
userName : "mauriciogarzamorris", | |
dataIds : {}, | |
filter : "id", | |
onComplete : function(){ }, | |
}; | |
this.data = []; | |
$.extend( true, this.settings, args || {} ); | |
var self = this; | |
switch( this.settings.filter || "id" ) { | |
case "id": | |
$.each( this.settings.dataIds, function( index, val ){ | |
$.ajax( { | |
type: "GET", | |
cache: false, | |
dataType: "json", | |
url: "http://gdata.youtube.com/feeds/api/videos/" + val + "?v=2&alt=jsonc", | |
success: function( data ) { | |
self.data.push( data.data ); | |
self.render( index ); | |
} | |
} ); | |
} ); | |
break; | |
case "user": | |
$.ajax( { | |
type: "GET", | |
cache: false, | |
dataType: "json", | |
url: "https://gdata.youtube.com/feeds/api/users/" + this.settings.userName + "/uploads?v=2&alt=jsonc&max-results=" + this.settings.results, | |
success: function( data ) { | |
self.data = data.data.items; | |
self.render(); | |
} | |
} ); | |
break; | |
}; | |
}; | |
/** | |
* Append the items. | |
* | |
* @fires Instagram | |
*/ | |
Youtube.prototype.render = function() { | |
this.settings.onComplete(); | |
console.log(this.data) | |
}; | |
return Youtube; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment