octonode
Advanced tools
Comparing version 0.1.3 to 0.2.0
(function() { | ||
var octonode; | ||
octonode = module.exports = { | ||
@@ -7,6 +8,9 @@ auth: require('./octonode/auth'), | ||
user: require('./octonode/user'), | ||
repository: require('./octonode/repository'), | ||
organization: require('./octonode/organization'), | ||
repo: require('./octonode/repo'), | ||
org: require('./octonode/org'), | ||
team: require('./octonode/team'), | ||
gist: require('./octonode/gist'), | ||
me: require('./octonode/me') | ||
}; | ||
}).call(this); |
(function() { | ||
var auth, qs, request; | ||
request = require('request'); | ||
qs = require('querystring'); | ||
auth = module.exports = { | ||
@@ -13,3 +16,3 @@ modes: { | ||
this.mode = this.modes.cli; | ||
} else if (options.client_id && options.client_secret) { | ||
} else if (options.id && options.secret) { | ||
this.mode = this.modes.web; | ||
@@ -22,11 +25,32 @@ } else { | ||
}, | ||
revoke: function(id, callback) { | ||
if (this.mode === this.modes.cli) { | ||
return request({ | ||
url: "https://" + this.options.username + ":" + this.options.password + "@api.github.com/authorizations/" + id, | ||
method: 'DELETE' | ||
}, function(err, res, body) { | ||
if ((err != null) || res.statusCode !== 204) { | ||
return callback(err || new Error(JSON.parse(body).message)); | ||
} else { | ||
return callback(null); | ||
} | ||
}); | ||
} else { | ||
return callback(new Error('Cannot revoke authorization in web mode')); | ||
} | ||
}, | ||
login: function(scopes, callback) { | ||
var uri; | ||
if (this.mode === this.modes.cli) { | ||
if (scopes instanceof Array) { | ||
scopes = JSON.stringify({ | ||
scopes: scopes | ||
}); | ||
} else { | ||
scopes = JSON.stringify(scopes); | ||
} | ||
return request({ | ||
url: "https://" + this.options.username + ":" + this.options.password + "@api.github.com/authorizations", | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
"scopes": scopes | ||
}), | ||
body: scopes, | ||
headers: { | ||
@@ -36,7 +60,11 @@ 'Content-Type': 'application/json' | ||
}, function(err, res, body) { | ||
body = JSON.parse(body); | ||
try { | ||
body = JSON.parse(body); | ||
} catch (err) { | ||
callback(new Error('Unable to parse body')); | ||
} | ||
if (res.statusCode === 401) { | ||
return callback(err, new Error(body.message)); | ||
return callback(new Error(body.message)); | ||
} else { | ||
return callback(null, body.token); | ||
return callback(null, body.id, body.token); | ||
} | ||
@@ -47,3 +75,3 @@ }); | ||
uri = 'https://github.com/login/oauth/authorize'; | ||
uri += '?client_id=' + this.options.client_id; | ||
uri += '?client_id=' + this.options.id; | ||
return uri += '&scope=' + scopes.join(','); | ||
@@ -56,4 +84,4 @@ } else { | ||
code: scopes, | ||
client_id: this.options.client_id, | ||
client_secret: this.options.client_secret | ||
client_id: this.options.id, | ||
client_secret: this.options.secret | ||
}), | ||
@@ -81,2 +109,3 @@ headers: { | ||
}; | ||
}).call(this); |
(function() { | ||
var Client, Me, Organization, Repository, User, request; | ||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
var Client, Gist, Me, Org, Repo, Team, User, request; | ||
request = require('request'); | ||
Me = require('./me'); | ||
User = require('./user'); | ||
Repository = require('./repository'); | ||
Organization = require('./organization'); | ||
Repo = require('./repo'); | ||
Org = require('./org'); | ||
Gist = require('./gist'); | ||
Team = require('./team'); | ||
Client = (function() { | ||
function Client(token) { | ||
this.token = token; | ||
} | ||
Client.prototype.me = function() { | ||
return new Me(this); | ||
}; | ||
Client.prototype.user = function(name) { | ||
return new User(name, this); | ||
}; | ||
Client.prototype.repository = function(name) { | ||
return new Repository(name, this); | ||
Client.prototype.repo = function(name) { | ||
return new Repo(name, this); | ||
}; | ||
Client.prototype.organization = function(name) { | ||
return new Organization(name, this); | ||
Client.prototype.org = function(name) { | ||
return new Org(name, this); | ||
}; | ||
Client.prototype.gist = function() { | ||
return new Gist(this); | ||
}; | ||
Client.prototype.team = function(id) { | ||
return new Team(id, this); | ||
}; | ||
Client.prototype.query = function(path) { | ||
var uri; | ||
if (path == null) { | ||
path = '/'; | ||
} | ||
if (path[0] !== '/') { | ||
path = '/' + path; | ||
} | ||
uri = "https://api.github.com" + path; | ||
return uri += this.token ? "?access_token=" + this.token : ''; | ||
if (path == null) path = '/'; | ||
if (path[0] !== '/') path = '/' + path; | ||
uri = "https://"; | ||
uri += typeof this.token === 'object' ? "" + this.token.username + ":" + this.token.password + "@" : ''; | ||
uri += "api.github.com" + path; | ||
return uri += typeof this.token === 'string' ? "?access_token=" + this.token : ''; | ||
}; | ||
Client.prototype.errorHandle = function(res, body, callback) { | ||
@@ -46,6 +68,6 @@ var _ref; | ||
} | ||
if (res.statusCode === 422) { | ||
if (body.message && res.statusCode === 422) { | ||
return callback(new Error(body.message)); | ||
} | ||
if ((_ref = res.statusCode) === 400 || _ref === 401 || _ref === 404) { | ||
if (body.message && ((_ref = res.statusCode) === 400 || _ref === 401 || _ref === 404)) { | ||
return callback(new Error(body.message)); | ||
@@ -55,17 +77,22 @@ } | ||
}; | ||
Client.prototype.get = function(path, callback) { | ||
Client.prototype.get = function(path, headers, callback) { | ||
var _this = this; | ||
if (!callback || typeof headers === 'function') { | ||
callback = headers; | ||
headers = {}; | ||
} | ||
return request({ | ||
uri: this.query(path), | ||
method: 'GET' | ||
}, __bind(function(err, res, body) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
return this.errorHandle(res, body, callback); | ||
}, this)); | ||
method: 'GET', | ||
headers: headers | ||
}, function(err, res, body) { | ||
if (err) return callback(err); | ||
return _this.errorHandle(res, body, callback); | ||
}); | ||
}; | ||
Client.prototype.post = function(path, content, callback) { | ||
if (content == null) { | ||
content = {}; | ||
} | ||
var _this = this; | ||
if (content == null) content = {}; | ||
return request({ | ||
@@ -78,13 +105,11 @@ uri: this.query(path), | ||
} | ||
}, __bind(function(err, res, body) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
return this.errorHandle(res, body, callback); | ||
}, this)); | ||
}, function(err, res, body) { | ||
if (err) return callback(err); | ||
return _this.errorHandle(res, body, callback); | ||
}); | ||
}; | ||
Client.prototype.put = function(path, content, callback) { | ||
if (content == null) { | ||
content = {}; | ||
} | ||
var _this = this; | ||
if (content == null) content = {}; | ||
return request({ | ||
@@ -97,13 +122,11 @@ uri: this.query(path), | ||
} | ||
}, __bind(function(err, res, body) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
return this.errorHandle(res, body, callback); | ||
}, this)); | ||
}, function(err, res, body) { | ||
if (err) return callback(err); | ||
return _this.errorHandle(res, body, callback); | ||
}); | ||
}; | ||
Client.prototype.del = function(path, content, callback) { | ||
if (content == null) { | ||
content = {}; | ||
} | ||
var _this = this; | ||
if (content == null) content = {}; | ||
return request({ | ||
@@ -116,12 +139,16 @@ uri: this.query(path), | ||
} | ||
}, __bind(function(err, res, body) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
return this.errorHandle(res, body, callback); | ||
}, this)); | ||
}, function(err, res, body) { | ||
if (err) return callback(err); | ||
return _this.errorHandle(res, body, callback); | ||
}); | ||
}; | ||
return Client; | ||
})(); | ||
module.exports = Client; | ||
module.exports = function(token) { | ||
return new Client(token); | ||
}; | ||
}).call(this); |
(function() { | ||
var Me, User; | ||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
var Me, Org, User; | ||
User = require('./user'); | ||
Org = require('./org'); | ||
Me = (function() { | ||
function Me(client) { | ||
this.client = client; | ||
} | ||
Me.prototype.profile = function(data) { | ||
return Object.keys(data).forEach(__bind(function(e) { | ||
return this[e] = data[e]; | ||
}, this)); | ||
var _this = this; | ||
return Object.keys(data).forEach(function(e) { | ||
return _this[e] = data[e]; | ||
}); | ||
}; | ||
Me.prototype.info = function(cb) { | ||
return this.client.get('/user', function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
@@ -26,7 +31,6 @@ return cb(new Error('User info error')); | ||
}; | ||
Me.prototype.update = function(info, cb) { | ||
return this.client.post('/user', info, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
@@ -39,2 +43,3 @@ return cb(new Error('User update error')); | ||
}; | ||
Me.prototype.emails = function(cbOrEmails, cb) { | ||
@@ -44,8 +49,6 @@ if ((cb != null) && typeof cbOrEmails !== 'function') { | ||
} else if (!(cb != null) && typeof cbOrEmails !== 'function') { | ||
return this.delEmails(cbOrEmails); | ||
return this.deleteEmails(cbOrEmails); | ||
} else { | ||
return this.client.get('/user/emails', function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
@@ -59,7 +62,6 @@ return cb(new Error('User emails error')); | ||
}; | ||
Me.prototype.setEmails = function(emails, cb) { | ||
return this.client.post('/user/emails', emails, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 201) { | ||
@@ -72,19 +74,13 @@ return cb(new Error('User setEmails error')); | ||
}; | ||
Me.prototype.delEmails = function(emails) { | ||
Me.prototype.deleteEmails = function(emails) { | ||
var _this = this; | ||
return this.client.del('/user/emails', emails, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (s !== 204) { | ||
return cb(new Error('User delEmails error')); | ||
} else { | ||
return cb(null, b); | ||
} | ||
if ((err != null) || s !== 204) return _this.deleteEmails(emails); | ||
}); | ||
}; | ||
Me.prototype.followers = function(cb) { | ||
return this.client.get('/user/followers', function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
@@ -97,2 +93,3 @@ return cb(new Error('User followers error')); | ||
}; | ||
Me.prototype.following = function(cbOrUser, cb) { | ||
@@ -103,5 +100,3 @@ if ((cb != null) && typeof cbOrUser !== 'function') { | ||
return this.client.get('/user/following', function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
@@ -115,34 +110,24 @@ return cb(new Error('User following error')); | ||
}; | ||
Me.prototype.checkFollowing = function(cbOrUser, cb) { | ||
return this.client.get("/user/following/" + cbOrUser, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
Me.prototype.checkFollowing = function(user, cb) { | ||
return this.client.get("/user/following/" + user, function(err, s, b) { | ||
if (err) return cb(err); | ||
return cb(null, s === 204); | ||
}); | ||
}; | ||
Me.prototype.follow = function(user) { | ||
var _this = this; | ||
return this.client.put("/user/following/" + user, {}, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (s !== 204) { | ||
return cb(new Error('User follow error')); | ||
} else { | ||
return cb(null, b); | ||
} | ||
if ((err != null) || s !== 204) return _this.follow(user); | ||
}); | ||
}; | ||
Me.prototype.unfollow = function(user) { | ||
var _this = this; | ||
return this.client.del("/user/following/" + user, {}, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (s !== 204) { | ||
return cb(new Error('User unfollow error')); | ||
} else { | ||
return cb(null, b); | ||
} | ||
if ((err != null) || s !== 204) return _this.unfollow(user); | ||
}); | ||
}; | ||
Me.prototype.keys = function(cbOrIdOrKey, cbOrKey, cb) { | ||
@@ -152,3 +137,3 @@ if (!(cb != null) && typeof cbOrIdOrKey === 'number' && typeof cbOrKey === 'function') { | ||
} else if (!(cbOrKey != null) && !(cb != null) && typeof cbOrIdOrKey === 'number') { | ||
return this.delKey(cbOrIdOrKey); | ||
return this.deleteKey(cbOrIdOrKey); | ||
} else if (!(cb != null) && typeof cbOrKey === 'function' && typeof cbOrIdOrKey === 'object') { | ||
@@ -160,5 +145,3 @@ return this.createKey(cbOrIdOrKey, cbOrKey); | ||
return this.client.get('/user/keys', function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
@@ -172,7 +155,6 @@ return cb(new Error('User keys error')); | ||
}; | ||
Me.prototype.getKey = function(id, cb) { | ||
return this.client.get("/user/keys/" + id, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
@@ -185,7 +167,6 @@ return cb(new Error('User getKey error')); | ||
}; | ||
Me.prototype.createKey = function(key, cb) { | ||
return this.client.post('/user/keys', key, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 201) { | ||
@@ -198,7 +179,6 @@ return cb(new Error('User createKey error')); | ||
}; | ||
Me.prototype.updateKey = function(id, key, cb) { | ||
return this.client.post("/user/keys/" + id, key, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
@@ -211,19 +191,32 @@ return cb(new Error('User updateKey error')); | ||
}; | ||
Me.prototype.delKey = function(id) { | ||
return this.client.del("/user/keys/" + id, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (s !== 204) { | ||
return cb(new Error('User delKey error')); | ||
} else { | ||
return cb(null, b); | ||
} | ||
Me.prototype.deleteKey = function(id) { | ||
var _this = this; | ||
return this.client.del("/user/keys/" + id, {}, function(err, s, b) { | ||
if ((err != null) || s !== 204) return _this.deleteKey(id); | ||
}); | ||
}; | ||
Me.prototype.org = function(name) { | ||
return new Org(name, this.client); | ||
}; | ||
Me.prototype.repos = function(cbOrRepo, cb) { | ||
if (typeof cb === 'function' && typeof cbOrRepo === 'object') { | ||
return this.createRepo(cbOrRepo, cb); | ||
} else { | ||
return this.client.get("/user/repos", function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error('User repos error')); | ||
} else { | ||
return cb(null, b); | ||
} | ||
}); | ||
} | ||
}; | ||
Me.prototype.createRepo = function(repo, cb) { | ||
return this.client.post("/user/repos", repo, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 201) { | ||
@@ -236,5 +229,20 @@ return cb(new Error('User createRepo error')); | ||
}; | ||
Me.prototype.fork = function(repo, cb) { | ||
return this.client.post("/repos/" + repo + "/forks", {}, function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 202) { | ||
return cb(new Error('User fork error')); | ||
} else { | ||
return cb(null, b); | ||
} | ||
}); | ||
}; | ||
return Me; | ||
})(); | ||
module.exports = Me; | ||
}).call(this); |
(function() { | ||
var Organization; | ||
Organization = (function() { | ||
function Organization(name, client) { | ||
var Org; | ||
Org = (function() { | ||
function Org(name, client) { | ||
this.name = name; | ||
this.client = client; | ||
} | ||
Organization.prototype.info = function(cb) { | ||
Org.prototype.info = function(cb) { | ||
return this.client.get("/orgs/" + this.name, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error('Org info error')); | ||
} else { | ||
return cb(null, b); | ||
} | ||
}); | ||
}; | ||
Org.prototype.repos = function(cbOrRepo, cb) { | ||
if (typeof cb === 'function' && typeof cbOrRepo === 'object') { | ||
return this.createRepo(cbOrRepo, cb); | ||
} else { | ||
return this.client.get("/orgs/" + this.name + "/repos", function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error('Org repos error')); | ||
} else { | ||
return cb(null, b); | ||
} | ||
}); | ||
} | ||
}; | ||
Org.prototype.createRepo = function(repo, cb) { | ||
return this.client.post("/orgs/" + this.name + "/repos", repo, function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 201) { | ||
return cb(new Error('Org createRepo error')); | ||
} else { | ||
return cb(null, b); | ||
} | ||
}); | ||
}; | ||
Org.prototype.teams = function(cb) { | ||
return this.client.get("/orgs/" + this.name + "/teams", function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error('Organization info error')); | ||
return cb(new Error('Org teams error')); | ||
} else { | ||
@@ -20,5 +58,27 @@ return cb(null, b); | ||
}; | ||
return Organization; | ||
Org.prototype.members = function(cb) { | ||
return this.client.get("/orgs/" + this.name + "/members", function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error('Org members error')); | ||
} else { | ||
return cb(null, b); | ||
} | ||
}); | ||
}; | ||
Org.prototype.member = function(user, cb) { | ||
return this.client.get("/orgs/" + this.name + "/members/" + user, function(err, s, b) { | ||
if (err) return cb(err); | ||
return cb(null, s === 204); | ||
}); | ||
}; | ||
return Org; | ||
})(); | ||
module.exports = Organization; | ||
module.exports = Org; | ||
}).call(this); |
(function() { | ||
var Repository; | ||
Repository = (function() { | ||
function Repository(name, client) { | ||
var Repo; | ||
Repo = (function() { | ||
function Repo(name, client) { | ||
this.name = name; | ||
this.client = client; | ||
} | ||
Repository.prototype._invokeGet = function(path, expectedStatus, methodName, cb) { | ||
if (expectedStatus == null) { | ||
expectedStatus = 200; | ||
} | ||
return this.client.get(path, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
Repo.prototype.info = function(cb) { | ||
return this.client.get("/repos/" + this.name, function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error("Repo info error")); | ||
} else { | ||
return cb(null, b); | ||
} | ||
if (s !== expectedStatus) { | ||
return cb(new Error("Repository." + methodName + " error")); | ||
}); | ||
}; | ||
Repo.prototype.commits = function(cb) { | ||
return this.client.get("/repos/" + this.name + "/commits", function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error("Repo commits error")); | ||
} else { | ||
@@ -23,12 +32,19 @@ return cb(null, b); | ||
}; | ||
Repository.prototype._invokePost = function(path, body, expectedStatus, methodName, cb) { | ||
if (expectedStatus == null) { | ||
expectedStatus = 202; | ||
} | ||
return this.client.post(path, body, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
Repo.prototype.tags = function(cb) { | ||
return this.client.get("/repos/" + this.name + "/tags", function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error("Repo tags error")); | ||
} else { | ||
return cb(null, b); | ||
} | ||
if (s !== expectedStatus) { | ||
return cb(new Error("Repository." + methodName + " error")); | ||
}); | ||
}; | ||
Repo.prototype.languages = function(cb) { | ||
return this.client.get("/repos/" + this.name + "/languages", function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error("Repo languages error")); | ||
} else { | ||
@@ -39,35 +55,77 @@ return cb(null, b); | ||
}; | ||
Repository.prototype.info = function(cb) { | ||
return this._invokeGet("/repos/" + this.name, 200, "info", cb); | ||
Repo.prototype.contributors = function(cb) { | ||
return this.client.get("/repos/" + this.name + "/contributors", function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error("Repo contributors error")); | ||
} else { | ||
return cb(null, b); | ||
} | ||
}); | ||
}; | ||
Repository.prototype.getCommits = function(cb) { | ||
return this._invokeGet("/repos/" + this.name + "/commits", 200, "getCommits", cb); | ||
Repo.prototype.teams = function(cb) { | ||
return this.client.get("/repos/" + this.name + "/teams", function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error("Repo teams error")); | ||
} else { | ||
return cb(null, b); | ||
} | ||
}); | ||
}; | ||
Repository.prototype.getTags = function(cb) { | ||
return this._invokeGet("/repos/" + this.name + "/tags", 200, "getTags", cb); | ||
Repo.prototype.branches = function(cb) { | ||
return this.client.get("/repos/" + this.name + "/branches", function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error("Repo branches error")); | ||
} else { | ||
return cb(null, b); | ||
} | ||
}); | ||
}; | ||
Repository.prototype.getLanguages = function(cb) { | ||
return this._invokeGet("/repos/" + this.name + "/languages", 200, "getLanguages", cb); | ||
Repo.prototype.issues = function(cb) { | ||
return this.client.get("/repos/" + this.name + "/issues", function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error("Repo issues error")); | ||
} else { | ||
return cb(null, b); | ||
} | ||
}); | ||
}; | ||
Repository.prototype.getContributors = function(cb) { | ||
return this._invokeGet("/repos/" + this.name + "/contributors", 200, "getContributors", cb); | ||
Repo.prototype.forks = function(cb) { | ||
return this.client.get("/repos/" + this.name + "/forks", function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error("Repo forks error")); | ||
} else { | ||
return cb(null, b); | ||
} | ||
}); | ||
}; | ||
Repository.prototype.getTeams = function(cb) { | ||
return this._invokeGet("/repos/" + this.name + "/teams", 200, "getTeams", cb); | ||
Repo.prototype.blob = function(sha, cb) { | ||
return this.client.get("/repos/" + this.name + "/git/blobs/" + sha, { | ||
Accept: 'application/vnd.github.raw' | ||
}, function(err, s, b) { | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
return cb(new Error("Repo blob error")); | ||
} else { | ||
return cb(null, b); | ||
} | ||
}); | ||
}; | ||
Repository.prototype.getBranches = function(cb) { | ||
return this._invokeGet("/repos/" + this.name + "/branches", 200, "getBranches", cb); | ||
}; | ||
Repository.prototype.getIssues = function(cb) { | ||
return this._invokeGet("/repos/" + this.name + "/issues", 200, "getIssues", cb); | ||
}; | ||
Repository.prototype.getForks = function(cb) { | ||
return this._invokeGet("/repos/" + this.name + "/forks", 200, "getForks", cb); | ||
}; | ||
Repository.prototype.createFork = function(cb) { | ||
return this._invokePost("/repos/" + this.name + "/forks", {}, 202, "createFork", cb); | ||
}; | ||
return Repository; | ||
return Repo; | ||
})(); | ||
module.exports = Repository; | ||
module.exports = Repo; | ||
}).call(this); |
(function() { | ||
var User; | ||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
User = (function() { | ||
function User(login, client) { | ||
@@ -9,12 +10,13 @@ this.login = login; | ||
} | ||
User.prototype.profile = function(data) { | ||
return Object.keys(data).forEach(__bind(function(e) { | ||
return this[e] = data[e]; | ||
}, this)); | ||
var _this = this; | ||
return Object.keys(data).forEach(function(e) { | ||
return _this[e] = data[e]; | ||
}); | ||
}; | ||
User.prototype.info = function(cb) { | ||
return this.client.get("/users/" + this.login, function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
@@ -27,7 +29,6 @@ return cb(new Error('User info error')); | ||
}; | ||
User.prototype.followers = function(cb) { | ||
return this.client.get("/users/" + this.login + "/followers", function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
@@ -40,7 +41,6 @@ return cb(new Error('User followers error')); | ||
}; | ||
User.prototype.following = function(cb) { | ||
return this.client.get("/users/" + this.login + "/following", function(err, s, b) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (err) return cb(err); | ||
if (s !== 200) { | ||
@@ -53,5 +53,9 @@ return cb(new Error('User following error')); | ||
}; | ||
return User; | ||
})(); | ||
module.exports = User; | ||
}).call(this); |
{ | ||
"name": "octonode", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"author": "Pavan Kumar Sunkara <pavan.sss1991@gmail.com> (http://pksunkara.github.com)", | ||
@@ -5,0 +5,0 @@ "description": "nodejs wrapper for github v3 api", |
334
README.md
@@ -17,6 +17,8 @@ # octonode | ||
var ghme = client.me(); | ||
var ghuser = client.user('pkumar'); | ||
var ghrepo = client.repository('pkumar/hub'); | ||
var ghorg = client.organization('flatiron'); | ||
var ghme = client.me(); | ||
var ghuser = client.user('pksunkara'); | ||
var ghrepo = client.repo('pksunkara/hub'); | ||
var ghorg = client.org('flatiron'); | ||
var ghgist = client.gist(); | ||
var ghteam = client.team(37); | ||
``` | ||
@@ -32,9 +34,20 @@ | ||
github.auth.config({ | ||
username: 'pkumar', | ||
username: 'pksunkara', | ||
password: 'password' | ||
}).login(['user', 'repo', 'gist'], function (err, token) { | ||
console.log(token); | ||
}).login(['user', 'repo', 'gist'], function (err, id, token) { | ||
console.log(id, token); | ||
}); | ||
``` | ||
### Revoke authentication to github in cli mode (desktop application) | ||
```js | ||
github.auth.config({ | ||
username: 'pksunkara', | ||
password: 'password' | ||
}).revoke(id, function (err) { | ||
if (err) throw err; | ||
}); | ||
``` | ||
### Authenticate to github in web mode (web application) | ||
@@ -44,10 +57,11 @@ | ||
// Web application which authenticates to github | ||
var http = require('http'); | ||
var url = require('url'); | ||
var qs = require('querystring'); | ||
var http = require('http') | ||
, url = require('url') | ||
, qs = require('querystring') | ||
, github = require('octonode'); | ||
// Build the authorization config and url | ||
var auth_url = github.auth.config({ | ||
client_id: 'mygithubclientid', | ||
client_secret: 'mygithubclientsecret' | ||
id: 'mygithubclientid', | ||
secret: 'mygithubclientsecret' | ||
}).login(['user', 'repo', 'gist']); | ||
@@ -59,3 +73,3 @@ | ||
// Redirect to github login | ||
if (uri.pathname=='/') { | ||
if (uri.pathname=='/login') { | ||
res.writeHead(301, {'Content-Type': 'text/plain', 'Location': auth_url}) | ||
@@ -83,5 +97,5 @@ res.end('Redirecting to ' + auth_url); | ||
```js | ||
var client = new github.client(); | ||
var client = github.client(); | ||
client.get('/users/pkumar', function (err, status, body) { | ||
client.get('/users/pksunkara', function (err, status, body) { | ||
console.log(body); //json object | ||
@@ -94,3 +108,3 @@ }); | ||
```js | ||
var client = new github.client('someaccesstoken'); | ||
var client = github.client('someaccesstoken'); | ||
@@ -102,4 +116,17 @@ client.get('/user', function (err, status, body) { | ||
## Github authenticated user api | ||
### Build a client from credentials | ||
```js | ||
var client = github.client({ | ||
username: 'pksunkara', | ||
password: 'password' | ||
}); | ||
client.get('/user', function (err, status, body) { | ||
console.log(body); //json object | ||
}); | ||
``` | ||
## API Callback Structure | ||
__All the callbacks for the following will take first an error argument, then a data argument, like this:__ | ||
@@ -114,4 +141,6 @@ | ||
Token required for the following: | ||
## Github authenticated user api | ||
Token/Credentials required for the following: | ||
### Get information about the user (GET /user) | ||
@@ -129,7 +158,2 @@ | ||
"email": "octocat@github.com", | ||
"blog": "https://github.com/blog", | ||
"company": "GitHub", | ||
"location": "San Francisco", | ||
"hireable": true, | ||
"bio": "There once..." | ||
}, callback); | ||
@@ -218,2 +242,23 @@ ``` | ||
### List your repositories (GET /user/repos) | ||
```js | ||
ghme.repos(callback); //array of repos | ||
``` | ||
### Create a repository (POST /user/respos) | ||
```js | ||
ghme.repos({ | ||
"name": "Hello-World", | ||
"description": "This is your first repo", | ||
}, callback); //repo | ||
``` | ||
### Fork a repository (POST /repos/pksunkara/hub/forks) | ||
```js | ||
ghme.fork('pksunkara/hub', callback); //forked repo | ||
``` | ||
## Github users api | ||
@@ -223,3 +268,3 @@ | ||
### Get information about an user (GET /users/pkumar) | ||
### Get information about an user (GET /users/pksunkara) | ||
@@ -230,3 +275,3 @@ ```js | ||
### Get an user followers (GET /users/pkumar/followers) | ||
### Get an user followers (GET /users/pksunkara/followers) | ||
@@ -237,3 +282,3 @@ ```js | ||
### Get an user followings (GET /users/pkumar/following) | ||
### Get an user followings (GET /users/pksunkara/following) | ||
@@ -246,6 +291,4 @@ ```js | ||
No token required for the following | ||
### Get information about a repository (GET /repos/pksunkara/octonode) | ||
### Get information about a repository (/repos/pkumar/octonode) | ||
```js | ||
@@ -255,14 +298,218 @@ ghrepo.info(callback); //json | ||
## Github organizations api | ||
### Get the commits for a repository (GET /repos/pkumar/hub/commits) | ||
No token required for the following | ||
```js | ||
ghrepo.commits(callback); //array of commits | ||
``` | ||
### Get information about an organization (/orgs/flatiron) | ||
### Get the tags for a repository (GET /repos/pksunkara/hub/tags) | ||
```js | ||
ghrepo.tags(callback); //array of tags | ||
``` | ||
### Get the languages for a repository (GET /repos/pksunkara/hub/languages) | ||
```js | ||
ghrepo.languages(callback); //array of languages | ||
``` | ||
### Get the contributors for a repository (GET /repos/pksunkara/hub/contributors) | ||
```js | ||
ghrepo.contributors(callback); //array of github users | ||
``` | ||
### Get the branches for a repository (GET /repos/pksunkara/hub/branches) | ||
```js | ||
ghrepo.branches(callback); //array of branches | ||
``` | ||
### Get the issues for a repository (GET /repos/pksunkara/hub/issues) | ||
```js | ||
ghrepo.issues(callback); //array of issues | ||
``` | ||
### Get the blob for a repository (GET /repos/pksunkara/hub/git/blobs/SHA) | ||
```js | ||
ghrepo.blob('18293abcd72', callback); //blob | ||
``` | ||
### Get the teams for a repository (GET /repos/pksunkara/hub/teams) | ||
```js | ||
ghrepo.teams(callback); //array of teams | ||
``` | ||
## Github organizations api | ||
### Get information about an organization (GET /orgs/flatiron) | ||
```js | ||
ghorg.info(callback); //json | ||
``` | ||
If you like this project, please watch this and follow me. | ||
### List organization repositories (GET /orgs/flatiron/repos) | ||
```js | ||
ghorg.repos(callback); //array of repos | ||
``` | ||
### Create an organization repository (POST /orgs/flatiron/repos) | ||
```js | ||
ghorg.repos({ | ||
name: 'Hello-world', | ||
description: 'My first world program' | ||
}, callback); //repo | ||
``` | ||
### Get an organization's teams (GET /orgs/flatiron/teams) | ||
```js | ||
ghorg.teams(callback); //array of teams | ||
``` | ||
### Get an organization's members (GET /orgs/flatiron/members) | ||
```js | ||
ghorg.members(callback); //array of github users | ||
``` | ||
### Check an organization member (GET /orgs/flatiron/members/pksunkara) | ||
```js | ||
ghorg.member('pksunkara', callback); //boolean | ||
``` | ||
## Github gists api | ||
### List authenticated user's gists (GET /gists) | ||
```js | ||
ghgist.list(callback); //array of gists | ||
``` | ||
### List authenticated user's public gists (GET /gists/public) | ||
```js | ||
ghgist.public(callback); //array of gists | ||
``` | ||
### List authenticated user's starred gists (GET /gists/starred) | ||
```js | ||
ghgist.starred(callback); //array of gists | ||
``` | ||
### List a user's public gists (GET /users/pksunkara/gists) | ||
```js | ||
ghgist.user('pksunkara', callback); //array of gists | ||
``` | ||
### Get a single gist (GET /gists/37) | ||
```js | ||
ghgist.get(37, callback); //gist | ||
```js | ||
### Create a gist (POST /gists) | ||
```js | ||
ghgist.create({ | ||
description: "the description", | ||
files: { ... } | ||
}), callback); //gist | ||
```js | ||
### Edit a gist (PATCH /gists/37) | ||
```js | ||
ghgist.edit(37, { | ||
description: "hello gist" | ||
}, callback); //gist | ||
```js | ||
### Delete a gist (DELETE /gists/37) | ||
```js | ||
ghgist.delete(37); | ||
```js | ||
### Star a gist (PUT /gists/37/star) | ||
```js | ||
ghgist.star(37); | ||
```js | ||
### Unstar a gist (DELETE /gists/37/unstar) | ||
```js | ||
ghgist.unstar(37); | ||
```js | ||
### Check if a gist is starred (GET /gists/37/star) | ||
```js | ||
ghgist.check(37); //boolean | ||
```js | ||
### List comments on a gist (GET /gists/37/comments) | ||
```js | ||
ghgist.comments(37, callback); //array of comments | ||
```js | ||
### Create a comment (POST /gists/37/comments) | ||
```js | ||
ghgist.comments(37, { | ||
body: "Just commenting" | ||
}, callback); //comment | ||
```js | ||
### Get a single comment (GET /gists/comments/1) | ||
```js | ||
ghgist.comment(1, callback); //comment | ||
```js | ||
### Edit a comment (POST /gists/comments/1) | ||
```js | ||
ghgist.comment(1, { | ||
body: "lol at commenting" | ||
}, callback); //comment | ||
```js | ||
### Delete a comment (DELETE /gists/comments/1) | ||
```js | ||
ghgist.comment(1); | ||
```js | ||
## Github teams api | ||
### Get a team (GET /team/37) | ||
```js | ||
ghteam.info(callback); //json | ||
``` | ||
### Get the team members (GET /team/37/members) | ||
```js | ||
ghteam.members(callback); //array of github users | ||
``` | ||
### Check if a user is part of the team (GET /team/37/members/pksunkara) | ||
```js | ||
ghteam.member('pksunkara'); //boolean | ||
``` | ||
## Testing | ||
@@ -273,2 +520,4 @@ ``` | ||
If you like this project, please watch this and follow me. | ||
## Contributors | ||
@@ -279,2 +528,4 @@ Here is a list of [Contributors](http://github.com/pksunkara/octonode/contributors) | ||
The following method names use underscore as an example. The library contains camel cased method names. | ||
```js | ||
@@ -285,4 +536,2 @@ // public orgs for unauthenticated, private and public for authenticated | ||
// public repos for unauthenticated, private and public for authenticated | ||
me.get_repositories(callback); | ||
me.create_repository({name: ''}, callback); | ||
me.get_watched_repositories(callback); | ||
@@ -298,4 +547,2 @@ me.is_watching('repo', callback); | ||
org.update(dict_with_update_properties, callback); | ||
org.get_members(callback); | ||
org.get_member('user', callback); | ||
org.add_member('user', 'team', callback); | ||
@@ -307,3 +554,3 @@ org.remove_member('user', callback); | ||
org.conceal_member('user', callback); | ||
org.get_teams(callback); | ||
org.get_team('team', callback); | ||
@@ -326,7 +573,2 @@ org.create_team({name:'', repo_names:'', permission:''}, callback); | ||
repo.update({name: ''}, callback); | ||
repo.get_contributors(callback); | ||
repo.get_languages(callback); | ||
repo.get_teams(callback); | ||
repo.get_tags(callback); | ||
repo.get_branches(callback); | ||
@@ -340,3 +582,2 @@ // collaborator information | ||
// commit data | ||
repo.get_commits(callback); | ||
repo.get_commit('sha-id', callback); | ||
@@ -356,6 +597,2 @@ repo.get_all_comments(callback); | ||
// fork data | ||
repo.get_forks(callback); | ||
repo.create_fork(callback); | ||
// keys | ||
@@ -408,3 +645,2 @@ repo.get_deploy_keys(callback); | ||
// raw git access | ||
repo.get_blob('sha-id', callback); | ||
repo.create_blob('content', 'encoding', callback); | ||
@@ -411,0 +647,0 @@ repo.get_commit('sha-id', callback); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
45373
14
879
643
1