Use SDK v1.21 generic methods
MODIFY
lib/src/common/activity_service.dart
lib/src/common/activity_service.dart
@@ -180,11 +180,9 @@ class ActivityService extends Service {
/// Fetches the specified notification thread.
///
/// API docs: https://developer.github.com/v3/activity/notifications/#view-a-single-thread
- Future<Notification> getThread(String threadId) {
- return _github.getJSON("/notification/threads/${threadId}",
- statusCode: StatusCodes.OK,
- convert: Notification.fromJSON) as Future<Notification>;
- }
+ Future<Notification> getThread(String threadId) =>
+ _github.getJSON("/notification/threads/${threadId}",
+ statusCode: StatusCodes.OK, convert: Notification.fromJSON);
// TODO: Implement markThreadRead: https://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read
// TODO: Implement getThreadSubscription: https://developer.github.com/v3/activity/notifications/#get-a-thread-subscription
@@ -276,12 +274,9 @@ class ActivityService extends Service {
///
/// API docs: https://developer.github.com/v3/activity/watching/#get-a-repository-subscription
Future<RepositorySubscription> getRepositorySubscription(
- RepositorySlug slug) {
- return _github.getJSON("/repos/${slug.fullName}/subscription",
- statusCode: StatusCodes.OK,
- convert: RepositorySubscription.fromJSON)
- as Future<RepositorySubscription>;
- }
+ RepositorySlug slug) =>
+ _github.getJSON("/repos/${slug.fullName}/subscription",
+ statusCode: StatusCodes.OK, convert: RepositorySubscription.fromJSON);
/// Sets the Repository Subscription Status
///

MODIFY
lib/src/common/authorizations_service.dart
lib/src/common/authorizations_service.dart
@@ -22,11 +22,9 @@ class AuthorizationsService extends Service {
/// Fetches an authorization specified by [id].
///
/// API docs: https://developer.github.com/v3/oauth_authorizations/#get-a-single-authorization
- Future<Authorization> getAuthorization(int id) {
- return _github.getJSON("/authorizations/${id}",
- statusCode: 200,
- convert: Authorization.fromJSON) as Future<Authorization>;
- }
+ Future<Authorization> getAuthorization(int id) =>
+ _github.getJSON("/authorizations/${id}",
+ statusCode: 200, convert: Authorization.fromJSON);
// TODO: Implement remaining API methods of authorizations:
// See https://developer.github.com/v3/oauth_authorizations/

MODIFY
lib/src/common/gists_service.dart
lib/src/common/gists_service.dart
@@ -43,10 +43,8 @@ class GistsService extends Service {
/// Fetches a Gist by the specified [id].
///
/// API docs: https://developer.github.com/v3/gists/#get-a-single-gist
- Future<Gist> getGist(String id) {
- return _github.getJSON("/gists/${id}",
- statusCode: StatusCodes.OK, convert: Gist.fromJSON) as Future<Gist>;
- }
+ Future<Gist> getGist(String id) => _github.getJSON("/gists/${id}",
+ statusCode: StatusCodes.OK, convert: Gist.fromJSON);
/// Creates a Gist
///

MODIFY
lib/src/common/git_service.dart
lib/src/common/git_service.dart
@@ -10,11 +10,9 @@ class GitService extends Service {
/// Fetches a blob from [slug] for a given [sha].
///
/// API docs: https://developer.github.com/v3/git/blobs/#get-a-blob
- Future<GitBlob> getBlob(RepositorySlug slug, String sha) {
- return _github.getJSON('/repos/${slug.fullName}/git/blobs/${sha}',
- convert: GitBlob.fromJSON,
- statusCode: StatusCodes.OK) as Future<GitBlob>;
- }
+ Future<GitBlob> getBlob(RepositorySlug slug, String sha) =>
+ _github.getJSON('/repos/${slug.fullName}/git/blobs/${sha}',
+ convert: GitBlob.fromJSON, statusCode: StatusCodes.OK);
/// Creates a blob with specified [blob] content.
///
@@ -29,11 +27,9 @@ class GitService extends Service {
/// Fetches a commit from [slug] for a given [sha].
///
/// API docs: https://developer.github.com/v3/git/commits/#get-a-commit
- Future<GitCommit> getCommit(RepositorySlug slug, String sha) {
- return _github.getJSON('/repos/${slug.fullName}/git/commits/${sha}',
- convert: GitCommit.fromJSON,
- statusCode: StatusCodes.OK) as Future<GitCommit>;
- }
+ Future<GitCommit> getCommit(RepositorySlug slug, String sha) =>
+ _github.getJSON('/repos/${slug.fullName}/git/commits/${sha}',
+ convert: GitCommit.fromJSON, statusCode: StatusCodes.OK);
/// Creates a new commit in a repository.
///
@@ -50,11 +46,9 @@ class GitService extends Service {
/// Note: The [ref] in the URL must be formatted as "heads/branch", not just "branch".
///
/// API docs: https://developer.github.com/v3/git/refs/#get-a-reference
- Future<GitReference> getReference(RepositorySlug slug, String ref) {
- return _github.getJSON('/repos/${slug.fullName}/git/refs/${ref}',
- convert: GitReference.fromJSON,
- statusCode: StatusCodes.OK) as Future<GitReference>;
- }
+ Future<GitReference> getReference(RepositorySlug slug, String ref) =>
+ _github.getJSON('/repos/${slug.fullName}/git/refs/${ref}',
+ convert: GitReference.fromJSON, statusCode: StatusCodes.OK);
/// Lists the references in a repository.
///
@@ -118,20 +112,18 @@ class GitService extends Service {
/// Fetches a tag from the repo given a SHA.
///
/// API docs: https://developer.github.com/v3/git/tags/#get-a-tag
- Future<GitTag> getTag(RepositorySlug slug, String sha) {
- return _github.getJSON('/repos/${slug.fullName}/git/tags/${sha}',
- convert: GitTag.fromJSON, statusCode: StatusCodes.OK) as Future<GitTag>;
- }
+ Future<GitTag> getTag(RepositorySlug slug, String sha) =>
+ _github.getJSON('/repos/${slug.fullName}/git/tags/${sha}',
+ convert: GitTag.fromJSON, statusCode: StatusCodes.OK);
/// Creates a new tag in a repository.
///
/// API docs: https://developer.github.com/v3/git/tags/#create-a-tag-object
- Future<GitTag> createTag(RepositorySlug slug, CreateGitTag tag) {
- return _github.postJSON('/repos/${slug.fullName}/git/tags',
+ Future<GitTag> createTag(RepositorySlug slug, CreateGitTag tag) =>
+ _github.postJSON('/repos/${slug.fullName}/git/tags',
convert: GitTag.fromJSON,
statusCode: StatusCodes.CREATED,
- body: tag.toJSON()) as Future<GitTag>;
- }
+ body: tag.toJSON());
/// Fetches a tree from a repository for the given ref [sha].
///
@@ -147,8 +139,7 @@ class GitService extends Service {
}
return _github.getJSON(path,
- convert: (j) => new GitTree.fromJson(j),
- statusCode: StatusCodes.OK) as Future<GitTree>;
+ convert: (j) => new GitTree.fromJson(j), statusCode: StatusCodes.OK);
}
/// Creates a new tree in a repository.

MODIFY
lib/src/common/github.dart
lib/src/common/github.dart
@@ -204,12 +204,12 @@ class GitHub {
/// [convert] is a simple function that is passed this [GitHub] instance and a JSON object.
/// The future will pass the object returned from this function to the then method.
/// The default [convert] function returns the input object.
- Future<dynamic> getJSON(String path,
+ Future<T> getJSON<T>(String path,
{int statusCode,
void fail(http.Response response),
Map<String, String> headers,
Map<String, String> params,
- JSONConverter convert,
+ JSONConverter<T> convert,
String preview}) async {
if (headers == null) headers = {};

MODIFY
lib/src/common/issues_service.dart
lib/src/common/issues_service.dart
@@ -138,10 +138,9 @@ class IssuesService extends Service {
/// Get an issue.
///
/// API docs: https://developer.github.com/v3/issues/#get-a-single-issue
- Future<Issue> get(RepositorySlug slug, int issueNumber) {
- return _github.getJSON("/repos/${slug.fullName}/issues/${issueNumber}",
- convert: Issue.fromJSON) as Future<Issue>;
- }
+ Future<Issue> get(RepositorySlug slug, int issueNumber) =>
+ _github.getJSON("/repos/${slug.fullName}/issues/${issueNumber}",
+ convert: Issue.fromJSON);
/// Create an issue.
///
@@ -202,10 +201,9 @@ class IssuesService extends Service {
/// Fetches the specified issue comment.
///
/// API docs: https://developer.github.com/v3/issues/comments/#get-a-single-comment
- Future<IssueComment> getComment(RepositorySlug slug, int id) {
- return _github.getJSON("/repos/${slug.fullName}/issues/comments/${id}",
- convert: IssueComment.fromJSON) as Future<IssueComment>;
- }
+ Future<IssueComment> getComment(RepositorySlug slug, int id) =>
+ _github.getJSON("/repos/${slug.fullName}/issues/comments/${id}",
+ convert: IssueComment.fromJSON);
/// Creates a new comment on the specified issue
///
@@ -245,11 +243,9 @@ class IssuesService extends Service {
/// Fetches a single label.
///
/// API docs: https://developer.github.com/v3/issues/labels/#get-a-single-label
- Future<IssueLabel> getLabel(RepositorySlug slug, String name) {
- return _github.getJSON("/repos/${slug.fullName}/labels/${name}",
- convert: IssueLabel.fromJSON,
- statusCode: StatusCodes.OK) as Future<IssueLabel>;
- }
+ Future<IssueLabel> getLabel(RepositorySlug slug, String name) =>
+ _github.getJSON("/repos/${slug.fullName}/labels/${name}",
+ convert: IssueLabel.fromJSON, statusCode: StatusCodes.OK);
/// Creates a new label on the specified repository.
///

MODIFY
lib/src/common/misc_service.dart
lib/src/common/misc_service.dart
@@ -27,10 +27,9 @@ class MiscService extends Service {
/// All template names can be fetched using [listGitignoreTemplates].
///
/// API docs: https://developer.github.com/v3/gitignore/#get-a-single-template
- Future<GitignoreTemplate> getGitignoreTemplate(String name) {
- return _github.getJSON("/gitignore/templates/${name}",
- convert: GitignoreTemplate.fromJSON) as Future<GitignoreTemplate>;
- }
+ Future<GitignoreTemplate> getGitignoreTemplate(String name) =>
+ _github.getJSON("/gitignore/templates/${name}",
+ convert: GitignoreTemplate.fromJSON);
/// Renders Markdown from the [input].
///
@@ -63,11 +62,9 @@ class MiscService extends Service {
}
/// Gets the GitHub API Status.
- Future<APIStatus> getApiStatus() {
- return _github.getJSON("https://status.github.com/api/status.json",
- statusCode: StatusCodes.OK,
- convert: APIStatus.fromJSON) as Future<APIStatus>;
- }
+ Future<APIStatus> getApiStatus() =>
+ _github.getJSON("https://status.github.com/api/status.json",
+ statusCode: StatusCodes.OK, convert: APIStatus.fromJSON);
/// Returns a stream of Octocats from Octodex.
///

MODIFY
lib/src/common/orgs_service.dart
lib/src/common/orgs_service.dart
@@ -24,15 +24,13 @@ class OrganizationsService extends Service {
/// Fetches the organization specified by [name].
///
/// API docs: https://developer.github.com/v3/orgs/#get-an-organization
- Future<Organization> get(String name) {
- return _github.getJSON("/orgs/${name}",
+ Future<Organization> get(String name) => _github.getJSON("/orgs/${name}",
convert: Organization.fromJSON,
statusCode: StatusCodes.OK, fail: (http.Response response) {
if (response.statusCode == 404) {
throw new OrganizationNotFound(_github, name);
}
- }) as Future<Organization>;
- }
+ });
/// Fetches the organizations specified by [names].
Stream<Organization> getMulti(List<String> names) {
@@ -287,11 +285,9 @@ class OrganizationsService extends Service {
/// Fetches a single hook by [id].
///
/// API docs: https://developer.github.com/v3/orgs/hooks/#get-single-hook
- Future<Hook> getHook(String org, int id) {
- return _github.getJSON("/orgs/${org}/hooks/${id}",
- convert: (Map<String, dynamic> i) => Hook.fromJSON(org, i))
- as Future<Hook>;
- }
+ Future<Hook> getHook(String org, int id) =>
+ _github.getJSON("/orgs/${org}/hooks/${id}",
+ convert: (Map<String, dynamic> i) => Hook.fromJSON(org, i));
/// Creates an organization hook based on the specified [hook].
///

MODIFY
lib/src/common/pulls_service.dart
lib/src/common/pulls_service.dart
@@ -16,11 +16,9 @@ class PullRequestsService extends Service {
/// Fetches a single pull request.
///
/// API docs: https://developer.github.com/v3/pulls/#get-a-single-pull-request
- Future<PullRequest> get(RepositorySlug slug, int number) {
- return _github.getJSON("/repos/${slug.fullName}/pulls/${number}",
- convert: PullRequest.fromJSON,
- statusCode: StatusCodes.OK) as Future<PullRequest>;
- }
+ Future<PullRequest> get(RepositorySlug slug, int number) =>
+ _github.getJSON("/repos/${slug.fullName}/pulls/${number}",
+ convert: PullRequest.fromJSON, statusCode: StatusCodes.OK);
/// Creates a Pull Request based on the given [request].
///

MODIFY
lib/src/common/repos_service.dart
lib/src/common/repos_service.dart
@@ -95,15 +95,14 @@ class RepositoriesService extends Service {
/// Fetches the repository specified by the [slug].
///
/// API docs: https://developer.github.com/v3/repos/#get
- Future<Repository> getRepository(RepositorySlug slug) {
- return _github.getJSON("/repos/${slug.owner}/${slug.name}",
+ Future<Repository> getRepository(RepositorySlug slug) =>
+ _github.getJSON("/repos/${slug.owner}/${slug.name}",
convert: Repository.fromJSON,
statusCode: StatusCodes.OK, fail: (http.Response response) {
if (response.statusCode == 404) {
throw new RepositoryNotFound(_github, slug.fullName);
}
- }) as Future<Repository>;
- }
+ });
/// Fetches a list of repositories specified by [slugs].
Stream<Repository> getRepositories(List<RepositorySlug> slugs) {
@@ -185,15 +184,15 @@ class RepositoriesService extends Service {
Future<LanguageBreakdown> listLanguages(RepositorySlug slug) =>
_github.getJSON("/repos/${slug.fullName}/languages",
statusCode: StatusCodes.OK,
- convert: (Map<String, int> input) => new LanguageBreakdown(input))
- as Future<LanguageBreakdown>;
+ convert: (Map<String, int> input) => new LanguageBreakdown(input));
/// Lists the tags of the specified repository.
///
/// API docs: https://developer.github.com/v3/repos/#list-tags
Stream<Tag> listTags(RepositorySlug slug) {
return new PaginationHelper(_github).objects(
- 'GET', '/repos/${slug.fullName}/tags', (j) => new Tag.fromJson(j)) as Stream<Tag>;
+ 'GET', '/repos/${slug.fullName}/tags', (j) => new Tag.fromJson(j))
+ as Stream<Tag>;
}
/// Lists the branches of the specified repository.
@@ -208,10 +207,9 @@ class RepositoriesService extends Service {
/// Fetches the specified branch.
///
/// API docs: https://developer.github.com/v3/repos/#get-branch
- Future<Branch> getBranch(RepositorySlug slug, String branch) {
- return _github.getJSON("/repos/${slug.fullName}/branches/${branch}",
- convert: Branch.fromJSON) as Future<Branch>;
- }
+ Future<Branch> getBranch(RepositorySlug slug, String branch) =>
+ _github.getJSON("/repos/${slug.fullName}/branches/${branch}",
+ convert: Branch.fromJSON);
/// Lists the users that have access to the repository identified by [slug].
///
@@ -265,10 +263,9 @@ class RepositoriesService extends Service {
/// Fetches the specified commit.
///
/// API docs: https://developer.github.com/v3/repos/commits/#get-a-single-commit
- Future<RepositoryCommit> getCommit(RepositorySlug slug, String sha) {
- return _github.getJSON("/repos/${slug.fullName}/commits/${sha}",
- convert: RepositoryCommit.fromJSON) as Future<RepositoryCommit>;
- }
+ Future<RepositoryCommit> getCommit(RepositorySlug slug, String sha) =>
+ _github.getJSON("/repos/${slug.fullName}/commits/${sha}",
+ convert: RepositoryCommit.fromJSON);
/// [refBase] and [refHead] can be the same value for a branch, commit, or ref
/// in [slug] or specify other repositories by using `repo:ref` syntax.
@@ -303,7 +300,7 @@ class RepositoriesService extends Service {
}
},
convert: (Map<String, dynamic> input) =>
- GitHubFile.fromJSON(input, slug)) as Future<GitHubFile>;
+ GitHubFile.fromJSON(input, slug));
}
/// Fetches content in a repository at the specified [path].
@@ -346,7 +343,7 @@ class RepositoriesService extends Service {
.toList();
}
return contents;
- }) as Future<RepositoryContents>;
+ });
}
/// Creates a new file in a repository.
@@ -441,11 +438,9 @@ class RepositoriesService extends Service {
/// Fetches a single hook by [id].
///
/// API docs: https://developer.github.com/v3/repos/hooks/#get-single-hook
- Future<Hook> getHook(RepositorySlug slug, int id) {
- return _github.getJSON("/repos/${slug.fullName}/hooks/${id}",
- convert: (Map<String, dynamic> i) =>
- Hook.fromJSON(slug.fullName, i)) as Future<Hook>;
- }
+ Future<Hook> getHook(RepositorySlug slug, int id) =>
+ _github.getJSON("/repos/${slug.fullName}/hooks/${id}",
+ convert: (Map<String, dynamic> i) => Hook.fromJSON(slug.fullName, i));
/// Creates a repository hook based on the specified [hook].
///
@@ -521,11 +516,9 @@ class RepositoriesService extends Service {
/// Fetches the GitHub pages information for the specified repository.
///
/// API docs: https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site
- Future<RepositoryPages> getPagesInfo(RepositorySlug slug) {
- return _github.getJSON("/repos/${slug.fullName}/pages",
- statusCode: 200,
- convert: RepositoryPages.fromJSON) as Future<RepositoryPages>;
- }
+ Future<RepositoryPages> getPagesInfo(RepositorySlug slug) =>
+ _github.getJSON("/repos/${slug.fullName}/pages",
+ statusCode: 200, convert: RepositoryPages.fromJSON);
// TODO: Implement listPagesBuilds: https://developer.github.com/v3/repos/pages/#list-pages-builds
// TODO: Implement getLatestPagesBuild: https://developer.github.com/v3/repos/pages/#list-latest-pages-build
@@ -542,10 +535,9 @@ class RepositoriesService extends Service {
/// Fetches a single release.
///
/// API docs: https://developer.github.com/v3/repos/releases/#get-a-single-release
- Future<Release> getRelease(RepositorySlug slug, int id) {
- return _github.getJSON("/repos/${slug.fullName}/releases/${id}",
- convert: Release.fromJSON) as Future<Release>;
- }
+ Future<Release> getRelease(RepositorySlug slug, int id) =>
+ _github.getJSON("/repos/${slug.fullName}/releases/${id}",
+ convert: Release.fromJSON);
/// Creates a Release based on the specified [release].
///
@@ -613,11 +605,9 @@ class RepositoriesService extends Service {
/// Fetches Participation Breakdowns.
///
/// API docs: https://developer.github.com/v3/repos/statistics/#participation
- Future<ContributorParticipation> getParticipation(RepositorySlug slug) {
- return _github.getJSON("/repos/${slug.fullName}/stats/participation",
- statusCode: 200, convert: ContributorParticipation.fromJSON)
- as Future<ContributorParticipation>;
- }
+ Future<ContributorParticipation> getParticipation(RepositorySlug slug) =>
+ _github.getJSON("/repos/${slug.fullName}/stats/participation",
+ statusCode: 200, convert: ContributorParticipation.fromJSON);
/// Fetches Punchcard.
///
@@ -655,9 +645,7 @@ class RepositoriesService extends Service {
///
/// API docs: https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
Future<CombinedRepositoryStatus> getCombinedStatus(
- RepositorySlug slug, String ref) {
- return _github.getJSON("/repos/${slug.fullName}/commits/${ref}/status",
- convert: CombinedRepositoryStatus.fromJSON,
- statusCode: 200) as Future<CombinedRepositoryStatus>;
- }
+ RepositorySlug slug, String ref) =>
+ _github.getJSON("/repos/${slug.fullName}/commits/${ref}/status",
+ convert: CombinedRepositoryStatus.fromJSON, statusCode: 200);
}

MODIFY
lib/src/common/users_service.dart
lib/src/common/users_service.dart
@@ -11,7 +11,7 @@ class UsersService extends Service {
///
/// API docs: https://developer.github.com/v3/users/#get-a-single-user
Future<User> getUser(String name) =>
- _github.getJSON("/users/${name}", convert: User.fromJSON) as Future<User>;
+ _github.getJSON("/users/${name}", convert: User.fromJSON);
/// Updates the Current User.
///
@@ -65,14 +65,13 @@ class UsersService extends Service {
/// Throws [AccessForbidden] if we are not authenticated.
///
/// API docs: https://developer.github.com/v3/users/#get-the-authenticated-user
- Future<CurrentUser> getCurrentUser() {
- return _github.getJSON("/user", statusCode: StatusCodes.OK,
+ Future<CurrentUser> getCurrentUser() =>
+ _github.getJSON("/user", statusCode: StatusCodes.OK,
fail: (http.Response response) {
if (response.statusCode == StatusCodes.FORBIDDEN) {
throw new AccessForbidden(_github);
}
- }, convert: CurrentUser.fromJSON) as Future<CurrentUser>;
- }
+ }, convert: CurrentUser.fromJSON);
/// Checks if a user exists.
Future<bool> isUser(String name) => _github

MODIFY
pubspec.yaml
pubspec.yaml
@@ -4,7 +4,7 @@ author: Kenneth Endfinger <kaendfinger@gmail.com>
description: GitHub API Client Library
homepage: https://github.com/DirectMyFile/github.dart
environment:
- sdk: '>=1.13.0 <2.0.0'
+ sdk: '>=1.21.0 <2.0.0'
dependencies:
html: '>=0.12.0 <0.14.0'
http: '^0.11.3'

Use SDK v1.21 generic methods