11import 'dart:io';
2-
32import 'package:dio/dio.dart';
43import 'package:dio/adapter.dart';
5- import 'package:dio_cookie_manager/dio_cookie_manager.dart';
6- import 'package:cookie_jar/cookie_jar.dart';
7- import 'package:path_provider/path_provider.dart';
8- import 'package:package_info/package_info.dart';
94
105import 'enums.dart';
116
@@ -17,16 +12,8 @@ class Client {
1712 bool selfSigned;
1813 bool initialized = false;
1914 Dio http;
20- PersistCookieJar cookieJar;
2115
22- Client({this.endPoint = 'https://appwrite.io/v1', this.selfSigned = false, Dio http}) : this.http = http ?? Dio() {
23-
24- type = (Platform.isIOS) ? 'ios' : type;
25- type = (Platform.isMacOS) ? 'macos' : type;
26- type = (Platform.isAndroid) ? 'android' : type;
27- type = (Platform.isLinux) ? 'linux' : type;
28- type = (Platform.isWindows) ? 'windows' : type;
29- type = (Platform.isFuchsia) ? 'fuchsia' : type;
16+ Client({this.endPoint = '{{spec .endpoint }}', this.selfSigned = false, Dio http}) : this.http = http ?? Dio() {
3017
3118 this.headers = {
3219 'content-type': 'application/json',
@@ -37,14 +24,7 @@ class Client {
3724
3825 assert(endPoint.startsWith(RegExp("http://|https://")), "endPoint $endPoint must start with 'http'");
3926 }
40-
41- Future<Directory > _getCookiePath() async {
42- final directory = await getApplicationDocumentsDirectory();
43- final path = directory.path;
44- final Directory dir = new Directory('$path/cookies');
45- await dir.create();
46- return dir;
47- }
27+
4828
4929{% for header in spec .global .headers %}
5030{% if header .description %}
@@ -76,17 +56,8 @@ class Client {
7656
7757 Future init() async {
7858 if(!initialized) {
79- final Directory cookieDir = await _getCookiePath();
80-
81- cookieJar = new PersistCookieJar(dir:cookieDir.path);
82-
8359 this.http.options.baseUrl = this.endPoint;
8460 this.http.options.validateStatus = (status) => status < 400;
85- this.http.interceptors.add(CookieManager(cookieJar));
86-
87- PackageInfo packageInfo = await PackageInfo.fromPlatform();
88-
89- addHeader('Origin', 'appwrite-' + type + '://' + packageInfo.packageName);
9061 }
9162 }
9263
@@ -112,6 +83,10 @@ class Client {
11283 }
11384
11485 if (method == HttpMethod.get) {
86+ params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
87+ params[key] = params[key].toString();
88+ }});
89+
11590 return http.get(path, queryParameters: params, options: options);
11691 } else {
11792 return http.request(path, data: params, options: options);
0 commit comments