Last active
December 15, 2015 17:29
-
-
Save tadev/5296648 to your computer and use it in GitHub Desktop.
github api functions for ircbot ringor in #docker on freenode
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
| /*jslint evil: true, regexp: true */ | |
| // Create a github object only if one does not already exist. | |
| //TODO: Convert to use github's JSONP endpoints so headers are visible to javascript too - http://developer.github.com/v3/#json-p-callbacks | |
| //TODO: Pagination support - http://developer.github.com/v3/#pagination | |
| var github; | |
| if (!github) { github = {}; } | |
| if (!github.users) { github.users = {}; } | |
| if (!github.repos) { github.repos = {}; } | |
| (function () { | |
| 'use strict'; | |
| var api_baseurl = "https://api.github.com/"; | |
| // <-- Globals | |
| github.rateLimitRemaining = -1; | |
| github.rateLimit = -1; | |
| // --> Globals | |
| var callback = function (response) | |
| { | |
| var meta = response.meta; | |
| github.rateLimitRemaining = parseInt(meta.X-RateLimit-Remaining); | |
| github.rateLimit = parseInt(meta.X-RateLimit-Limit); | |
| // links = JSON Array | ["https://api.github.com?page=2", {"rel": "next"}] | |
| var links = new Array; | |
| var links = response.meta.Link; | |
| var data = response.data; | |
| return data; | |
| } | |
| github.get = function(url){ return httpsGetJSON(url); } | |
| github.getPath = function(path){ return httpsGetJSON(api_baseurl + path); } | |
| github.checkRateLimit = function () | |
| { | |
| var _rateLimit = httpsGetJSON(api_baseurl + "/rate_limit"); | |
| github.rateLimitRemaining = _rateLimit.rate.remaining; | |
| github.rateLimit = _rateLimit.rate.limit; | |
| return _rateLimit.rate.remaining; | |
| } | |
| // Repository - /repos/ | |
| // get repository JSON | |
| github.repos.getRepo = function(owner,repo){ return httpsGetJSON(api_baseurl + "repos/" + owner + "/" + repo); } | |
| github.repos.getRepoDescription = function (owner,repo){ return github.repos.getRepo(owner,repo).description; } | |
| // issues | |
| github.repos.getIssues = function(owner, repo){ return httpsGetJSON(api_baseurl + "repos/" + owner + "/" + repo + "/issues"); } | |
| github.repos.getIssue = function(owner, repo, id){ return httpsGetJSON(api_baseurl + "repos/" + owner + "/" + repo + "/issues/" + id); } | |
| // commits | |
| github.repos.getCommits = function(owner, repo){ return httpsGetJSON(api_baseurl + "repos/" + owner + "/" + repo + "/commits"); } | |
| github.repos.getCommit = function(owner, repo, sha){ return httpsGetJSON(api_baseurl + "repos/" + owner + "/" + repo + "/commits/" + sha); } | |
| // stargazers | |
| github.repos.getStargazers = function(owner, repo){ return httpsGetJSON(api_baseurl + "repos/" + owner + "/" + repo + "/stargazers"); } | |
| // contributors | |
| github.repos.getContributors = function(owner, repo){ return httpsGetJSON(api_baseurl + "repos/" + owner + "/" + repo + "/contributors"); } | |
| // Users - /users/ | |
| // get user info JSON | |
| github.users.getUser = function(user){ return httpsGetJSON(api_baseurl + "users/" + user); } | |
| github.users.getUserName = function(user){ return httpsGetJSON(api_baseurl + "users/" + user).name; } // returns string | |
| // gist | |
| github.users.getGists = function(user){ return httpsGetJSON(api_baseurl + "users/" + user + "/gists"); } | |
| github.users.getGist = function(user, id){ return httpsGetJSON(api_baseurl + "users/" + user + "/gists/" + id); } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment