Browse Source

nextcloud: Add methods to check if app is supported

pull/62/head
jld3103 2 years ago
parent
commit
7afb4b2f9e
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 7
      packages/neon/pubspec.lock
  2. 2
      packages/nextcloud/lib/nextcloud.dart
  3. 32
      packages/nextcloud/lib/src/version_supported.dart
  4. 1
      packages/nextcloud/pubspec.yaml
  5. 6
      packages/nextcloud/test/core_test.dart
  6. 5
      packages/nextcloud/test/news_test.dart
  7. 5
      packages/nextcloud/test/notes_test.dart

7
packages/neon/pubspec.lock

@ -1226,6 +1226,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.2" version: "2.1.2"
version:
dependency: transitive
description:
name: version
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
vm_service: vm_service:
dependency: transitive dependency: transitive
description: description:

2
packages/nextcloud/lib/nextcloud.dart

@ -7,6 +7,7 @@ import 'dart:typed_data';
import 'package:crypto/crypto.dart'; import 'package:crypto/crypto.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/nextcloud.dart';
import 'package:version/version.dart';
import 'package:xml/xml.dart' as xml; import 'package:xml/xml.dart' as xml;
export 'package:crypton/crypton.dart' show RSAKeypair, RSAPublicKey, RSAPrivateKey; export 'package:crypton/crypton.dart' show RSAKeypair, RSAPublicKey, RSAPrivateKey;
@ -16,6 +17,7 @@ export 'src/nextcloud.openapi.dart';
part 'src/app_type.dart'; part 'src/app_type.dart';
part 'src/client.dart'; part 'src/client.dart';
part 'src/helpers.dart'; part 'src/helpers.dart';
part 'src/version_supported.dart';
part 'src/webdav/client.dart'; part 'src/webdav/client.dart';
part 'src/webdav/file.dart'; part 'src/webdav/file.dart';
part 'src/webdav/props.dart'; part 'src/webdav/props.dart';

32
packages/nextcloud/lib/src/version_supported.dart

@ -0,0 +1,32 @@
part of '../nextcloud.dart';
// ignore: public_member_api_docs
extension CoreVersionSupported on CoreClient {
/// Checks if the app on the server is supported by the client
Future<bool> isSupported([final CoreServerCapabilitiesOcsData? capabilities]) async =>
(capabilities ?? (await rootClient.core.getCapabilities()).ocs!.data!).version!.major! == 24;
}
// ignore: public_member_api_docs
extension NewsVersionSupported on NewsClient {
/// Checks if the app on the server is supported by the client
Future<bool> isSupported() async {
final versions = await getSupportedApiVersions();
return versions.apiLevels!.contains('v1-2');
}
}
// ignore: public_member_api_docs
extension NotesVersionSupported on NotesClient {
/// Checks if the app on the server is supported by the client
Future<bool> isSupported([final CoreServerCapabilitiesOcsData? capabilities]) async =>
(capabilities ?? (await rootClient.core.getCapabilities()).ocs!.data!)
.capabilities!
.notes!
.apiVersion!
.map(Version.parse)
.where((final version) => version.major == 1)
.isNotEmpty;
}
// Notifications, ProvisioningApi, UserStatus and Webdav are shipped with the Nextcloud server, so their supported versions depend on the major version of the Nextcloud instance.

1
packages/nextcloud/pubspec.yaml

@ -11,6 +11,7 @@ dependencies:
intl: ^0.17.0 intl: ^0.17.0
json_annotation: ^4.6.0 json_annotation: ^4.6.0
meta: ^1.7.0 meta: ^1.7.0
version: ^3.0.2
xml: ^6.1.0 xml: ^6.1.0
dev_dependencies: dev_dependencies:

6
packages/nextcloud/test/core_test.dart

@ -1,3 +1,4 @@
import 'package:nextcloud/nextcloud.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'helper.dart'; import 'helper.dart';
@ -17,6 +18,11 @@ Future main() async {
}); });
tearDown(() => client.destroy()); tearDown(() => client.destroy());
test('Is supported', () async {
final response = await client.core.isSupported();
expect(response, isTrue);
});
test('Get status', () async { test('Get status', () async {
final status = await client.core.getStatus(); final status = await client.core.getStatus();
expect(status.installed, true); expect(status.installed, true);

5
packages/nextcloud/test/news_test.dart

@ -25,6 +25,11 @@ Future main() async {
url: nasaFeedURL, url: nasaFeedURL,
); );
test('Is supported', () async {
final response = await client.news.isSupported();
expect(response, isTrue);
});
test('Add feed', () async { test('Add feed', () async {
var response = await client.news.listFeeds(); var response = await client.news.listFeeds();
expect(response.starredCount, 0); expect(response.starredCount, 0);

5
packages/nextcloud/test/notes_test.dart

@ -13,6 +13,11 @@ Future main() async {
}); });
tearDown(() => client.destroy()); tearDown(() => client.destroy());
test('Is supported', () async {
final response = await client.notes.isSupported();
expect(response, isTrue);
});
test('Create note favorite', () async { test('Create note favorite', () async {
final response = await client.notes.createNote( final response = await client.notes.createNote(
title: 'a', title: 'a',

Loading…
Cancel
Save