Skip to content

Commit

Permalink
add: ping to dart sdk.
Browse files Browse the repository at this point in the history
  • Loading branch information
ItzNotABug committed Dec 13, 2024
1 parent 475a5df commit b30d003
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
3 changes: 3 additions & 0 deletions templates/dart/lib/src/client.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ abstract class Client {
/// Add headers that should be sent with all API calls.
Client addHeader(String key, String value);

/// Sends a "ping" request to Appwrite to verify connectivity.
Future<String> ping();

/// Upload a file in chunks.
Future<Response> chunkedUpload({
required String path,
Expand Down
3 changes: 3 additions & 0 deletions templates/dart/lib/src/client_base.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ abstract class ClientBase implements Client {
@override
ClientBase addHeader(String key, String value);

@override
Future<String> ping();

@override
Future<Response> call(
HttpMethod method, {
Expand Down
8 changes: 8 additions & 0 deletions templates/dart/lib/src/client_browser.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ class ClientBrowser extends ClientBase with ClientMixin {
return this;
}

@override
Future<String> ping() async {
final String apiPath = '/ping';
final response = await call(HttpMethod.get, path: apiPath, responseType: ResponseType.plain);

return response.data;
}

@override
Future<String?> webAuth(Uri url) async {
final request = http.Request('GET', url);
Expand Down
8 changes: 8 additions & 0 deletions templates/dart/lib/src/client_io.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ class ClientIO extends ClientBase with ClientMixin {
return this;
}

@override
Future<String> ping() async {
final String apiPath = '/ping';
final response = await call(HttpMethod.get, path: apiPath, responseType: ResponseType.plain);

return response.data;
}

@override
Future<Response> chunkedUpload({
required String path,
Expand Down
1 change: 1 addition & 0 deletions tests/DartBetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DartBetaTest extends Base
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/dart dart:beta sh -c "dart pub get && dart pub run tests/tests.dart"';

protected array $expectedOutput = [
...Base::PING_RESPONSE,
...Base::FOO_RESPONSES,
...Base::BAR_RESPONSES,
...Base::GENERAL_RESPONSES,
Expand Down
1 change: 1 addition & 0 deletions tests/DartStableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DartStableTest extends Base
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/dart dart:stable sh -c "dart pub get && dart pub run tests/tests.dart"';

protected array $expectedOutput = [
...Base::PING_RESPONSE,
...Base::FOO_RESPONSES,
...Base::BAR_RESPONSES,
...Base::GENERAL_RESPONSES,
Expand Down
20 changes: 19 additions & 1 deletion tests/languages/dart/tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import '../lib/enums.dart';
import '../lib/src/input_file.dart';

import 'dart:io';
import 'dart:convert';

void main() async {
Client client = Client().setSelfSigned();
Expand All @@ -15,7 +16,16 @@ void main() async {
client.setSelfSigned();

print('\nTest Started');


// Ping pong test
client.setProject('123456');
final ping = await client.ping();
final pingResponse = parse(ping)!;
print(pingResponse);

// reset project.
client.setProject('console');

// Foo Tests
Mock response;
response = await foo.get(x: 'string', y: 123, z: ['string in array']);
Expand Down Expand Up @@ -164,3 +174,11 @@ void main() async {
response = await general.headers();
print(response.result);
}

String? parse(String json) {
try {
return jsonDecode(json)['result'] as String?;
} catch (_) {
return null;
}
}

0 comments on commit b30d003

Please sign in to comment.