Skip to content

Commit e9e991a

Browse files
committed
feat: update version
1 parent 3579314 commit e9e991a

File tree

11 files changed

+249
-76
lines changed

11 files changed

+249
-76
lines changed

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
# Appwrite Flutter SDK
22

3-
[![pub package](https://img.shields.io/pub/v/appwrite?style=flat-square.svg)](https://pub.dartlang.org/packages/appwrite)
3+
[![pub package](https://img.shields.io/pub/v/appwrite?style=flat-square)](https://pub.dartlang.org/packages/appwrite)
44
![License](https://img.shields.io/github/license/appwrite/sdk-for-flutter.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-0.8.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-0.9.0-blue.svg?style=flat-square)
6+
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
67
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite_io?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite_io)
78
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
89

9-
**This SDK is compatible with Appwrite server version 0.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-flutter/releases).**
10+
**This SDK is compatible with Appwrite server version 0.9.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-flutter/releases).**
1011

11-
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way.
12-
Use the Flutter SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools.
13-
For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
12+
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Flutter SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
1413

1514

1615

@@ -22,7 +21,7 @@ Add this to your package's `pubspec.yaml` file:
2221

2322
```yml
2423
dependencies:
25-
appwrite: ^0.6.4
24+
appwrite: ^0.7.0
2625
```
2726
2827
You can install packages from the command line:
@@ -57,7 +56,7 @@ The Appwrite SDK uses ASWebAuthenticationSession on iOS 12+ and SFAuthentication
5756
4. In Deployment Info, 'Target' select iOS 11.0
5857

5958
### Android
60-
In order to capture the Appwrite OAuth callback url, the following activity needs to be added to your [AndroidManifest.xml](https://github.com/appwrite/playground-for-flutter/blob/master/android/app/src/main/AndroidManifest.xml). Be sure to relpace the **[PROJECT_ID]** string with your actual Appwrite project ID. You can find your Appwrite project ID in you project settings screen in your Appwrite console.
59+
In order to capture the Appwrite OAuth callback url, the following activity needs to be added to your [AndroidManifest.xml](https://github.com/appwrite/playground-for-flutter/blob/master/android/app/src/main/AndroidManifest.xml). Be sure to replace the **[PROJECT_ID]** string with your actual Appwrite project ID. You can find your Appwrite project ID in your project settings screen in the console.
6160

6261
```xml
6362
<manifest>
@@ -82,7 +81,7 @@ While running Flutter Web, make sure your Appwrite server and your Flutter clien
8281

8382
### Init your SDK
8483

85-
<p>Initialize your SDK code with your project ID, which can be found in your project settings page.
84+
<p>Initialize your SDK with your Appwrite server API endpoint and project ID, which can be found in your project settings page.
8685

8786
```dart
8887
import 'package:appwrite/appwrite.dart';
@@ -102,7 +101,7 @@ When trying to connect to Appwrite from an emulator or a mobile device, localhos
102101

103102
### Make Your First Request
104103

105-
<p>Once your SDK object is set, access any of the Appwrite services and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the API References section.
104+
<p>Once your SDK object is set, access any of the Appwrite services and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section.
106105

107106
```dart
108107
// Register User
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'package:appwrite/appwrite.dart';
2+
3+
void main() { // Init SDK
4+
Client client = Client();
5+
Account account = Account(client);
6+
7+
client
8+
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
9+
.setProject('5df5acd0d48c2') // Your project ID
10+
;
11+
Future result = account.getSession(
12+
sessionId: '[SESSION_ID]',
13+
);
14+
15+
result
16+
.then((response) {
17+
print(response);
18+
}).catchError((error) {
19+
print(error.response);
20+
});
21+
}

lib/client.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class Client {
2626

2727
this.headers = {
2828
'content-type': 'application/json',
29-
'x-sdk-version': 'appwrite:flutter:0.6.4',
30-
'X-Appwrite-Response-Format' : '0.8.0',
29+
'x-sdk-version': 'appwrite:flutter:0.7.0',
30+
'X-Appwrite-Response-Format' : '0.9.0',
3131
};
3232

3333
this.config = {};
@@ -115,7 +115,7 @@ class Client {
115115
final macinfo = await deviceInfoPlugin.macOsInfo;
116116
device = '(Macintosh; ${macinfo.model})';
117117
}
118-
addHeader('user-agent', '${packageInfo.appName}/${packageInfo.version} $device');
118+
addHeader('user-agent', '${packageInfo.packageName}/${packageInfo.version} $device');
119119
} else {
120120
// if web set withCredentials true to make cookies work
121121
_prefs = await SharedPreferences.getInstance();
@@ -141,7 +141,9 @@ class Client {
141141
await this.init();
142142
}
143143

144-
params.removeWhere((key,value) => value == null);
144+
if(params.isNotEmpty) {
145+
params.removeWhere((key,value) => value == null);
146+
}
145147

146148
// Origin is hardcoded for testing
147149
Options options = Options(

lib/enums.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,3 @@ extension HttpMethodString on HttpMethod {
77
return this.toString().split('.').last.toUpperCase();
88
}
99
}
10-
11-
enum OrderType { asc, desc }
12-
13-
extension OrderTypeString on OrderType {
14-
String name() {
15-
return this.toString().split('.').last.toUpperCase();
16-
}
17-
}

lib/services/account.dart

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ class Account extends Service {
3030
/// login to their new account, you need to create a new [account
3131
/// session](/docs/client/account#accountCreateSession).
3232
///
33-
Future<Response> create({required String email, required String password, String? name}) {
33+
Future<Response> create({required String email
34+
, required String password
35+
, String? name
36+
}) {
3437
final String path = '/account';
3538

3639
final Map<String, dynamic> params = {
@@ -76,7 +79,9 @@ class Account extends Service {
7679
/// This endpoint can also be used to convert an anonymous account to a normal
7780
/// one, by passing an email address and a new password.
7881
///
79-
Future<Response> updateEmail({required String email, required String password}) {
82+
Future<Response> updateEmail({required String email
83+
, required String password
84+
}) {
8085
final String path = '/account/email';
8186

8287
final Map<String, dynamic> params = {
@@ -96,7 +101,8 @@ class Account extends Service {
96101
/// Use this endpoint to create a JSON Web Token. You can use the resulting JWT
97102
/// to authenticate on behalf of the current user when working with the
98103
/// Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes
99-
/// from its creation and will be invalid if the user will logout.
104+
/// from its creation and will be invalid if the user will logout in that time
105+
/// frame.
100106
///
101107
Future<Response> createJWT() {
102108
final String path = '/account/jwt';
@@ -133,7 +139,8 @@ class Account extends Service {
133139
///
134140
/// Update currently logged in user account name.
135141
///
136-
Future<Response> updateName({required String name}) {
142+
Future<Response> updateName({required String name
143+
}) {
137144
final String path = '/account/name';
138145

139146
final Map<String, dynamic> params = {
@@ -153,7 +160,9 @@ class Account extends Service {
153160
/// to pass in the new password, and the old password. For users created with
154161
/// OAuth and Team Invites, oldPassword is optional.
155162
///
156-
Future<Response> updatePassword({required String password, String? oldPassword}) {
163+
Future<Response> updatePassword({required String password
164+
, String? oldPassword
165+
}) {
157166
final String path = '/account/password';
158167

159168
final Map<String, dynamic> params = {
@@ -190,7 +199,8 @@ class Account extends Service {
190199
/// Update currently logged in user account preferences. You can pass only the
191200
/// specific settings you wish to update.
192201
///
193-
Future<Response> updatePrefs({required Map prefs}) {
202+
Future<Response> updatePrefs({required Map prefs
203+
}) {
194204
final String path = '/account/prefs';
195205

196206
final Map<String, dynamic> params = {
@@ -215,7 +225,9 @@ class Account extends Service {
215225
/// complete the process. The verification link sent to the user's email
216226
/// address is valid for 1 hour.
217227
///
218-
Future<Response> createRecovery({required String email, required String url}) {
228+
Future<Response> createRecovery({required String email
229+
, required String url
230+
}) {
219231
final String path = '/account/recovery';
220232

221233
final Map<String, dynamic> params = {
@@ -242,7 +254,11 @@ class Account extends Service {
242254
/// the only valid redirect URLs are the ones from domains you have set when
243255
/// adding your platforms in the console interface.
244256
///
245-
Future<Response> updateRecovery({required String userId, required String secret, required String password, required String passwordAgain}) {
257+
Future<Response> updateRecovery({required String userId
258+
, required String secret
259+
, required String password
260+
, required String passwordAgain
261+
}) {
246262
final String path = '/account/recovery';
247263

248264
final Map<String, dynamic> params = {
@@ -282,7 +298,9 @@ class Account extends Service {
282298
/// Allow the user to login into their account by providing a valid email and
283299
/// password combination. This route will create a new session for the user.
284300
///
285-
Future<Response> createSession({required String email, required String password}) {
301+
Future<Response> createSession({required String email
302+
, required String password
303+
}) {
286304
final String path = '/account/sessions';
287305

288306
final Map<String, dynamic> params = {
@@ -319,9 +337,10 @@ class Account extends Service {
319337
///
320338
/// Use this endpoint to allow a new user to register an anonymous account in
321339
/// your project. This route will also create a new session for the user. To
322-
/// allow the new user to convert an anonymous account to a normal account
323-
/// account, you need to update its [email and
324-
/// password](/docs/client/account#accountUpdateEmail).
340+
/// allow the new user to convert an anonymous account to a normal account, you
341+
/// need to update its [email and
342+
/// password](/docs/client/account#accountUpdateEmail) or create an [OAuth2
343+
/// session](/docs/client/account#accountCreateOAuth2Session).
325344
///
326345
Future<Response> createAnonymousSession() {
327346
final String path = '/account/sessions/anonymous';
@@ -343,7 +362,11 @@ class Account extends Service {
343362
/// first. Use the success and failure arguments to provide a redirect URL's
344363
/// back to your app when login is completed.
345364
///
346-
Future createOAuth2Session({required String provider, String? success, String? failure, List? scopes}) {
365+
Future createOAuth2Session({required String provider
366+
, String? success
367+
, String? failure
368+
, List? scopes
369+
}) {
347370
final String path = '/account/sessions/oauth2/{provider}'.replaceAll(RegExp('{provider}'), provider);
348371

349372
final Map<String, dynamic> params = {
@@ -361,8 +384,7 @@ class Account extends Service {
361384
for (var item in value) {
362385
query.add(Uri.encodeComponent(key + '[]') + '=' + Uri.encodeComponent(item));
363386
}
364-
}
365-
else {
387+
} else if(value != null) {
366388
query.add(Uri.encodeComponent(key) + '=' + Uri.encodeComponent(value));
367389
}
368390
});
@@ -395,6 +417,25 @@ class Account extends Service {
395417
});
396418
}
397419

420+
}
421+
422+
/// Get Session By ID
423+
///
424+
/// Use this endpoint to get a logged in user's session using a Session ID.
425+
/// Inputting 'current' will return the current session being used.
426+
///
427+
Future<Response> getSession({required String sessionId
428+
}) {
429+
final String path = '/account/sessions/{sessionId}'.replaceAll(RegExp('{sessionId}'), sessionId);
430+
431+
final Map<String, dynamic> params = {
432+
};
433+
434+
final Map<String, String> headers = {
435+
'content-type': 'application/json',
436+
};
437+
438+
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
398439
}
399440

400441
/// Delete Account Session
@@ -403,7 +444,8 @@ class Account extends Service {
403444
/// account sessions across all of their different devices. When using the
404445
/// option id argument, only the session unique ID provider will be deleted.
405446
///
406-
Future<Response> deleteSession({required String sessionId}) {
447+
Future<Response> deleteSession({required String sessionId
448+
}) {
407449
final String path = '/account/sessions/{sessionId}'.replaceAll(RegExp('{sessionId}'), sessionId);
408450

409451
final Map<String, dynamic> params = {
@@ -434,7 +476,8 @@ class Account extends Service {
434476
/// adding your platforms in the console interface.
435477
///
436478
///
437-
Future<Response> createVerification({required String url}) {
479+
Future<Response> createVerification({required String url
480+
}) {
438481
final String path = '/account/verification';
439482

440483
final Map<String, dynamic> params = {
@@ -455,7 +498,9 @@ class Account extends Service {
455498
/// to verify the user email ownership. If confirmed this route will return a
456499
/// 200 status code.
457500
///
458-
Future<Response> updateVerification({required String userId, required String secret}) {
501+
Future<Response> updateVerification({required String userId
502+
, required String secret
503+
}) {
459504
final String path = '/account/verification';
460505

461506
final Map<String, dynamic> params = {

0 commit comments

Comments
 (0)