forked from github-tools/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitHub.js
More file actions
107 lines (94 loc) · 2.93 KB
/
GitHub.js
File metadata and controls
107 lines (94 loc) · 2.93 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
/**
* @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 Gist from './Gist';
import User from './User';
import Issue from './Issue';
import Search from './Search';
import RateLimit from './RateLimit';
import Repository from './Repository';
import Organization from './Organization';
/**
* GitHub encapsulates the functionality to create various API wrapper objects.
*/
class GitHub {
/**
* Create a new GitHub.
* @param {Requestable.auth} [auth] - the credentials to authenticate to Github. If auth is
* not provided requests will be made unauthenticated
* @param {string} [apiBase=https://api.github.com] - the base Github API URL
*/
constructor(auth, apiBase = 'https://api.github.com') {
this.__apiBase = apiBase;
this.__auth = auth || {};
}
/**
* Create a new Gist wrapper
* @param {number} [id] - the id for the gist, leave undefined when creating a new gist
* @return {Gist}
*/
getGist(id) {
return new Gist(id, this.__auth, this.__apiBase);
}
/**
* Create a new User wrapper
* @param {string} [user] - the name of the user to get information about
* leave undefined for the authenticated user
* @return {User}
*/
getUser(user) {
return new User(user, this.__auth, this.__apiBase);
}
/**
* Create a new Organization wrapper
* @param {string} organization - the name of the organization
* @return {Organization}
*/
getOrganization(organization) {
return new Organization(organization, this.__auth, this.__apiBase);
}
/**
* Create a new Repository wrapper
* @param {string} user - the user who owns the respository
* @param {string} repo - the name of the repository
* @return {Repository}
*/
getRepo(user, repo) {
return new Repository(this._getFullName(user, repo), this.__auth, this.__apiBase);
}
/**
* Create a new Issue wrapper
* @param {string} user - the user who owns the respository
* @param {string} repo - the name of the repository
* @return {Issue}
*/
getIssues(user, repo) {
return new Issue(this._getFullName(user, repo), this.__auth, this.__apiBase);
}
/**
* Create a new Search wrapper
* @param {string} query - the query to search for
* @return {Search}
*/
search(query) {
return new Search(query, this.__auth, this.__apiBase);
}
/**
* Create a new RateLimit wrapper
* @return {RateLimit}
*/
getRateLimit() {
return new RateLimit(this.__auth, this.__apiBase);
}
_getFullName(user, repo) {
let fullname = user;
if (repo) {
fullname = `${user}/${repo}`;
}
return fullname;
}
}
module.exports = GitHub;