Skip to content

Commit 96aed4f

Browse files
authored
Merge pull request #2 from Almoullim/master
Add dart support
2 parents 609c832 + ae271e6 commit 96aed4f

23 files changed

+1812
-10
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
composer.lock
22
/vendor/
3-
/.idea/
3+
/.idea/
4+
5+
# Dart auto-generated
6+
examples/dart/.packages
7+
examples/dart/pubspec.lock

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,26 @@ $sdk->generate(__DIR__ . '/examples/php'); // Generate source code
6767
## Supported Languages
6868

6969
| Language | Coding Standards | Package Manager | Maintainer |
70-
|------------|------------------|-----------------|------------|
71-
| PHP | [PHP FIG](https://www.php-fig.org/) | Composer | @eldadfux |
72-
| Javascript | [NPM Coding Style](https://docs.npmjs.com/misc/coding-style) | NPM, Yarn, Bower | @eldadfux |
73-
| NodeJS | [NPM Coding Style](https://docs.npmjs.com/misc/coding-style) | NPM, Yarn | @eldadfux |
74-
| Ruby | [Ruby Style Guide](https://github.com/rubocop-hq/ruby-style-guide) | GEM | @eldadfux |
75-
| Python | [PEP8](https://www.python.org/dev/peps/pep-0008/) | PIP | @eldadfux |
76-
| Kotlin | | ? | |
77-
| Swift | | ? | |
70+
|------------|---------------------|--------------------|----------------|
71+
| PHP | [PHP FIG] | Composer | [@eldadfux] |
72+
| Javascript | [NPM Coding Style] | NPM, Yarn, Bower | [@eldadfux] |
73+
| NodeJS | [NPM Coding Style] | NPM, Yarn | [@eldadfux] |
74+
| Ruby | [Ruby Style Guide] | GEM | [@eldadfux] |
75+
| Python | [PEP8] | PIP | [@eldadfux] |
76+
| Dart | [Effective Dart] | pub tool | [@Almoullim] |
77+
| Kotlin | | ? | |
78+
| Swift | | ? | |
79+
80+
[@Almoullim]: https://github.com/Almoullim
81+
[@eldadfux]: https://github.com/eldadfux
82+
83+
[PHP FIG]: https://www.php-fig.org/
84+
[NPM Coding Style]: https://docs.npmjs.com/misc/coding-style
85+
[NPM Coding Style]: https://docs.npmjs.com/misc/coding-style
86+
[Ruby Style Guide]: https://github.com/rubocop-hq/ruby-style-guide
87+
[PEP8]: https://www.python.org/dev/peps/pep-0008/
88+
[Effective Dart]: https://dart.dev/guides/language/effective-dart/style
89+
7890

7991
## Development
8092

example.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
use Appwrite\SDK\Language\PHP;
1010
use Appwrite\SDK\Language\Python;
1111
use Appwrite\SDK\Language\Ruby;
12+
use Appwrite\SDK\Language\Dart;
1213

13-
$languages = ['js', 'node', 'php', 'python', 'ruby'];
14+
$languages = ['js', 'node', 'php', 'python', 'ruby', 'dart'];
1415

1516
try {
1617

@@ -82,6 +83,20 @@ function getSSLPage($url) {
8283
;
8384

8485
$sdk->generate(__DIR__ . '/examples/python');
86+
87+
// Dart
88+
$sdk = new SDK(new Dart(), new Swagger2($spec));
89+
90+
$sdk
91+
->setLogo('https://appwrite.io/v1/images/console.png')
92+
->setLicenseContent('test test test')
93+
->setWarning('**WORK IN PROGRESS - NOT READY FOR USAGE**')
94+
->setVersion('0.0.1')
95+
;
96+
97+
$sdk->generate(__DIR__ . '/examples/dart');
98+
99+
85100
}
86101
catch (Exception $exception) {
87102
echo 'Error: ' . $exception->getMessage() . ' on ' . $exception->getFile() . ':' . $exception->getLine() . "\n";

examples/dart/lib/client.dart

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import 'package:dio/dio.dart';
2+
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
3+
import 'package:cookie_jar/cookie_jar.dart';
4+
5+
class Client {
6+
String endPoint;
7+
Map<String, String> headers;
8+
bool selfSigned;
9+
Dio http;
10+
11+
Client() {
12+
this.endPoint = 'https://appwrite.io/v1';
13+
this.headers = {
14+
'content-type': 'application/json',
15+
'x-sdk-version': 'appwrite:dart:0.0.1',
16+
};
17+
this.selfSigned = false;
18+
19+
this.http = Dio();
20+
this.http.options.baseUrl = this.endPoint;
21+
this.http.options.validateStatus = (status) => status != 404;
22+
this.http.interceptors.add(CookieManager(CookieJar()));
23+
}
24+
25+
26+
/// Your Appwrite project ID. You can find your project ID in your Appwrite console project settings.
27+
Client setProject(value) {
28+
this.addHeader('X-Appwrite-Project', value);
29+
30+
return this;
31+
}
32+
33+
34+
/// Your Appwrite project secret key. You can can create a new API key from your Appwrite console API keys dashboard.
35+
Client setKey(value) {
36+
this.addHeader('X-Appwrite-Key', value);
37+
38+
return this;
39+
}
40+
41+
42+
Client setLocale(value) {
43+
this.addHeader('X-Appwrite-Locale', value);
44+
45+
return this;
46+
}
47+
48+
49+
Client setMode(value) {
50+
this.addHeader('X-Appwrite-Mode', value);
51+
52+
return this;
53+
}
54+
55+
Client setSelfSigned({bool status = true}) {
56+
this.selfSigned = status;
57+
58+
return this;
59+
}
60+
61+
Client setEndpoint(String endPoint)
62+
{
63+
this.endPoint = endPoint;
64+
this.http.options.baseUrl = this.endPoint;
65+
return this;
66+
}
67+
68+
Client addHeader(String key, String value) {
69+
this.headers[key.toLowerCase()] = value.toLowerCase();
70+
71+
return this;
72+
}
73+
74+
Future<Response> call(String method, {String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}}) {
75+
if(this.selfSigned) {
76+
// Allow self signed requests
77+
}
78+
79+
String reqPath = path;
80+
bool isGet = method.toUpperCase() == "GET";
81+
82+
// Origin is hardcoded for testing
83+
Options options = Options(
84+
headers: {...this.headers, ...headers, "Origin": "http://localhost"},
85+
method: method.toUpperCase(),
86+
);
87+
88+
if (isGet) {
89+
path += "?";
90+
params.forEach((k, v) {
91+
path += "${k}=${v}&";
92+
});
93+
}
94+
95+
if (!isGet)
96+
return http.request(reqPath, data: params, options: options);
97+
else
98+
return http.request(reqPath, options: options);
99+
}
100+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export 'package:dart_appwrite/services/account.dart';
2+
export 'package:dart_appwrite/services/auth.dart';
3+
export 'package:dart_appwrite/services/avatars.dart';
4+
export 'package:dart_appwrite/services/database.dart';
5+
export 'package:dart_appwrite/services/locale.dart';
6+
export 'package:dart_appwrite/services/projects.dart';
7+
export 'package:dart_appwrite/services/storage.dart';
8+
export 'package:dart_appwrite/services/teams.dart';
9+
export 'package:dart_appwrite/services/users.dart';
10+
export 'package:dart_appwrite/client.dart';
11+
export 'package:dio/dio.dart' show Response;

examples/dart/lib/service.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import 'package:dart_appwrite/client.dart';
2+
3+
class Service {
4+
Client client;
5+
6+
Service(Client client) {
7+
this.client = client;
8+
}
9+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import "package:dart_appwrite/service.dart";
2+
import "package:dart_appwrite/client.dart";
3+
import 'package:dio/dio.dart';
4+
5+
class Account extends Service {
6+
7+
Account(Client client): super(client);
8+
9+
/// Get currently logged in user data as JSON object.
10+
Future<Response> get() async {
11+
String path = '/account';
12+
13+
Map<String, dynamic> params = {
14+
};
15+
16+
return await this.client.call('get', path: path, params: params);
17+
}
18+
/// Delete currently logged in user account.
19+
Future<Response> delete() async {
20+
String path = '/account';
21+
22+
Map<String, dynamic> params = {
23+
};
24+
25+
return await this.client.call('delete', path: path, params: params);
26+
}
27+
/// Update currently logged in user account email address. After changing user
28+
/// address, user confirmation status is being reset and a new confirmation
29+
/// mail is sent. For security measures, user password is required to complete
30+
/// this request.
31+
Future<Response> updateEmail({email, password}) async {
32+
String path = '/account/email';
33+
34+
Map<String, dynamic> params = {
35+
'email': email,
36+
'password': password,
37+
};
38+
39+
return await this.client.call('patch', path: path, params: params);
40+
}
41+
/// Update currently logged in user account name.
42+
Future<Response> updateName({name}) async {
43+
String path = '/account/name';
44+
45+
Map<String, dynamic> params = {
46+
'name': name,
47+
};
48+
49+
return await this.client.call('patch', path: path, params: params);
50+
}
51+
/// Update currently logged in user password. For validation, user is required
52+
/// to pass the password twice.
53+
Future<Response> updatePassword({password, oldPassword}) async {
54+
String path = '/account/password';
55+
56+
Map<String, dynamic> params = {
57+
'password': password,
58+
'old-password': oldPassword,
59+
};
60+
61+
return await this.client.call('patch', path: path, params: params);
62+
}
63+
/// Get currently logged in user preferences key-value object.
64+
Future<Response> getPrefs() async {
65+
String path = '/account/prefs';
66+
67+
Map<String, dynamic> params = {
68+
};
69+
70+
return await this.client.call('get', path: path, params: params);
71+
}
72+
/// Update currently logged in user account preferences. You can pass only the
73+
/// specific settings you wish to update.
74+
Future<Response> updatePrefs({prefs}) async {
75+
String path = '/account/prefs';
76+
77+
Map<String, dynamic> params = {
78+
'prefs': prefs,
79+
};
80+
81+
return await this.client.call('patch', path: path, params: params);
82+
}
83+
/// Get currently logged in user list of latest security activity logs. Each
84+
/// log returns user IP address, location and date and time of log.
85+
Future<Response> getSecurity() async {
86+
String path = '/account/security';
87+
88+
Map<String, dynamic> params = {
89+
};
90+
91+
return await this.client.call('get', path: path, params: params);
92+
}
93+
/// Get currently logged in user list of active sessions across different
94+
/// devices.
95+
Future<Response> getSessions() async {
96+
String path = '/account/sessions';
97+
98+
Map<String, dynamic> params = {
99+
};
100+
101+
return await this.client.call('get', path: path, params: params);
102+
}
103+
}

0 commit comments

Comments
 (0)