forked from octokit/octokit.js
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgithub.js
More file actions
172 lines (148 loc) · 4.12 KB
/
github.js
File metadata and controls
172 lines (148 loc) · 4.12 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
/**
* Copyright 2010 Ajax.org B.V.
*
* This product includes software developed by
* Ajax.org B.V. (http://www.ajax.org/).
*
* Author: Fabian Jaokbs <fabian@ajax.org>
*/
var Request = require("./github/Request").Request;
/**
* Simple JavaScript GitHub API
*
* Based on the PHP GitHub API project http://github.com/ornicar/php-github-api
*/
var GitHubApi = exports.GitHubApi = function(debug) {
/**
* Use debug mode (prints debug messages)
*/
this.$debug = debug;
/**
* The list of loaded API instances
*/
this.$apis = [];
};
(function() {
/**
* The request instance used to communicate with GitHub
*/
this.$request = null;
/**
* Authenticate a user for all next requests
*
* @param {String} login GitHub username
* @param {String} token GitHub private token
* @return {GitHubApi} fluent interface
*/
this.authenticate = function(login, token)
{
this.getRequest()
.setOption('login', login)
.setOption('token', token);
return this;
};
/**
* Deauthenticate a user for all next requests
*
* @return {GitHubApi} fluent interface
*/
this.deAuthenticate = function() {
return this.authenticate(null, null);
};
/**
* Call any route, GET method
* Ex: api.get('repos/show/my-username/my-repo')
*
* @param {String} route the GitHub route
* @param {Object} parameters GET parameters
* @param {Object} requestOptions reconfigure the request
* @return {Array} data returned
*/
this.get = function(route, parameters, requestOptions, callback) {
return this.getRequest().get(route, parameters || {}, requestOptions, callback);
};
/**
* Call any route, POST method
* Ex: api.post('repos/show/my-username', {'email': 'my-new-email@provider.org'})
*
* @param {String} route the GitHub route
* @param {Object} parameters POST parameters
* @param {Object} requestOptions reconfigure the request
* @return {Array} data returned
*/
this.post = function(route, parameters, requestOptions, callback) {
return this.getRequest().post(route, parameters || {}, requestOptions, callback);
};
/**
* Get the request
*
* @return {Request} a request instance
*/
this.getRequest = function()
{
if(!this.request) {
this.request = new Request({debug: this.debug});
}
return this.request;
};
/**
* Get the user API
*
* @return {UserApi} the user API
*/
this.getUserApi = function()
{
if(!this.$apis['user']) {
this.$apis['user'] = new (require("./github/UserApi").UserApi)(this);
}
return this.$apis['user'];
};
/**
* Get the repo API
*
* @return {RepoApi} the repo API
*/
this.getRepoApi = function()
{
if(!this.$apis['repo']) {
this.$apis['repo'] = new (require("./github/RepoApi").RepoApi)(this);
}
return this.$apis['repo'];
};
/**
* Get the issue API
*
* @return {IssueApi} the issue API
*/
this.getIssueApi = function()
{
if(!this.$apis['issue']) {
this.$apis['issue'] = new (require("./github/IssueApi").IssueApi)(this);
}
return this.$apis['issue'];
};
/**
* Get the object API
*
* @return {ObjectApi} the object API
*/
this.getObjectApi = function()
{
if(!this.$apis['object']) {
this.$apis['object'] = new (require("./github/ObjectApi").ObjectApi)(this);
}
return this.$apis['object'];
};
/**
* Get the commit API
*
* @return {CommitTest} the commit API
*/
this.getCommitApi = function()
{
if(!this.$apis['commit']) {
this.$apis['commit'] = new (require("./github/CommitApi").CommitApi)(this);
}
return this.$apis['commit'];
};
}).call(GitHubApi.prototype);