Files
GitJournal/lib/apis/githost.dart
Vishesh Handa 763cbf8493 Use flutter_web_auth instead of our own OAuth mechanism
This works slightly better on iOS and on Android it has a keep alive,
which will prevent our app from being killed. Additionally, this way
there is less for me to maintain, which is always nicer.

The API for flutter_web_auth is also much simpler.

This also inolves some custom logic for parsing the Query Parameters
from the GitLab callback, as it doesn't seem to be a proper URI. Not
sure what is going on with Gitlab.
2020-06-09 17:09:38 +02:00

62 lines
1.5 KiB
Dart

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