Skip to content

Commit a76ffe1

Browse files
committed
Fix Strong mode, docs and other fixes
1 parent 1ab836c commit a76ffe1

File tree

2 files changed

+86
-105
lines changed

2 files changed

+86
-105
lines changed

lib/src/common/git_service.dart

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class GitService extends Service {
1212
/// API docs: https://developer.github.com/v3/git/blobs/#get-a-blob
1313
Future<GitBlob> getBlob(RepositorySlug slug, String sha) {
1414
return _github.getJSON('/repos/${slug.fullName}/git/blobs/${sha}',
15-
convert: GitBlob.fromJSON, statusCode: StatusCodes.OK);
15+
convert: GitBlob.fromJSON,
16+
statusCode: StatusCodes.OK) as Future<GitBlob>;
1617
}
1718

1819
/// Creates a blob with specified [blob] content.
@@ -22,15 +23,16 @@ class GitService extends Service {
2223
return _github.postJSON('/repos/${slug.fullName}/git/blobs',
2324
convert: GitBlob.fromJSON,
2425
statusCode: StatusCodes.CREATED,
25-
body: blob.toJSON());
26+
body: blob.toJSON()) as Future<GitBlob>;
2627
}
2728

2829
/// Fetches a commit from [slug] for a given [sha].
2930
///
3031
/// API docs: https://developer.github.com/v3/git/commits/#get-a-commit
3132
Future<GitCommit> getCommit(RepositorySlug slug, String sha) {
3233
return _github.getJSON('/repos/${slug.fullName}/git/commits/${sha}',
33-
convert: GitCommit.fromJSON, statusCode: StatusCodes.OK);
34+
convert: GitCommit.fromJSON,
35+
statusCode: StatusCodes.OK) as Future<GitCommit>;
3436
}
3537

3638
/// Creates a new commit in a repository.
@@ -40,7 +42,7 @@ class GitService extends Service {
4042
return _github.postJSON('/repos/${slug.fullName}/git/commits',
4143
convert: GitCommit.fromJSON,
4244
statusCode: StatusCodes.CREATED,
43-
body: commit.toJSON());
45+
body: commit.toJSON()) as Future<GitCommit>;
4446
}
4547

4648
/// Fetches a reference from a repository for the given [ref].
@@ -50,7 +52,8 @@ class GitService extends Service {
5052
/// API docs: https://developer.github.com/v3/git/refs/#get-a-reference
5153
Future<GitReference> getReference(RepositorySlug slug, String ref) {
5254
return _github.getJSON('/repos/${slug.fullName}/git/refs/${ref}',
53-
convert: GitReference.fromJSON, statusCode: StatusCodes.OK);
55+
convert: GitReference.fromJSON,
56+
statusCode: StatusCodes.OK) as Future<GitReference>;
5457
}
5558

5659
/// Lists the references in a repository.
@@ -67,7 +70,7 @@ class GitService extends Service {
6770
}
6871

6972
return new PaginationHelper(_github)
70-
.objects('GET', path, GitReference.fromJSON);
73+
.objects('GET', path, GitReference.fromJSON) as Stream<GitReference>;
7174
}
7275

7376
/// Creates a new reference in a repository.
@@ -81,7 +84,7 @@ class GitService extends Service {
8184
return _github.postJSON('/repos/${slug.fullName}/git/refs',
8285
convert: GitReference.fromJSON,
8386
statusCode: StatusCodes.CREATED,
84-
body: JSON.encode({'ref': ref, 'sha': sha}));
87+
body: JSON.encode({'ref': ref, 'sha': sha})) as Future<GitReference>;
8588
}
8689

8790
/// Updates a reference in a repository.
@@ -98,7 +101,9 @@ class GitService extends Service {
98101
.request('PATCH', '/repos/${slug.fullName}/git/refs/${ref}',
99102
body: body, headers: headers)
100103
.then((response) {
101-
return GitReference.fromJSON(JSON.decode(response.body));
104+
return GitReference
105+
.fromJSON(JSON.decode(response.body) as Map<String, dynamic>)
106+
as Future<GitReference>;
102107
});
103108
}
104109

@@ -116,7 +121,7 @@ class GitService extends Service {
116121
/// API docs: https://developer.github.com/v3/git/tags/#get-a-tag
117122
Future<GitTag> getTag(RepositorySlug slug, String sha) {
118123
return _github.getJSON('/repos/${slug.fullName}/git/tags/${sha}',
119-
convert: GitTag.fromJSON, statusCode: StatusCodes.OK);
124+
convert: GitTag.fromJSON, statusCode: StatusCodes.OK) as Future<GitTag>;
120125
}
121126

