Add a GitHost interface

GitLab and GitHost are two implementations of that interface.
This commit is contained in:
Vishesh Handa
2019-01-25 11:21:58 +01:00
parent c7174ab2da
commit ac5c2be05d
5 changed files with 83 additions and 64 deletions

View File

@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:journal/apis/github.dart';
import 'package:journal/apis/gitlab.dart';
import 'apis/githost.dart';
import 'apis/github.dart';
import 'apis/gitlab.dart';
class OAuthApp extends StatefulWidget {
@override
@ -14,11 +15,18 @@ var key =
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+VAh8r+vn0c+M+DacOo/szXcdMpxO1kIO3USkzgE5XdO83kQdDwh4Xc4P3dcc+FFSfVcEl3mSXGKbYC3G0ZoVcWd4ed40Gt3sLHSfNRQlRv+obnqKbzDLuOGfq65EkaJ90vrWBo/k7K8tBC2j1FZ/PUYy3DxeQkPEZXCMZDSG5P/+XoHn5IPcaxDpvlZjtOrx4H3pQ/YVI+XmyFAsZe+/Shy5sg4ilsdo4BQN2nODuBLwmgYu/hHmCcd8t4OxgBANVN8TMqHnZfRLixRSuXn0DbV4YOa/b2lBFQNvjkoBF6KhXOxZ+awyjyTpNp4AgF5c+3xptkNwUlwiQDCzcUmH your_email@example.com';
class OAuthAppState extends State<OAuthApp> {
var github = new Gitlab();
GitHost githost;
void initState() {
super.initState();
github.init(() {
if (true) {
githost = new GitHub();
} else {
githost = new GitLab();
}
githost.init(() {
print("GitHub initialized and has access code");
});
}
@ -35,14 +43,14 @@ class OAuthAppState extends State<OAuthApp> {
RaisedButton(
child: Text("Open OAuth URL"),
onPressed: () {
github.launchOAuthScreen();
githost.launchOAuthScreen();
},
),
RaisedButton(
child: Text("List Repos"),
onPressed: () async {
try {
var repos = await github.listRepos();
var repos = await githost.listRepos();
for (var repo in repos) {
print(repo);
}
@ -55,7 +63,7 @@ class OAuthAppState extends State<OAuthApp> {
child: Text("Create Repo"),
onPressed: () async {
try {
var repo = await github.createRepo("journal_test2");
var repo = await githost.createRepo("journal_test2");
print(repo);
} catch (err) {
print("Create Repo: " + err.toString());
@ -66,7 +74,7 @@ class OAuthAppState extends State<OAuthApp> {
child: Text("Add Deploy Key"),
onPressed: () async {
try {
await github.addDeployKey(key, "vhanda/journal_test2");
await githost.addDeployKey(key, "vhanda/journal_test2");
} catch (err) {
print("Deploy Key: " + err.toString());
}