Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth access token and namespace APIs #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ module.exports = Gitlab;
* @param {Object} options
* - {String} api, api root url, e.g.: 'http://gitlab.com/api/v3'
* - {String} privateToken, You can find or reset your private token in your profile.
* - {String} accessToken, Obtained via OAuth
*/
function Gitlab(options) {
options = options || {};
options.api = options.api || 'https://gitlab.com/api/v3';
RESTFulClient.call(this, options);
this.privateToken = options.privateToken;
this.accessToken = options.accessToken;

this.addResources(resources);

Expand All @@ -45,7 +47,12 @@ function Gitlab(options) {
util.inherits(Gitlab, RESTFulClient);

Gitlab.prototype.setAuthentication = function (req) {
req.params.data.private_token = req.params.data.private_token || this.privateToken;
var accessToken = req.params.data.access_token || this.accessToken;
if (accessToken) {
req.params.data.access_token = accessToken;
} else {
req.params.data.private_token = req.params.data.private_token || this.privateToken;
}
return req;
};

Expand Down
4 changes: 4 additions & 0 deletions lib/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ var properties = {
'transferProject'
],
groupMembers: [],
namespaces: [
'list',
'search',
],
};

for (var key in properties) {
Expand Down
2 changes: 2 additions & 0 deletions lib/resources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ module.exports = {
resourcePath: '/projects/:id/keys',
idName: 'key_id',
},

namespaces: require('./namespace'),
};
33 changes: 33 additions & 0 deletions lib/resources/namespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**!
* gitlab - lib/resources/namespace.js
*
* Copyright(c) repo-utils and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <[email protected]> (http://fengmk2.com)
*/

'use strict';

/**
* Module dependencies.
*/

var util = require('util');
var restful = require('restful-client');

module.exports = Namespace;

function Namespace(client) {
this.constructor.super_.call(this, client, '/namespaces', 'id');
}
util.inherits(Namespace, restful.RESTFulResource);

Namespace.prototype.list = function (params, callback) {
this.client.request('get', '/namespaces', params, callback);
};

Namespace.prototype.search = function (params, callback) {
this.client.request('get', '/namespaces/search/:query', params, callback);
};