@@ -2,32 +2,25 @@ part of github.common;
2
2
3
3
typedef http.Client ClientCreator ();
4
4
5
- /**
6
- * The Main GitHub Client
7
- *
8
- * ## Example
9
- *
10
- * var github = new GitHub(auth: new Authentication.withToken("SomeToken"));
11
- * // Use the Client
12
- */
5
+ /// The Main GitHub Client
6
+ ///
7
+ /// ## Example
8
+ ///
9
+ /// var github = new GitHub(auth: new Authentication.withToken("SomeToken"));
10
+ /// // Use the Client
11
+ ///
13
12
class GitHub {
14
13
static const _ratelimitLimitHeader = 'x-ratelimit-limit' ;
15
14
static const _ratelimitResetHeader = 'x-ratelimit-reset' ;
16
15
static const _ratelimitRemainingHeader = 'x-ratelimit-remaining' ;
17
16
18
- /**
19
- * Authentication Information
20
- */
17
+ /// Authentication Information
21
18
Authentication auth;
22
19
23
- /**
24
- * API Endpoint
25
- */
20
+ /// API Endpoint
26
21
final String endpoint;
27
22
28
- /**
29
- * HTTP Client
30
- */
23
+ /// HTTP Client
31
24
final http.Client client;
32
25
33
26
ActivityService _activity;
@@ -45,6 +38,17 @@ class GitHub {
45
38
UrlShortenerService _urlShortener;
46
39
UsersService _users;
47
40
41
+ /// Creates a new [GitHub] instance.
42
+ ///
43
+ /// [endpoint] is the api endpoint to use
44
+ /// [auth] is the authentication information
45
+ GitHub (
46
+ {Authentication auth,
47
+ this .endpoint: "https://api.github.com" ,
48
+ http.Client client})
49
+ : this .auth = auth == null ? new Authentication .anonymous () : auth,
50
+ this .client = client == null ? new http.Client () : client;
51
+
48
52
/// The maximum number of requests that the consumer is permitted to make per
49
53
/// hour.
50
54
///
@@ -72,20 +76,6 @@ class GitHub {
72
76
73
77
int _rateLimitReset, _rateLimitLimit, _rateLimitRemaining;
74
78
75
- /**
76
- * Creates a new [GitHub] instance.
77
- *
78
- * [fetcher] is the HTTP Transporter to use
79
- * [endpoint] is the api endpoint to use
80
- * [auth] is the authentication information
81
- */
82
- GitHub (
83
- {Authentication auth,
84
- this .endpoint: "https://api.github.com" ,
85
- http.Client client})
86
- : this .auth = auth == null ? new Authentication .anonymous () : auth,
87
- this .client = client == null ? new http.Client () : client;
88
-
89
79
/// Service for activity related methods of the GitHub API.
90
80
ActivityService get activity {
91
81
if (_activity == null ) {
@@ -201,26 +191,19 @@ class GitHub {
201
191
return _users;
202
192
}
203
193
204
- /**
205
- * Handles Get Requests that respond with JSON
206
- *
207
- * [path] can either be a path like '/repos' or a full url.
208
- *
209
- * [statusCode] is the expected status code. If it is null, it is ignored.
210
- * If the status code that the response returns is not the status code you provide
211
- * then the [fail] function will be called with the HTTP Response.
212
- * If you don't throw an error or break out somehow, it will go into some error checking
213
- * that throws exceptions when it finds a 404 or 401. If it doesn't find a general HTTP Status Code
214
- * for errors, it throws an Unknown Error.
215
- *
216
- * [headers] are HTTP Headers. If it doesn't exist, the 'Accept' and 'Authorization' headers are added.
217
- *
218
- * [params] are query string parameters.
219
- *
220
- * [convert] is a simple function that is passed this [GitHub] instance and a JSON object.
221
- * The future will pass the object returned from this function to the then method.
222
- * The default [convert] function returns the input object.
223
- */
194
+ /// Handles Get Requests that respond with JSON
195
+ /// [path] can either be a path like '/repos' or a full url.
196
+ /// [statusCode] is the expected status code. If it is null, it is ignored.
197
+ /// If the status code that the response returns is not the status code you provide
198
+ /// then the [fail] function will be called with the HTTP Response.
199
+ /// If you don't throw an error or break out somehow, it will go into some error checking
200
+ /// that throws exceptions when it finds a 404 or 401. If it doesn't find a general HTTP Status Code
201
+ /// for errors, it throws an Unknown Error.
202
+ /// [headers] are HTTP Headers. If it doesn't exist, the 'Accept' and 'Authorization' headers are added.
203
+ /// [params] are query string parameters.
204
+ /// [convert] is a simple function that is passed this [GitHub] instance and a JSON object.
205
+ /// The future will pass the object returned from this function to the then method.
206
+ /// The default [convert] function returns the input object.
224
207
Future <dynamic > getJSON (String path,
225
208
{int statusCode,
226
209
void fail (http.Response response),
@@ -252,35 +235,31 @@ class GitHub {
252
235
return convert (json);
253
236
}
254
237
255
- /**
256
- * Handles Post Requests that respond with JSON
257
- *
258
- * [path] can either be a path like '/repos' or a full url.
259
- *
260
- * [statusCode] is the expected status code. If it is null, it is ignored.
261
- * If the status code that the response returns is not the status code you provide
262
- * then the [fail] function will be called with the HTTP Response.
263
- * If you don't throw an error or break out somehow, it will go into some error checking
264
- * that throws exceptions when it finds a 404 or 401. If it doesn't find a general HTTP Status Code
265
- * for errors, it throws an Unknown Error.
266
- *
267
- * [headers] are HTTP Headers. If it doesn't exist, the 'Accept' and 'Authorization' headers are added.
268
- *
269
- * [params] are query string parameters.
270
- *
271
- * [convert] is a simple function that is passed this [GitHub] instance and a JSON object.
272
- * The future will pass the object returned from this function to the then method.
273
- * The default [convert] function returns the input object.
274
- *
275
- * [body] is the data to send to the server.
276
- */
238
+ /// Handles Post Requests that respond with JSO
239
+ ///
240
+ /// [path] can either be a path like '/repos' or a full url.
241
+ /// [statusCode] is the expected status code. If it is null, it is ignored.
242
+ /// If the status code that the response returns is not the status code you provide
243
+ /// then the [fail] function will be called with the HTTP Response.
244
+ ///
245
+ /// If you don't throw an error or break out somehow, it will go into some error checking
246
+ /// that throws exceptions when it finds a 404 or 401. If it doesn't find a general HTTP Status Code
247
+ /// for errors, it throws an Unknown Error.
248
+ ///
249
+ /// [headers] are HTTP Headers. If it doesn't exist, the 'Accept' and 'Authorization' headers are added.
250
+ /// [params] are query string parameters.
251
+ /// [convert] is a simple function that is passed this [GitHub] instance and a JSON object.
252
+ ///
253
+ /// The future will pass the object returned from this function to the then method.
254
+ /// The default [convert] function returns the input object.
255
+ /// [body] is the data to send to the server.
277
256
Future <dynamic > postJSON (String path,
278
257
{int statusCode,
279
258
void fail (http.Response response),
280
259
Map <String , String > headers,
281
260
Map <String , String > params,
282
261
JSONConverter convert,
283
- body,
262
+ String body,
284
263
String preview}) async {
285
264
if (headers == null ) headers = {};
286
265
@@ -303,16 +282,16 @@ class GitHub {
303
282
return convert (JSON .decode (response.body));
304
283
}
305
284
306
- /**
307
- * Internal method to handle status codes
308
- * /
285
+ ///
286
+ /// Internal method to handle status codes
287
+ // /
309
288
void handleStatusCode (http.Response response) {
310
289
String message;
311
290
List <Map <String , String >> errors;
312
291
if (response.headers['content-type' ].contains ('application/json' )) {
313
292
var json = JSON .decode (response.body);
314
293
message = json['message' ];
315
- errors = json['errors' ];
294
+ errors = json['errors' ] as List < Map < String , String >> ;
316
295
}
317
296
switch (response.statusCode) {
318
297
case 404 :
@@ -349,15 +328,14 @@ class GitHub {
349
328
throw new UnknownError (this , message);
350
329
}
351
330
352
- /**
353
- * Handles Authenticated Requests in an easy to understand way.
354
- *
355
- * [method] is the HTTP method.
356
- * [path] can either be a path like '/repos' or a full url.
357
- * [headers] are HTTP Headers. If it doesn't exist, the 'Accept' and 'Authorization' headers are added.
358
- * [params] are query string parameters.
359
- * [body] is the body content of requests that take content.
360
- */
331
+ /// Handles Authenticated Requests in an easy to understand way.
332
+ ///
333
+ /// [method] is the HTTP method.
334
+ /// [path] can either be a path like '/repos' or a full url.
335
+ /// [headers] are HTTP Headers. If it doesn't exist, the 'Accept' and 'Authorization' headers are added.
336
+ /// [params] are query string parameters.
337
+ /// [body] is the body content of requests that take content.
338
+ ///
361
339
Future <http.Response > request (String method, String path,
362
340
{Map <String , String > headers,
363
341
Map <String , dynamic > params,
@@ -422,11 +400,8 @@ class GitHub {
422
400
return response;
423
401
}
424
402
425
- /**
426
- * Disposes of this GitHub Instance.
427
- *
428
- * No other methods on this instance should be called after this method is called.
429
- */
403
+ /// Disposes of this GitHub Instance.
404
+ /// No other methods on this instance should be called after this method is called.
430
405
void dispose () {
431
406
// Destroy the Authentication Information
432
407
// This is needed for security reasons.
0 commit comments