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 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> loginAPI(String user, String password) async { http.Response response = await http.post( Uri.encodeFull(_baseUrl + "/api/v1/Login"), body: jsonEncode({ 'user': user, 'password': password, }), ).timeout(Duration(seconds: 10)); // TODO: // - StatusCode: // - 405 (StatusMethodNotAllowed) // - 400 (StatusBadRequest) // - 401 (StatusUnauthorized) // - // - // - String setCookieVal = response.headers["set-cookie"]; List 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 mediaItemsAPI(String albumID, String tagID) async { return null; } Future tagsAPI() async { return null; } Future albumsAPI() async { return null; } Future meAPI() async { return null; } // API Calls: // - Login // - MediaItems // - Tags // - Albums // - Me }