This repository was archived by the owner on Dec 26, 2019. It is now read-only.
forked from moul/node-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsers.js
More file actions
151 lines (137 loc) · 3.84 KB
/
Users.js
File metadata and controls
151 lines (137 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
(function() {
var BaseModel, Users,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
BaseModel = require('../BaseModel');
Users = (function(superClass) {
extend(Users, superClass);
function Users() {
this.search = bind(this.search, this);
this.session = bind(this.session, this);
this.create = bind(this.create, this);
this.show = bind(this.show, this);
this.current = bind(this.current, this);
this.all = bind(this.all, this);
this.init = bind(this.init, this);
return Users.__super__.constructor.apply(this, arguments);
}
Users.prototype.init = function() {
return this.keys = this.load('UserKeys');
};
Users.prototype.all = function(params, fn) {
var cb, data;
if (params == null) {
params = {};
}
if (fn == null) {
fn = null;
}
if ('function' === typeof params) {
fn = params;
params = {};
}
this.debug("Users::all()");
if (params.page == null) {
params.page = 1;
}
if (params.per_page == null) {
params.per_page = 100;
}
data = [];
cb = (function(_this) {
return function(err, retData) {
if (err) {
if (fn) {
return fn(retData || data);
}
} else if (retData.length === params.per_page) {
_this.debug("Recurse Users::all()");
data = data.concat(retData);
params.page++;
return _this.get("users", params, cb);
} else {
data = data.concat(retData);
if (fn) {
return fn(data);
}
}
};
})(this);
return this.get("users", params, cb);
};
Users.prototype.current = function(fn) {
if (fn == null) {
fn = null;
}
this.debug("Users::current()");
return this.get("user", function(data) {
if (fn) {
return fn(data);
}
});
};
Users.prototype.show = function(userId, fn) {
if (fn == null) {
fn = null;
}
this.debug("Users::show()");
return this.get("users/" + (parseInt(userId)), (function(_this) {
return function(data) {
if (fn) {
return fn(data);
}
};
})(this));
};
Users.prototype.create = function(params, fn) {
if (params == null) {
params = {};
}
if (fn == null) {
fn = null;
}
this.debug("Users::create()", params);
return this.post("users", params, function(data) {
if (fn) {
return fn(data);
}
});
};
Users.prototype.session = function(email, password, fn) {
var params;
if (fn == null) {
fn = null;
}
this.debug("Users::session()");
params = {
email: email,
password: password
};
return this.post("session", params, function(data) {
if (fn) {
return fn(data);
}
});
};
Users.prototype.search = function(emailOrUsername, fn) {
var params;
if (fn == null) {
fn = null;
}
this.debug("Users::search(" + emailOrUsername + ")");
params = {
search: emailOrUsername
};
return this.get("users", params, function(data) {
if (fn) {
return fn(data);
}
});
};
return Users;
})(BaseModel);
module.exports = function(client) {
return new Users(client);
};
}).call(this);