Files
GitJournal/lib/apis/githost.dart
Vishesh Handa d653663a47 Change Git dart API
Use a class instead of a many functions. This way we avoid passing the
same arguments again and again.
2019-06-17 19:38:56 +02:00

58 lines
1.4 KiB
Dart

import 'dart:async';
import 'package:flutter/foundation.dart';
typedef OAuthCallback = void Function(GitHostException);
abstract class GitHost {
void init(OAuthCallback oAuthCallback);
Future launchOAuthScreen();
Future<UserInfo> getUserInfo();
Future<List<GitHostRepo>> listRepos();
Future<GitHostRepo> createRepo(String name);
Future<GitHostRepo> getRepo(String name);
Future addDeployKey(String sshPublicKey, String repo);
}
class UserInfo {
String name;
String email;
String username;
UserInfo({
@required this.name,
@required this.email,
@required this.username,
});
}
class GitHostRepo {
String fullName;
String cloneUrl;
GitHostRepo({this.fullName, this.cloneUrl});
@override
String toString() {
return 'GitRepo{fulleName: $fullName, cloneUrl: $cloneUrl}';
}
}
class GitHostException implements Exception {
static const OAuthFailed = const GitHostException("OAuthFailed");
static const MissingAccessCode = const GitHostException("MissingAccessCode");
static const RepoExists = const GitHostException("RepoExists");
static const CreateRepoFailed = const GitHostException("CreateRepoFailed");
static const DeployKeyFailed = const GitHostException("DeployKeyFailed");
static const GetRepoFailed = const GitHostException("GetRepoFailed");
final String cause;
const GitHostException(this.cause);
@override
String toString() {
return "GitHostException: " + cause;
}
}