28 lines
777 B
Dart
28 lines
777 B
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import '../nextcloud_ocs.dart';
|
|
import 'autocompleteResponse.dart';
|
|
|
|
class AutocompleteApi {
|
|
Future<AutocompleteResponse> find(String query) async {
|
|
final endpoint = NextcloudOcs.uri(
|
|
'core/autocomplete/get',
|
|
queryParameters: {
|
|
'search': query,
|
|
'itemType': ' ',
|
|
'itemId': ' ',
|
|
'shareTypes[]': ['0'],
|
|
'limit': '10',
|
|
},
|
|
);
|
|
final response = await http.get(endpoint, headers: NextcloudOcs.headers());
|
|
if (response.statusCode != HttpStatus.ok) {
|
|
throw Exception('Api call failed with ${response.statusCode}: ${response.body}');
|
|
}
|
|
return AutocompleteResponse.fromJson(jsonDecode(response.body)['ocs']);
|
|
}
|
|
}
|