Created
January 27, 2012 03:58
-
-
Save fleeting/1686893 to your computer and use it in GitHub Desktop.
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
(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