Created
November 4, 2011 15:15
-
-
Save davetayls/1339553 to your computer and use it in GitHub Desktop.
Twitter AMD Module
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
/** | |
* Twitter AMD Module | |
*/ | |
/*jslint browser: true, vars: true, white: true, forin: true, indent: 4 */ | |
/*global define,require */ | |
define( | |
['jquery/core'], | |
function($){ | |
'use strict'; | |
var TWITTER_API = 'https://api.twitter.com', | |
twitterRegEx = /twitter\.com\/#?!?([A-Za-z0-9_]+)[\/]?([A-Za-z0-9_]*)/ | |
; | |
return { | |
getTwitterDetails: function(twitterUrl) { | |
var matches = twitterRegEx.exec(twitterUrl); | |
if (matches){ | |
return { | |
url: twitterUrl, | |
username: matches[1], | |
list: matches[2] | |
}; | |
} | |
}, | |
loadTwitterFollower: function(id, callback) { | |
$.getJSON(TWITTER_API + '/1/users/lookup.json?cursor=-1&user_id=' + id + '&callback=?', function(data, status){ | |
callback.apply(this, arguments); | |
}); | |
}, | |
loadTwitterFollowers: function(screenname, callback) { | |
var self = this; | |
$.getJSON(TWITTER_API + '/1/followers/ids.json?cursor=-1&screen_name=' + screenname + '&callback=?', function(data, status){ | |
self.loadTwitterFollower(data.ids.slice(0,20).join(','), function(data, status){ | |
callback.apply(self, arguments); | |
}); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment