File tree Expand file tree Collapse file tree 7 files changed +43
-4
lines changed
templates/flutter/lib/src Expand file tree Collapse file tree 7 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,9 @@ abstract class Client {
65
65
/// Add headers that should be sent with all API calls.
66
66
Client addHeader(String key, String value);
67
67
68
+ /// Sends a "ping" request to Appwrite to verify connectivity.
69
+ Future<String > ping();
70
+
68
71
/// Send the API request.
69
72
Future<Response > call(HttpMethod method, {
70
73
String path = '',
Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ abstract class ClientBase implements Client {
23
23
@override
24
24
ClientBase addHeader(String key, String value);
25
25
26
+ @override
27
+ Future<String > ping();
28
+
26
29
@override
27
30
Future<Response > call(
28
31
HttpMethod method, {
Original file line number Diff line number Diff line change @@ -98,6 +98,14 @@ class ClientBrowser extends ClientBase with ClientMixin {
98
98
return this;
99
99
}
100
100
101
+ @override
102
+ Future<String > ping() async {
103
+ final String apiPath = '/ping';
104
+ final response = await call(HttpMethod.get, responseType: ResponseType.plain);
105
+
106
+ return response.data;
107
+ }
108
+
101
109
Future init() async {
102
110
final cookieFallback = web.window.localStorage['cookieFallback'];
103
111
if (cookieFallback != null) {
Original file line number Diff line number Diff line change @@ -130,6 +130,14 @@ class ClientIO extends ClientBase with ClientMixin {
130
130
return this;
131
131
}
132
132
133
+ @override
134
+ Future<String > ping() async {
135
+ final String apiPath = '/ping';
136
+ final response = await call(HttpMethod.get, responseType: ResponseType.plain);
137
+
138
+ return response.data;
139
+ }
140
+
133
141
Future init() async {
134
142
if(_initProgress) return;
135
143
_initProgress = true;
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ class FlutterBetaTest extends Base
19
19
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/flutter fischerscode/flutter-sudo:beta sh -c "sudo chown -R flutter:flutter . && flutter pub get && flutter test test/appwrite_test.dart" ' ;
20
20
21
21
protected array $ expectedOutput = [
22
+ ...Base::PING_RESPONSE ,
22
23
...Base::FOO_RESPONSES ,
23
24
...Base::BAR_RESPONSES ,
24
25
...Base::GENERAL_RESPONSES ,
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ class FlutterStableTest extends Base
19
19
'docker run --network="mockapi" --rm -v $(pwd):/app:rw -w /app/tests/sdks/flutter fischerscode/flutter-sudo:stable sh -c "sudo chown -R flutter:flutter . && flutter pub get && flutter test test/appwrite_test.dart" ' ;
20
20
21
21
protected array $ expectedOutput = [
22
+ ...Base::PING_RESPONSE ,
22
23
...Base::FOO_RESPONSES ,
23
24
...Base::BAR_RESPONSES ,
24
25
...Base::GENERAL_RESPONSES ,
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import '../lib/models.dart';
7
7
import '../lib/enums.dart' ;
8
8
import '../lib/src/input_file.dart' ;
9
9
import 'dart:io' ;
10
+ import 'dart:convert' ;
10
11
11
12
class FakePathProvider extends PathProviderPlatform {
12
13
@override
@@ -20,17 +21,23 @@ void main() async {
20
21
WidgetsFlutterBinding .ensureInitialized ();
21
22
PathProviderPlatform .instance = FakePathProvider ();
22
23
Client client = Client ()
24
+ .setProject ('123456' )
23
25
.addHeader ("Origin" , "http://localhost" )
24
26
.setSelfSigned ();
25
- Foo foo = Foo (client);
26
- Bar bar = Bar (client);
27
- General general = General (client);
28
27
29
- client.setSelfSigned ();
28
+ final ping = await client.ping ();
29
+ final pingResponse = parse (ping)! ;
30
+ print (pingResponse);
31
+
32
+ // reset configs
30
33
client.setProject ('console' );
31
34
client.setEndPointRealtime (
32
35
"wss://cloud.appwrite.io/v1" );
33
36
37
+ Foo foo = Foo (client);
38
+ Bar bar = Bar (client);
39
+ General general = General (client);
40
+
34
41
Realtime realtime = Realtime (client);
35
42
final rtsub = realtime.subscribe (["tests" ]);
36
43
@@ -189,3 +196,11 @@ void main() async {
189
196
response = await general.headers ();
190
197
print (response.result);
191
198
}
199
+
200
+ String ? parse (String json) {
201
+ try {
202
+ return jsonDecode (json)['result' ] as String ? ;
203
+ } catch (_) {
204
+ return null ;
205
+ }
206
+ }
You can’t perform that action at this time.
0 commit comments