Skip to content

Commit cb8bed0

Browse files
committed
Improved code quality and added support for private files
1 parent 75746a7 commit cb8bed0

27 files changed

+193
-193
lines changed

.travis.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
language: dart
2+
3+
dart: stable
4+
5+
os: linux
6+
7+
install:
8+
- mkdir -p ~/.pub-cache
9+
- |
10+
cat <<EOF > ~/.pub-cache/credentials.json
11+
{
12+
"accessToken":"$PUB_ACCESS_TOKEN",
13+
"refreshToken":"$PUB_REFRESH_TOKEN",
14+
"tokenEndpoint":"$PUB_TOKEN_EDNPOINT",
15+
"scopes":["https://www.googleapis.com/auth/plus.me","https://www.googleapis.com/auth/userinfo.email"],
16+
"expiration":$PUB_EXPIRATION
17+
}
18+
19+
deploy:
20+
provider: script
21+
skip_cleanup: true
22+
script: pub publish -f
23+
on:
24+
tags: true

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 0.3.0
2+
3+
- Improved code quality
4+
- Added a custom Appwrite exception
5+
- Enabled access to private storage file
6+
7+
## 0.2.0
8+
9+
- Upgraded to work with Appwrite 0.7
10+
111
## 0.1.0
212

313
- First release

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Add this to your package's `pubspec.yaml` file:
2323

2424
```yml
2525
dependencies:
26-
dart_appwrite: ^0.2.0
26+
dart_appwrite: ^0.3.0
2727
```
2828
2929
You can install packages from the command line:

