forked from github-tools/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.js.html
More file actions
228 lines (188 loc) · 17.1 KB
/
User.js.html
File metadata and controls
228 lines (188 loc) · 17.1 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>User.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Gist.html">Gist</a><ul class='methods'><li data-type='method'><a href="Gist.html#create">create</a></li><li data-type='method'><a href="Gist.html#createComment">createComment</a></li><li data-type='method'><a href="Gist.html#delete">delete</a></li><li data-type='method'><a href="Gist.html#deleteComment">deleteComment</a></li><li data-type='method'><a href="Gist.html#editComment">editComment</a></li><li data-type='method'><a href="Gist.html#fork">fork</a></li><li data-type='method'><a href="Gist.html#getComment">getComment</a></li><li data-type='method'><a href="Gist.html#isStarred">isStarred</a></li><li data-type='method'><a href="Gist.html#listComments">listComments</a></li><li data-type='method'><a href="Gist.html#read">read</a></li><li data-type='method'><a href="Gist.html#star">star</a></li><li data-type='method'><a href="Gist.html#unstar">unstar</a></li><li data-type='method'><a href="Gist.html#update">update</a></li></ul></li><li><a href="GitHub.html">GitHub</a><ul class='methods'><li data-type='method'><a href="GitHub.html#_getFullName">_getFullName</a></li><li data-type='method'><a href="GitHub.html#getGist">getGist</a></li><li data-type='method'><a href="GitHub.html#getIssues">getIssues</a></li><li data-type='method'><a href="GitHub.html#getMarkdown">getMarkdown</a></li><li data-type='method'><a href="GitHub.html#getOrganization">getOrganization</a></li><li data-type='method'><a href="GitHub.html#getRateLimit">getRateLimit</a></li><li data-type='method'><a href="GitHub.html#getRepo">getRepo</a></li><li data-type='method'><a href="GitHub.html#getTeam">getTeam</a></li><li data-type='method'><a href="GitHub.html#getUser">getUser</a></li><li data-type='method'><a href="GitHub.html#search">search</a></li></ul></li><li><a href="Issue.html">Issue</a><ul class='methods'><li data-type='method'><a href="Issue.html#createIssue">createIssue</a></li><li data-type='method'><a href="Issue.html#createIssueComment">createIssueComment</a></li><li data-type='method'><a href="Issue.html#createMilestone">createMilestone</a></li><li data-type='method'><a href="Issue.html#deleteIssueComment">deleteIssueComment</a></li><li data-type='method'><a href="Issue.html#deleteMilestone">deleteMilestone</a></li><li data-type='method'><a href="Issue.html#editIssue">editIssue</a></li><li data-type='method'><a href="Issue.html#editIssueComment">editIssueComment</a></li><li data-type='method'><a href="Issue.html#editMilestone">editMilestone</a></li><li data-type='method'><a href="Issue.html#getIssue">getIssue</a></li><li data-type='method'><a href="Issue.html#getIssueComment">getIssueComment</a></li><li data-type='method'><a href="Issue.html#getMilestone">getMilestone</a></li><li data-type='method'><a href="Issue.html#listIssueComments">listIssueComments</a></li><li data-type='method'><a href="Issue.html#listIssueEvents">listIssueEvents</a></li><li data-type='method'><a href="Issue.html#listIssues">listIssues</a></li><li data-type='method'><a href="Issue.html#listMilestones">listMilestones</a></li></ul></li><li><a href="Markdown.html">Markdown</a><ul class='methods'><li data-type='method'><a href="Markdown.html#render">render</a></li></ul></li><li><a href="Organization.html">Organization</a><ul class='methods'><li data-type='method'><a href="Organization.html#createRepo">createRepo</a></li><li data-type='method'><a href="Organization.html#createTeam">createTeam</a></li><li data-type='method'><a href="Organization.html#getRepos">getRepos</a></li><li data-type='method'><a href="Organization.html#getTeams">getTeams</a></li><li data-type='method'><a href="Organization.html#isMember">isMember</a></li><li data-type='method'><a href="Organization.html#listMembers">listMembers</a></li></ul></li><li><a href="RateLimit.html">RateLimit</a><ul class='methods'><li data-type='method'><a href="RateLimit.html#getRateLimit">getRateLimit</a></li></ul></li><li><a href="Repository.html">Repository</a><ul class='methods'><li data-type='method'><a href="Repository.html#_getContentObject">_getContentObject</a></li><li data-type='method'><a href="Repository.html#commit">commit</a></li><li data-type='method'><a href="Repository.html#compareBranches">compareBranches</a></li><li data-type='method'><a href="Repository.html#createBlob">createBlob</a></li><li data-type='method'><a href="Repository.html#createBranch">createBranch</a></li><li data-type='method'><a href="Repository.html#createHook">createHook</a></li><li data-type='method'><a href="Repository.html#createPullRequest">createPullRequest</a></li><li data-type='method'><a href="Repository.html#createRef">createRef</a></li><li data-type='method'><a href="Repository.html#createRelease">createRelease</a></li><li data-type='method'><a href="Repository.html#createTree">createTree</a></li><li data-type='method'><a href="Repository.html#deleteFile">deleteFile</a></li><li data-type='method'><a href="Repository.html#deleteHook">deleteHook</a></li><li data-type='method'><a href="Repository.html#deleteRef">deleteRef</a></li><li data-type='method'><a href="Repository.html#deleteRelease">deleteRelease</a></li><li data-type='method'><a href="Repository.html#deleteRepo">deleteRepo</a></li><li data-type='method'><a href="Repository.html#fork">fork</a></li><li data-type='method'><a href="Repository.html#getBlob">getBlob</a></li><li data-type='method'><a href="Repository.html#getCollaborators">getCollaborators</a></li><li data-type='method'><a href="Repository.html#getCommit">getCommit</a></li><li data-type='method'><a href="Repository.html#getContents">getContents</a></li><li data-type='method'><a href="Repository.html#getContributors">getContributors</a></li><li data-type='method'><a href="Repository.html#getDetails">getDetails</a></li><li data-type='method'><a href="Repository.html#getHook">getHook</a></li><li data-type='method'><a href="Repository.html#getPullRequest">getPullRequest</a></li><li data-type='method'><a href="Repository.html#getRef">getRef</a></li><li data-type='method'><a href="Repository.html#getRelease">getRelease</a></li><li data-type='method'><a href="Repository.html#getSha">getSha</a></li><li data-type='method'><a href="Repository.html#getSingleCommit">getSingleCommit</a></li><li data-type='method'><a href="Repository.html#getTree">getTree</a></li><li data-type='method'><a href="Repository.html#isCollaborator">isCollaborator</a></li><li data-type='method'><a href="Repository.html#isStarred">isStarred</a></li><li data-type='method'><a href="Repository.html#listBranches">listBranches</a></li><li data-type='method'><a href="Repository.html#listCommits">listCommits</a></li><li data-type='method'><a href="Repository.html#listForks">listForks</a></li><li data-type='method'><a href="Repository.html#listHooks">listHooks</a></li><li data-type='method'><a href="Repository.html#listPullRequests">listPullRequests</a></li><li data-type='method'><a href="Repository.html#listReleases">listReleases</a></li><li data-type='method'><a href="Repository.html#listStatuses">listStatuses</a></li><li data-type='method'><a href="Repository.html#listTags">listTags</a></li><li data-type='method'><a href="Repository.html#move">move</a></li><li data-type='method'><a href="Repository.html#star">star</a></li><li data-type='method'><a href="Repository.html#unstar">unstar</a></li><li data-type='method'><a href="Repository.html#updateHead">updateHead</a></li><li data-type='method'><a href="Repository.html#updateHook">updateHook</a></li><li data-type='method'><a href="Repository.html#updateRelease">updateRelease</a></li><li data-type='method'><a href="Repository.html#updateTree">updateTree</a></li><li data-type='method'><a href="Repository.html#writeFile">writeFile</a></li></ul></li><li><a href="Requestable.html">Requestable</a><ul class='methods'><li data-type='method'><a href="Requestable.html#_dateToISO">_dateToISO</a></li><li data-type='method'><a href="Requestable.html#_getOptionsWithDefaults">_getOptionsWithDefaults</a></li><li data-type='method'><a href="Requestable.html#_request">_request</a></li><li data-type='method'><a href="Requestable.html#_request204or404">_request204or404</a></li><li data-type='method'><a href="Requestable.html#_requestAllPages">_requestAllPages</a></li></ul></li><li><a href="ResponseError.html">ResponseError</a></li><li><a href="Search.html">Search</a><ul class='methods'><li data-type='method'><a href="Search.html#forCode">forCode</a></li><li data-type='method'><a href="Search.html#forIssues">forIssues</a></li><li data-type='method'><a href="Search.html#forRepositories">forRepositories</a></li><li data-type='method'><a href="Search.html#forUsers">forUsers</a></li></ul></li><li><a href="Team.html">Team</a><ul class='methods'><li data-type='method'><a href="Team.html#addMembership">addMembership</a></li><li data-type='method'><a href="Team.html#deleteTeam">deleteTeam</a></li><li data-type='method'><a href="Team.html#editTeam">editTeam</a></li><li data-type='method'><a href="Team.html#getMembership">getMembership</a></li><li data-type='method'><a href="Team.html#getTeam">getTeam</a></li><li data-type='method'><a href="Team.html#isManagedRepo">isManagedRepo</a></li><li data-type='method'><a href="Team.html#listMembers">listMembers</a></li><li data-type='method'><a href="Team.html#listRepos">listRepos</a></li><li data-type='method'><a href="Team.html#manageRepo">manageRepo</a></li><li data-type='method'><a href="Team.html#unmanageRepo">unmanageRepo</a></li></ul></li><li><a href="User.html">User</a><ul class='methods'><li data-type='method'><a href="User.html#createRepo">createRepo</a></li><li data-type='method'><a href="User.html#follow">follow</a></li><li data-type='method'><a href="User.html#getProfile">getProfile</a></li><li data-type='method'><a href="User.html#listGists">listGists</a></li><li data-type='method'><a href="User.html#listNotifications">listNotifications</a></li><li data-type='method'><a href="User.html#listOrgs">listOrgs</a></li><li data-type='method'><a href="User.html#listRepos">listRepos</a></li><li data-type='method'><a href="User.html#listStarredRepos">listStarredRepos</a></li><li data-type='method'><a href="User.html#unfollow">unfollow</a></li></ul></li></ul>
</nav>
<div id="main">
<h1 class="page-title">User.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @file
* @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.
* @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
* Github.js is freely distributable.
*/
import Requestable from './Requestable';
import debug from 'debug';
const log = debug('github:user');
/**
* A User allows scoping of API requests to a particular Github user.
*/
class User extends Requestable {
/**
* Create a User.
* @param {string} [username] - the user to use for user-scoped queries
* @param {Requestable.auth} [auth] - information required to authenticate to Github
* @param {string} [apiBase=https://api.github.com] - the base Github API URL
*/
constructor(username, auth, apiBase) {
super(auth, apiBase);
this.__user = username;
}
/**
* Get the url for the request. (dependent on if we're requesting for the authenticated user or not)
* @private
* @param {string} endpoint - the endpoint being requested
* @return {string} - the resolved endpoint
*/
__getScopedUrl(endpoint) {
if (this.__user) {
return endpoint ?
`/users/${this.__user}/${endpoint}` :
`/users/${this.__user}`
;
} else { // eslint-disable-line
switch (endpoint) {
case '':
return '/user';
case 'notifications':
case 'gists':
return `/${endpoint}`;
default:
return `/user/${endpoint}`;
}
}
}
/**
* List the user's repositories
* @see https://developer.github.com/v3/repos/#list-user-repositories
* @param {Object} [options={}] - any options to refine the search
* @param {Requestable.callback} [cb] - will receive the list of repositories
* @return {Promise} - the promise for the http request
*/
listRepos(options, cb) {
if (typeof options === 'function') {
cb = options;
options = {};
}
options = this._getOptionsWithDefaults(options);
log(`Fetching repositories with options: ${JSON.stringify(options)}`);
return this._requestAllPages(this.__getScopedUrl('repos'), options, cb);
}
/**
* List the orgs that the user belongs to
* @see https://developer.github.com/v3/orgs/#list-user-organizations
* @param {Requestable.callback} [cb] - will receive the list of organizations
* @return {Promise} - the promise for the http request
*/
listOrgs(cb) {
return this._request('GET', this.__getScopedUrl('orgs'), null, cb);
}
/**
* List the user's gists
* @see https://developer.github.com/v3/gists/#list-a-users-gists
* @param {Requestable.callback} [cb] - will receive the list of gists
* @return {Promise} - the promise for the http request
*/
listGists(cb) {
return this._request('GET', this.__getScopedUrl('gists'), null, cb);
}
/**
* List the user's notifications
* @see https://developer.github.com/v3/activity/notifications/#list-your-notifications
* @param {Object} [options={}] - any options to refine the search
* @param {Requestable.callback} [cb] - will receive the list of repositories
* @return {Promise} - the promise for the http request
*/
listNotifications(options, cb) {
options = options || {};
if (typeof options === 'function') {
cb = options;
options = {};
}
options.since = this._dateToISO(options.since);
options.before = this._dateToISO(options.before);
return this._request('GET', this.__getScopedUrl('notifications'), options, cb);
}
/**
* Show the user's profile
* @see https://developer.github.com/v3/users/#get-a-single-user
* @param {Requestable.callback} [cb] - will receive the user's information
* @return {Promise} - the promise for the http request
*/
getProfile(cb) {
return this._request('GET', this.__getScopedUrl(''), null, cb);
}
/**
* Gets the list of starred repositories for the user
* @see https://developer.github.com/v3/activity/starring/#list-repositories-being-starred
* @param {Requestable.callback} [cb] - will receive the list of starred repositories
* @return {Promise} - the promise for the http request
*/
listStarredRepos(cb) {
let requestOptions = this._getOptionsWithDefaults();
return this._requestAllPages(this.__getScopedUrl('starred'), requestOptions, cb);
}
/**
* Have the authenticated user follow this user
* @see https://developer.github.com/v3/users/followers/#follow-a-user
* @param {string} username - the user to follow
* @param {Requestable.callback} [cb] - will receive true if the request succeeds
* @return {Promise} - the promise for the http request
*/
follow(username, cb) {
return this._request('PUT', `/user/following/${this.__user}`, null, cb);
}
/**
* Have the currently authenticated user unfollow this user
* @see https://developer.github.com/v3/users/followers/#follow-a-user
* @param {string} username - the user to unfollow
* @param {Requestable.callback} [cb] - receives true if the request succeeds
* @return {Promise} - the promise for the http request
*/
unfollow(username, cb) {
return this._request('DELETE', `/user/following/${this.__user}`, null, cb);
}
/**
* Create a new repository for the currently authenticated user
* @see https://developer.github.com/v3/repos/#create
* @param {object} options - the repository definition
* @param {Requestable.callback} [cb] - will receive the API response
* @return {Promise} - the promise for the http request
*/
createRepo(options, cb) {
return this._request('POST', '/user/repos', options, cb);
}
}
module.exports = User;
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Fri May 27 2016 14:42:50 GMT-0500 (CDT) using the Minami theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>