Preclean
This commit is contained in:
85
web_native/lib/services/api/api.dart
Normal file
85
web_native/lib/services/api/api.dart
Normal file
@@ -0,0 +1,85 @@
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
// import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
// import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
// if(kIsWeb) {
|
||||
// // Use web storage
|
||||
// } else {
|
||||
// // Use flutter_secure_storage
|
||||
// }
|
||||
|
||||
// final _storage = FlutterSecureStorage();
|
||||
|
||||
class ImaginiAPI {
|
||||
static const _baseUrl = "http://10.0.20.170:8484";
|
||||
// static const String _GET_ALBUMS = '/albums';
|
||||
|
||||
Future<String> exampleApi() async {
|
||||
http.Response response = await http.get(
|
||||
Uri.encodeFull("https://www.example.com/api"),
|
||||
);
|
||||
print("Status: ${response.statusCode.toString()}");
|
||||
print("Respone: ${response.body.toString()}");
|
||||
return response.body;
|
||||
}
|
||||
|
||||
Future<Map<String, String>> loginAPI(String user, String password) async {
|
||||
http.Response response = await http.post(
|
||||
Uri.encodeFull(_baseUrl + "/api/v1/Login"),
|
||||
body: jsonEncode(<String, String>{
|
||||
'user': user,
|
||||
'password': password,
|
||||
}),
|
||||
).timeout(Duration(seconds: 10));
|
||||
|
||||
|
||||
|
||||
// TODO:
|
||||
// - StatusCode:
|
||||
// - 405 (StatusMethodNotAllowed)
|
||||
// - 400 (StatusBadRequest)
|
||||
// - 401 (StatusUnauthorized)
|
||||
// -
|
||||
// -
|
||||
// -
|
||||
|
||||
String setCookieVal = response.headers["set-cookie"];
|
||||
List<Cookie> allCookies = setCookieVal.split(',')
|
||||
.map((cookie) => Cookie.fromSetCookieValue(cookie)).toList();
|
||||
|
||||
Cookie accessToken = allCookies.firstWhere((cookie) => cookie.name == "AccessToken");
|
||||
Cookie refreshToken = allCookies.firstWhere((cookie) => cookie.name == "RefreshToken");
|
||||
|
||||
print("Status: ${response.statusCode.toString()}");
|
||||
print("Body: ${response.body.toString()}");
|
||||
print("AccessToken: ${accessToken.toString()}");
|
||||
print("RefreshToken: ${refreshToken.toString()}");
|
||||
return response.headers;
|
||||
}
|
||||
|
||||
Future<String> mediaItemsAPI(String albumID, String tagID) async {
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<String> tagsAPI() async {
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<String> albumsAPI() async {
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<String> meAPI() async {
|
||||
return null;
|
||||
}
|
||||
|
||||
// API Calls:
|
||||
// - Login
|
||||
// - MediaItems
|
||||
// - Tags
|
||||
// - Albums
|
||||
// - Me
|
||||
}
|
||||
19
web_native/lib/services/api/exceptions.dart
Normal file
19
web_native/lib/services/api/exceptions.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
class ConnectionRefusedException {
|
||||
var message;
|
||||
ConnectionRefusedException(this.message);
|
||||
}
|
||||
|
||||
class NoServiceFoundException {
|
||||
var message;
|
||||
NoServiceFoundException(this.message);
|
||||
}
|
||||
|
||||
class InvalidFormatException {
|
||||
var message;
|
||||
InvalidFormatException(this.message);
|
||||
}
|
||||
|
||||
class UnknownException {
|
||||
var message;
|
||||
UnknownException(this.message);
|
||||
}
|
||||
Reference in New Issue
Block a user