2021-01-28 04:33:26 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2021-02-10 05:09:57 +00:00
|
|
|
// ignore: uri_does_not_exist
|
|
|
|
import 'cookie_client_stub.dart'
|
|
|
|
// ignore: uri_does_not_exist
|
|
|
|
if (dart.library.html) 'browser_cookie_client.dart'
|
|
|
|
// ignore: uri_does_not_exist
|
|
|
|
if (dart.library.io) 'io_cookie_client.dart';
|
|
|
|
|
2021-01-28 04:33:26 +00:00
|
|
|
import 'package:meta/meta.dart';
|
2021-02-10 05:09:57 +00:00
|
|
|
import 'package:graphql_flutter/graphql_flutter.dart';
|
2021-02-10 22:42:57 +00:00
|
|
|
import 'package:imagini/graphql/imagini_graphql.dart';
|
2021-01-28 04:33:26 +00:00
|
|
|
|
|
|
|
class APIProvider{
|
|
|
|
String _server, _accessToken, _refreshToken;
|
|
|
|
|
2021-02-10 05:09:57 +00:00
|
|
|
GraphQLClient _client;
|
|
|
|
HttpLink httpLink;
|
|
|
|
// CookieLink cookieLink;
|
|
|
|
static const String _GRAPHQL_ENDPOINT = "/query";
|
2021-01-28 04:33:26 +00:00
|
|
|
|
|
|
|
APIProvider({
|
|
|
|
@required String server,
|
|
|
|
String accessToken,
|
|
|
|
String refreshToken
|
|
|
|
}) {
|
|
|
|
_server = server;
|
|
|
|
_accessToken = accessToken;
|
|
|
|
_refreshToken = refreshToken;
|
2021-02-10 05:09:57 +00:00
|
|
|
httpLink = HttpLink(_server + _GRAPHQL_ENDPOINT,
|
|
|
|
httpClient: getCookieClient(),
|
|
|
|
);
|
|
|
|
|
|
|
|
// cookieLink = CookieLink(_updateAccessToken, _updateRefreshToken);
|
|
|
|
_client = GraphQLClient(
|
|
|
|
cache: GraphQLCache(),
|
|
|
|
link: httpLink,
|
|
|
|
);
|
2021-01-28 04:33:26 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 05:09:57 +00:00
|
|
|
// void _updateAccessToken(_accessToken) {
|
|
|
|
// print("Updating Access Token: $_accessToken");
|
|
|
|
// this._accessToken = _accessToken;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// void _updateRefreshToken(_refreshToken) {
|
|
|
|
// print("Updating Refresh Token: $_accessToken");
|
|
|
|
// this._refreshToken = _refreshToken;
|
|
|
|
// }
|
|
|
|
|
2021-02-10 22:42:57 +00:00
|
|
|
Future<Login$Query$AuthResponse> login([
|
2021-01-28 04:33:26 +00:00
|
|
|
String username,
|
|
|
|
String password,
|
|
|
|
]) async {
|
|
|
|
assert(
|
2021-02-11 20:35:47 +00:00
|
|
|
(username != null && password != null)
|
2021-01-28 04:33:26 +00:00
|
|
|
);
|
|
|
|
|
2021-02-10 05:09:57 +00:00
|
|
|
QueryResult response = await _client.query(
|
|
|
|
QueryOptions(
|
2021-02-10 22:42:57 +00:00
|
|
|
document: LoginQuery().document,
|
2021-02-10 05:09:57 +00:00
|
|
|
variables: {
|
2021-02-11 20:35:47 +00:00
|
|
|
"user": username,
|
|
|
|
"password": password
|
2021-02-10 05:09:57 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
);
|
2021-01-28 04:33:26 +00:00
|
|
|
|
2021-02-10 22:42:57 +00:00
|
|
|
final loginResponse = Login$Query.fromJson(response.data);
|
|
|
|
return loginResponse.login;
|
2021-01-28 04:33:26 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 20:35:47 +00:00
|
|
|
Future<Me$Query$User> me() async {
|
|
|
|
QueryResult response = await _client.query(
|
|
|
|
QueryOptions(
|
|
|
|
document: MeQuery().document,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
final meResponse = Me$Query.fromJson(response.data);
|
|
|
|
return meResponse.me;
|
2021-01-28 04:33:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<String> mediaItems([
|
|
|
|
String startDate,
|
|
|
|
String endDate,
|
|
|
|
String albumID,
|
|
|
|
List<String> tagID,
|
|
|
|
String type, // TODO: Make enum
|
|
|
|
int page,
|
|
|
|
]) async {
|
|
|
|
// Query:
|
|
|
|
// /api/v1/MediaItems
|
|
|
|
// Derive Params:
|
|
|
|
// startDate:
|
|
|
|
// &createdAt=>2020-10-10T10:10:10
|
|
|
|
// endDate:
|
|
|
|
// &createdAt=<2020-10-10T10:10:10
|
|
|
|
// albumID:
|
|
|
|
// &albumID=9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d
|
|
|
|
// tagID:
|
|
|
|
// &tagID=9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d,9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d
|
|
|
|
// type:
|
|
|
|
// &type=Photos
|
|
|
|
// &type=Videos
|
|
|
|
// page:
|
|
|
|
// &page=4
|
|
|
|
|
|
|
|
// Returns:
|
|
|
|
// {
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<String> tags([
|
|
|
|
int page
|
|
|
|
]) async {
|
|
|
|
// Query:
|
|
|
|
// /api/v1/Tags
|
|
|
|
// Derive Params:
|
|
|
|
// page:
|
|
|
|
// &page=4
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<String> albums([
|
|
|
|
int page
|
|
|
|
]) async {
|
|
|
|
// Query:
|
|
|
|
// /api/v1/Albums
|
|
|
|
// Derive Params:
|
|
|
|
// page:
|
|
|
|
// &page=4
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<String> me() async {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dispose() {}
|
|
|
|
}
|