docs/examples/avatars/get-browser.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ void main() { // Init SDK
1010
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
1111
;
1212

13-
String result = avatars.getBrowser(
13+
Future result = avatars.getBrowser(
1414
code: 'aa',
1515
);
1616

17-
print(result); // Resource URL string
17+
result
18+
.then((response) {
19+
print(response);
20+
}).catchError((error) {
21+
print(error.response);
22+
});
1823
}

docs/examples/avatars/get-credit-card.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ void main() { // Init SDK
1010
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
1111
;
1212

13-
String result = avatars.getCreditCard(
13+
Future result = avatars.getCreditCard(
1414
code: 'amex',
1515
);
1616

17-
print(result); // Resource URL string
17+
result
18+
.then((response) {
19+
print(response);
20+
}).catchError((error) {
21+
print(error.response);
22+
});
1823
}

docs/examples/avatars/get-favicon.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ void main() { // Init SDK
1010
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
1111
;
1212

13-
String result = avatars.getFavicon(
13+
Future result = avatars.getFavicon(
1414
url: 'https://example.com',
1515
);
1616

17-
print(result); // Resource URL string
17+
result
18+
.then((response) {
19+
print(response);
20+
}).catchError((error) {
21+
print(error.response);
22+
});
1823
}

docs/examples/avatars/get-flag.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ void main() { // Init SDK
1010
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
1111
;
1212

13-
String result = avatars.getFlag(
13+
Future result = avatars.getFlag(
1414
code: 'af',
1515
);
1616

17-
print(result); // Resource URL string
17+
result
18+
.then((response) {
19+
print(response);
20+
}).catchError((error) {
21+
print(error.response);
22+
});
1823
}

docs/examples/avatars/get-image.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ void main() { // Init SDK
1010
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
1111
;
1212

13-
String result = avatars.getImage(
13+
Future result = avatars.getImage(
1414
url: 'https://example.com',
1515
);
1616

17-
print(result); // Resource URL string
17+
result
18+
.then((response) {
19+
print(response);
20+
}).catchError((error) {
21+
print(error.response);
22+
});
1823
}

docs/examples/avatars/get-initials.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ void main() { // Init SDK
1010
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
1111
;
1212

13-
String result = avatars.getInitials(
13+
Future result = avatars.getInitials(
1414
);
1515

16-
print(result); // Resource URL string
16+
result
17+
.then((response) {
18+
print(response);
19+
}).catchError((error) {
20+
print(error.response);
21+
});
1722
}

docs/examples/avatars/get-q-r.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ void main() { // Init SDK
1010
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
1111
;
1212

13-
String result = avatars.getQR(
13+
Future result = avatars.getQR(
1414
text: '[TEXT]',
1515
);
1616

17-
print(result); // Resource URL string
17+
result
18+
.then((response) {
19+
print(response);
20+
}).catchError((error) {
21+
print(error.response);
22+
});
1823
}

docs/examples/storage/get-file-download.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ void main() { // Init SDK
1010
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
1111
;
1212

13-
String result = storage.getFileDownload(
13+
Future result = storage.getFileDownload(
1414
fileId: '[FILE_ID]',
1515
);
1616

17-
print(result); // Resource URL string
17+
result
18+
.then((response) {
19+
print(response);
20+
}).catchError((error) {
21+
print(error.response);
22+
});
1823
}

docs/examples/storage/get-file-preview.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ void main() { // Init SDK
1010
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
1111
;
1212

13-
String result = storage.getFilePreview(
13+
Future result = storage.getFilePreview(
1414
fileId: '[FILE_ID]',
1515
);
1616

17-
print(result); // Resource URL string
17+
result
18+
.then((response) {
19+
print(response);
20+
}).catchError((error) {
21+
print(error.response);
22+
});
1823
}

docs/examples/storage/get-file-view.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ void main() { // Init SDK
1010
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
1111
;
1212

13-
String result = storage.getFileView(
13+
Future result = storage.getFileView(
1414
fileId: '[FILE_ID]',
1515
);
1616

17-
print(result); // Resource URL string
17+
result
18+
.then((response) {
19+
print(response);
20+
}).catchError((error) {
21+
print(error.response);
22+
});
1823
}

lib/client.dart

+26-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import 'dart:io';
2-
import 'package:dio/dio.dart';
3-
import 'package:dio/adapter.dart';
4-
5-
import 'enums.dart';
1+
part of dart_appwrite;
62

73
class Client {
84
String endPoint;
@@ -17,7 +13,7 @@ class Client {
1713

1814
this.headers = {
1915
'content-type': 'application/json',
20-
'x-sdk-version': 'appwrite:dart:0.2.0',
16+
'x-sdk-version': 'appwrite:dart:0.3.0',
2117
};
2218

2319
this.config = {};
@@ -70,7 +66,7 @@ class Client {
7066
}
7167
}
7268

73-
Future<Response> call(HttpMethod method, {String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}}) async {
69+
Future<Response> call(HttpMethod method, {String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}, ResponseType responseType}) async {
7470
if(selfSigned) {
7571
// Allow self signed requests
7672
(http.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (HttpClient client) {
@@ -85,20 +81,30 @@ class Client {
8581
Options options = Options(
8682
headers: {...this.headers, ...headers},
8783
method: method.name(),
84+
responseType: responseType
8885
);
89-
90-
if(headers['content-type'] == 'multipart/form-data') {
91-
return http.request(path, data: FormData.fromMap(params), options: options);
92-
}
93-
94-
if (method == HttpMethod.get) {
95-
params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
96-
params[key] = params[key].toString();
97-
}});
98-
99-
return http.get(path, queryParameters: params, options: options);
100-
} else {
101-
return http.request(path, data: params, options: options);
86+
try {
87+
88+
if(headers['content-type'] == 'multipart/form-data') {
89+
return http.request(path, data: FormData.fromMap(params), options: options);
90+
}
91+
92+
if (method == HttpMethod.get) {
93+
params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
94+
params[key] = params[key].toString();
95+
}});
96+
97+
return http.get(path, queryParameters: params, options: options);
98+
} else {
99+
return http.request(path, data: params, options: options);
100+
}
101+
} on DioError catch(e) {
102+
if(e.response == null) {
103+
throw AppwriteException(e.message);
104+
}
105+
throw AppwriteException(e.response.data['message'],e.response.data['code'], e.response.data);
106+
} catch(e) {
107+
throw AppwriteException(e.message);
102108
}
103109
}
104110
}

lib/dart_appwrite.dart

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1+
library dart_appwrite;
2+
3+
import 'dart:io';
4+
import 'package:dio/dio.dart';
5+
import 'package:meta/meta.dart';
6+
import 'package:dio/adapter.dart';
7+
8+
19
export 'package:dio/dio.dart' show Response, MultipartFile;
210

3-
export 'client.dart';
4-
export 'enums.dart';
5-
export 'services/avatars.dart';
6-
export 'services/database.dart';
7-
export 'services/functions.dart';
8-
export 'services/health.dart';
9-
export 'services/locale.dart';
10-
export 'services/storage.dart';
11-
export 'services/teams.dart';
12-
export 'services/users.dart';
11+
part 'client.dart';
12+
part 'enums.dart';
13+
part 'service.dart';
14+
part 'exception.dart';
15+
part 'services/avatars.dart';
16+
part 'services/database.dart';
17+
part 'services/functions.dart';
18+
part 'services/health.dart';
19+
part 'services/locale.dart';
20+
part 'services/storage.dart';
21+
part 'services/teams.dart';
22+
part 'services/users.dart';

lib/enums.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
part of dart_appwrite;
2+
13
enum HttpMethod { get, post, put, delete, patch }
24

35
extension HttpMethodString on HttpMethod {

lib/exception.dart

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
part of dart_appwrite;
2+
3+
class AppwriteException implements Exception {
4+
final String message;
5+
final int code;
6+
final dynamic response;
7+
8+
AppwriteException([this.message = "", this.code, this.response]);
9+
10+
}

lib/service.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'client.dart';
1+
part of dart_appwrite;
22

33
class Service {
44
final Client client;

0 commit comments

Comments
 (0)