Skip to content

Instantly share code, notes, and snippets.

@fleeting
Created January 27, 2012 03:58
Show Gist options
  • Save fleeting/1686893 to your computer and use it in GitHub Desktop.
Save fleeting/1686893 to your computer and use it in GitHub Desktop.
(function($) {
"use strict";
$.extend({
simpleGithub: function(options){
var options = $.extend({
name: 'jamesfleeting', //username
type: 'user', //Options: user, org, repo (what type of account is `name`)
method: 'repos', //Options: info, repos
option: '', //Options:
success: function(response){},
error: function(message){}
}, options);
if(options.type === 'user' && options.method === 'repos')
var githubUrl = 'https://api.github.com/users/'+options.name+'/repos?callback=?';
$.getJSON(
githubUrl,
function(obj) {
if(obj != null) {
var results = [];
if(options.type === 'user' && options.type === 'user') {
$(obj.data).each(function() {
var result = {
id: this.id,
name: this.name,
url: this.url,
description: this.description,
homepage: this.homepage,
clone_url: this.clone_url,
created_at: this.created_at,
updated_at: this.updated_at,
fork: this.fork,
forks: this.forks,
watchers: this.watchers,
has_downloads: this.has_downloads,
has_issues: this.has_issues,
has_wiki: this.has_wiki,
open_issues: this.open_issues,
html_url: this.html_url,
language: this.language,
master_branch: this.master_branch,
private: this.private,
pushed_at: this.pushed_at,
size: this.size,
git_url: this.git_url,
ssh_url: this.ssh_url,
svn_url: this.svn_url,
mirror_url: this.mirror_url
};
results[results.length] = result;
});
}
console.log(results);
options.success(results);
} else {
options.error("Your GitHub info could not be received. Try again.");
}
}
);
return this;
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment