Skip to content

Commit 9e9c7f3

Browse files
committed
add: ping to flutter sdk.
1 parent cc1da05 commit 9e9c7f3

File tree

7 files changed

+43
-4
lines changed

7 files changed

+43
-4
lines changed

templates/flutter/lib/src/client.dart.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ abstract class Client {
6565
/// Add headers that should be sent with all API calls.
6666
Client addHeader(String key, String value);
6767

68+
/// Sends a "ping" request to Appwrite to verify connectivity.
69+
Future<String> ping();
70+
6871
/// Send the API request.
6972
Future<Response> call(HttpMethod method, {
7073
String path = '',

templates/flutter/lib/src/client_base.dart.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ abstract class ClientBase implements Client {
2323
@override
2424
ClientBase addHeader(String key, String value);
2525

26+
@override
27+
Future<String> ping();
28+
2629
@override
2730
Future<Response> call(
2831
HttpMethod method, {

templates/flutter/lib/src/client_browser.dart.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ class ClientBrowser extends ClientBase with ClientMixin {
9898
return this;
9999
}
100100

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+
101109
Future init() async {
102110
final cookieFallback = web.window.localStorage['cookieFallback'];
103111
if (cookieFallback != null) {

templates/flutter/lib/src/client_io.dart.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ class ClientIO extends ClientBase with ClientMixin {
130130
return this;
131131
}
132132

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+
133141
Future init() async {
134142
if(_initProgress) return;
135143
_initProgress = true;

tests/FlutterBetaTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class FlutterBetaTest extends Base
1919
'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"';
2020

2121
protected array $expectedOutput = [
22+
...Base::PING_RESPONSE,
2223
...Base::FOO_RESPONSES,
2324
...Base::BAR_RESPONSES,
2425
...Base::GENERAL_RESPONSES,

tests/FlutterStableTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class FlutterStableTest extends Base
1919
'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"';
2020

2121
protected array $expectedOutput = [
22+
...Base::PING_RESPONSE,
2223
...Base::FOO_RESPONSES,
2324
...Base::BAR_RESPONSES,
2425
...Base::GENERAL_RESPONSES,

tests/languages/flutter/tests.dart

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import '../lib/models.dart';
77
import '../lib/enums.dart';
88
import '../lib/src/input_file.dart';
99
import 'dart:io';
10+
import 'dart:convert';
1011

1112
class FakePathProvider extends PathProviderPlatform {
1213
@override
@@ -20,17 +21,23 @@ void main() async {
2021
WidgetsFlutterBinding.ensureInitialized();
2122
PathProviderPlatform.instance = FakePathProvider();
2223
Client client = Client()
24+
.setProject('123456')
2325
.addHeader("Origin", "http://localhost")
2426
.setSelfSigned();
25-
Foo foo = Foo(client);
26-
Bar bar = Bar(client);
27-
General general = General(client);
2827

29-
client.setSelfSigned();
28+
final ping = await client.ping();
29+
final pingResponse = parse(ping)!;
30+
print(pingResponse);
31+
32+
// reset configs
3033
client.setProject('console');
3134
client.setEndPointRealtime(
3235
"wss://cloud.appwrite.io/v1");
3336

37+
Foo foo = Foo(client);
38+
Bar bar = Bar(client);
39+
General general = General(client);
40+
3441
Realtime realtime = Realtime(client);
3542
final rtsub = realtime.subscribe(["tests"]);
3643

@@ -189,3 +196,11 @@ void main() async {
189196
response = await general.headers();
190197
print(response.result);
191198
}
199+
200+
String? parse(String json) {
201+
try {
202+
return jsonDecode(json)['result'] as String?;
203+
} catch (_) {
204+
return null;
205+
}
206+
}

0 commit comments

Comments
 (0)