122127
/// Creates a new tag in a repository.
@@ -126,10 +131,10 @@ class GitService extends Service {
126131
return _github.postJSON('/repos/${slug.fullName}/git/tags',
127132
convert: GitTag.fromJSON,
128133
statusCode: StatusCodes.CREATED,
129-
body: tag.toJSON());
134+
body: tag.toJSON()) as Future<GitTag>;
130135
}
131136

132-
/// Fetches a tree from a repository for the given [ref].
137+
/// Fetches a tree from a repository for the given ref [sha].
133138
///
134139
/// If [recursive] is set to true, the tree is fetched recursively.
135140
///
@@ -143,7 +148,8 @@ class GitService extends Service {
143148
}
144149

145150
return _github.getJSON(path,
146-
convert: GitTree.fromJSON, statusCode: StatusCodes.OK);
151+
convert: GitTree.fromJSON,
152+
statusCode: StatusCodes.OK) as Future<GitTree>;
147153
}
148154

149155
/// Creates a new tree in a repository.
@@ -153,6 +159,6 @@ class GitService extends Service {
153159
return _github.postJSON('/repos/${slug.fullName}/git/trees',
154160
convert: GitTree.fromJSON,
155161
statusCode: StatusCodes.CREATED,
156-
body: tree.toJSON());
162+
body: tree.toJSON()) as Future<GitTree>;
157163
}
158164
}

lib/src/common/github.dart

Lines changed: 67 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,25 @@ part of github.common;
22

33
typedef http.Client ClientCreator();
44

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+
///
1312
class GitHub {
1413
static const _ratelimitLimitHeader = 'x-ratelimit-limit';
1514
static const _ratelimitResetHeader = 'x-ratelimit-reset';
1615
static const _ratelimitRemainingHeader = 'x-ratelimit-remaining';
1716

18-
/**
19-
* Authentication Information
20-
*/
17+
/// Authentication Information
2118
Authentication auth;
2219

23-
/**
24-
* API Endpoint
25-
*/
20+
/// API Endpoint
2621
final String endpoint;
2722

28-
/**
29-
* HTTP Client
30-
*/
23+
/// HTTP Client
3124
final http.Client client;
3225

3326
ActivityService _activity;
@@ -45,6 +38,17 @@ class GitHub {
4538
UrlShortenerService _urlShortener;
4639
UsersService _users;
4740

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+
4852
/// The maximum number of requests that the consumer is permitted to make per
4953
/// hour.
5054
///
@@ -72,20 +76,6 @@ class GitHub {
7276

7377
int _rateLimitReset, _rateLimitLimit, _rateLimitRemaining;
7478

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-
8979
/// Service for activity related methods of the GitHub API.
9080
ActivityService get activity {
9181
if (_activity == null) {
@@ -201,26 +191,19 @@ class GitHub {
201191
return _users;
202192
}
203193

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.
224207
Future<dynamic> getJSON(String path,
225208
{int statusCode,
226209
void fail(http.Response response),
@@ -252,35 +235,31 @@ class GitHub {
252235
return convert(json);
253236
}
254237

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.
277256
Future<dynamic> postJSON(String path,
278257
{int statusCode,
279258
void fail(http.Response response),
280259
Map<String, String> headers,
281260
Map<String, String> params,
282261
JSONConverter convert,
283-
body,
262+
String body,
284263
String preview}) async {
285264
if (headers == null) headers = {};
286265

@@ -303,16 +282,16 @@ class GitHub {
303282
return convert(JSON.decode(response.body));
304283
}
305284

306-
/**
307-
* Internal method to handle status codes
308-
*/
285+
///
286+
/// Internal method to handle status codes
287+
///
309288
void handleStatusCode(http.Response response) {
310289
String message;
311290
List<Map<String, String>> errors;
312291
if (response.headers['content-type'].contains('application/json')) {
313292
var json = JSON.decode(response.body);
314293
message = json['message'];
315-
errors = json['errors'];
294+
errors = json['errors'] as List<Map<String, String>>;
316295
}
317296
switch (response.statusCode) {
318297
case 404:
@@ -349,15 +328,14 @@ class GitHub {
349328
throw new UnknownError(this, message);
350329
}
351330

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+
///
361339
Future<http.Response> request(String method, String path,
362340
{Map<String, String> headers,
363341
Map<String, dynamic> params,
@@ -422,11 +400,8 @@ class GitHub {
422400
return response;
423401
}
424402

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.
430405
void dispose() {
431406
// Destroy the Authentication Information
432407
// This is needed for security reasons.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy