Skip to content

Commit d6b3dcc

Browse files
Merge pull request #1147 from nextcloud/refactor/nextcloud/docs
Update nextcloud package docs
2 parents dd0fdd9 + 489ffcb commit d6b3dcc

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

packages/nextcloud/README.md

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# nextcloud
22

3-
A Nextcloud client written in Dart.
3+
A Nextcloud API client written in Dart.
44

5-
This client will become the replacement for https://github.com/provokateurin/dart-nextcloud at some point ([See](https://github.com/nextcloud/neon/issues/1)).
6-
7-
8-
## Installing
5+
## Installation
96

107
In the future this code will be available at https://pub.dev/packages/nextcloud, but for now you have to include it via git in your pubspec.yaml:
118
```yaml
@@ -25,15 +22,45 @@ dependency_overrides:
2522
```
2623
You can either remove the `ref` or use a commit hash. It's not recommended to remove it, because then the version will be updated very often.
2724

28-
## Development
25+
## Usage
26+
27+
### Authentication
2928

30-
Except for WebDAV all client code is generated using OpenAPI specs which can be found in the `../../specs/` folder.
31-
Templates for these OpenAPI specs are generated from the Nextcloud codebase to make development easier.
29+
There are multiple ways to authenticate.
30+
First there is HTTP Basic auth which works with the normal user credentials (e-mail and other identifiers also work):
31+
```dart
32+
final client = NextcloudClient(
33+
Uri.parse('http://localhost'),
34+
loginName: 'admin',
35+
password: 'admin',
36+
);
37+
```
38+
39+
Secondly there is Http Bearer auth which works with app passwords:
40+
```dart
41+
final client = NextcloudClient(
42+
Uri.parse('http://localhost'),
43+
loginName: 'admin',
44+
appPassword: 'xxxxx-xxxxx-xxxxx-xxxx-xxxxx',
45+
);
46+
```
3247

33-
To generate such a template take a look at `../../tool/generate-nextcloud.sh`.
34-
After you have generated a template, you need to fill it out. Some endpoints can or have to be discarded.
48+
Not all endpoints work with just HTTP Basic auth, so it is advised to use app passwords obtained either directly in the Web UI by the user or using the [login flow](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/LoginFlow/index.html#login-flow-v2).
49+
Some endpoints do not need any authentication at all or provide extended information when the request is optionally authenticated.
3550

36-
Then you start writing tests for the endpoints you added.
37-
To easily inspect the responses for an endpoint, just set the `type` to `string` inside the `schema` blocks of the spec and let the output be printed in the tests.
51+
### Endpoints
52+
53+
It is not guaranteed that an API request will work unless the app is installed and enabled on the server (and has a supported version).
54+
55+
To get an easier overview of the available endpoints you can browse the [server OpenAPI documentation](https://docs.nextcloud.com/server/latest/developer_manual/_static/openapi.html), but be aware that the package might not be in sync with it.
56+
Alternatively you can also go to https://pub.dev/documentation/nextcloud/latest (once the package has been republished at https://pub.dev/packages/nextcloud).
57+
58+
The endpoints are grouped by app and most apps also group their endpoints again.
59+
They can be accessed using getters on the `NextcloudClient`.
60+
61+
For an example checkout the [example](./example/example.dart).
62+
63+
## Development
3864

39-
Sometimes you will have to look at the source code of Nextcloud, because the API is not always intuitive. Make sure to check if there is any API documentation that can help you.
65+
Except for WebDAV all client code is generated using OpenAPI specifications which can be found in the `lib/src/api/` folder.
66+
These OpenAPI specifications are [generated](https://github.com/nextcloud/openapi-extractor) from the PHP source code.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:nextcloud/nextcloud.dart';
2+
import 'package:nextcloud/provisioning_api.dart';
3+
4+
Future<void> main() async {
5+
final client = NextcloudClient(
6+
Uri.parse('http://localhost'),
7+
loginName: 'admin',
8+
password: 'admin',
9+
);
10+
11+
final response = await client.provisioningApi.users.getCurrentUser();
12+
print(response.body.ocs.data.id); // Will print `admin`
13+
}

0 commit comments

Comments
 (0)