Skip to content

Commit fc22cb4

Browse files
author
WooSignal
committed
v0.1.4 update, class filenames refactored, now throws exceptions from responses plus other varies changes. Read Changelog for more info
1 parent b5c02c5 commit fc22cb4

35 files changed

+793
-200
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## [0.1.4] - 2020-06-16
2+
3+
* Meta data now is returned for users
4+
* Ability to store, update and delete meta data on WP_User
5+
* Throw exceptions for requests
6+
* Handle async await in callback
7+
* Updated models
8+
* Refactor model file names
9+
* More documentation added in code
10+
111
## [0.1.3] - 2020-06-03
212

313
* pubspec.yaml update

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ In your flutter project add the dependency:
2525
``` dart
2626
dependencies:
2727
...
28-
wp_json_api: ^0.1.3
28+
wp_json_api: ^0.1.4
2929
```
3030

3131
### Usage example #
@@ -50,11 +50,15 @@ WPJsonAPI.instance.initWith(baseUrl: "https://mysite.com");
5050

5151
### Call a method from the request callback
5252
``` dart
53+
try {
5354
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
5455
.api((request) => request.wpLogin(
5556
email: email,
5657
password: password
5758
));
59+
} on Exception catch (e) {
60+
print(e);
61+
}
5862
```
5963

6064
### Available API Requests
@@ -203,4 +207,7 @@ For help getting started with WooSignal, view our
203207
## Usage
204208
To use this plugin, add `wp_json_api` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).
205209

210+
## Note
211+
Install WordPress plugin "WP JSON API" 2.0.x or later for version 0.1.4
212+
206213
Disclaimer: This plugin is not affiliated with or supported by Automattic, Inc. All logos and trademarks are the property of their respective owners.

example/main.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter/material.dart';
2-
import 'package:wp_json_api/enums/WPAuthType.dart';
3-
import 'package:wp_json_api/models/responses/WPUserInfoResponse.dart';
4-
import 'package:wp_json_api/models/responses/WPUserLoginResponse.dart';
2+
import 'package:wp_json_api/enums/wp_auth_type.dart';
3+
import 'package:wp_json_api/models/responses/wp_user_info_response.dart';
4+
import 'package:wp_json_api/models/responses/wp_user_login_response.dart';
55
import 'package:wp_json_api/wp_json_api.dart';
66

77
void main() => runApp(MyApp());
@@ -50,12 +50,17 @@ class _MyHomePageState extends State<MyHomePage> {
5050
String email = _tfEmailController.text;
5151
String password = _tfPasswordController.text;
5252

53+
WPUserLoginResponse wpUserLoginResponse;
5354
// LOGIN
54-
WPUserLoginResponse wpUserLoginResponse =
55-
await WPJsonAPI.instance.api((request) {
56-
return request.wpLogin(
57-
email: email, password: password, authType: WPAuthType.WpEmail);
58-
});
55+
try {
56+
wpUserLoginResponse =
57+
await WPJsonAPI.instance.api((request) {
58+
return request.wpLogin(
59+
email: email, password: password, authType: WPAuthType.WpEmail);
60+
});
61+
} on Exception catch (e) {
62+
print(e);
63+
}
5964

6065
if (wpUserLoginResponse != null) {
6166
print(wpUserLoginResponse.data.userToken);

example/pubspec.lock

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
# Generated by pub
22
# See https://dart.dev/tools/pub/glossary#lockfile
33
packages:
4-
archive:
5-
dependency: transitive
6-
description:
7-
name: archive
8-
url: "https://pub.dartlang.org"
9-
source: hosted
10-
version: "2.0.13"
11-
args:
12-
dependency: transitive
13-
description:
14-
name: args
15-
url: "https://pub.dartlang.org"
16-
source: hosted
17-
version: "1.6.0"
184
async:
195
dependency: transitive
206
description:
@@ -36,27 +22,27 @@ packages:
3622
url: "https://pub.dartlang.org"
3723
source: hosted
3824
version: "1.1.3"
39-
collection:
25+
clock:
4026
dependency: transitive
4127
description:
42-
name: collection
28+
name: clock
4329
url: "https://pub.dartlang.org"
4430
source: hosted
45-
version: "1.14.12"
46-
convert:
31+
version: "1.0.1"
32+
collection:
4733
dependency: transitive
4834
description:
49-
name: convert
35+
name: collection
5036
url: "https://pub.dartlang.org"
5137
source: hosted
52-
version: "2.1.1"
53-
crypto:
38+
version: "1.14.12"
39+
fake_async:
5440
dependency: transitive
5541
description:
56-
name: crypto
42+
name: fake_async
5743
url: "https://pub.dartlang.org"
5844
source: hosted
59-
version: "2.1.4"
45+
version: "1.1.0"
6046
flutter:
6147
dependency: "direct main"
6248
description: flutter
@@ -81,13 +67,6 @@ packages:
8167
url: "https://pub.dartlang.org"
8268
source: hosted
8369
version: "3.1.3"
84-
image:
85-
dependency: transitive
86-
description:
87-
name: image
88-
url: "https://pub.dartlang.org"
89-
source: hosted
90-
version: "2.1.12"
9170
matcher:
9271
dependency: transitive
9372
description:
@@ -108,28 +87,14 @@ packages:
10887
name: path
10988
url: "https://pub.dartlang.org"
11089
source: hosted
111-
version: "1.6.4"
90+
version: "1.7.0"
11291
pedantic:
11392
dependency: transitive
11493
description:
11594
name: pedantic
11695
url: "https://pub.dartlang.org"
11796
source: hosted
11897
version: "1.8.0+1"
119-
petitparser:
120-
dependency: transitive
121-
description:
122-
name: petitparser
123-
url: "https://pub.dartlang.org"
124-
source: hosted
125-
version: "2.4.0"
126-
quiver:
127-
dependency: transitive
128-
description:
129-
name: quiver
130-
url: "https://pub.dartlang.org"
131-
source: hosted
132-
version: "2.1.3"
13398
sky_engine:
13499
dependency: transitive
135100
description: flutter
@@ -197,13 +162,6 @@ packages:
197162
path: ".."
198163
relative: true
199164
source: path
200-
version: "0.1.2"
201-
xml:
202-
dependency: transitive
203-
description:
204-
name: xml
205-
url: "https://pub.dartlang.org"
206-
source: hosted
207-
version: "3.6.1"
165+
version: "0.1.4"
208166
sdks:
209167
dart: ">=2.6.0 <3.0.0"
File renamed without changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2020, WooSignal Ltd.
2+
// All rights reserved.
3+
//
4+
// Redistribution and use in source and binary forms are permitted
5+
// provided that the above copyright notice and this paragraph are
6+
// duplicated in all such forms and that any documentation,
7+
// advertising materials, and other materials related to such
8+
// distribution and use acknowledge that the software was developed
9+
// by the WooSignal. The name of the
10+
// WooSignal may not be used to endorse or promote products derived
11+
// from this software without specific prior written permission.
12+
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13+
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14+
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15+
16+
enum WPMetaDataActionType {
17+
/// MetaData action type [WPMetaDataActionType.Create] is used for
18+
/// creating/adding additional meta data to a key.
19+
Create,
20+
21+
/// MetaData action type [WPMetaDataActionType.Update] is used for
22+
/// updating a meta data key.
23+
/// If the meta field for the user does not exist, it will be added.
24+
Update,
25+
26+
/// MetaData action type [WPMetaDataActionType.Delete] is used for
27+
/// deleting a meta data key and value. You can optionally pass in a [value]
28+
/// to only remove that value from the the array of data.
29+
Delete,
30+
}
File renamed without changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2020, WooSignal Ltd.
2+
// All rights reserved.
3+
//
4+
// Redistribution and use in source and binary forms are permitted
5+
// provided that the above copyright notice and this paragraph are
6+
// duplicated in all such forms and that any documentation,
7+
// advertising materials, and other materials related to such
8+
// distribution and use acknowledge that the software was developed
9+
// by the WooSignal. The name of the
10+
// WooSignal may not be used to endorse or promote products derived
11+
// from this software without specific prior written permission.
12+
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13+
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14+
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15+
16+
class EmptyUsernameException implements Exception {
17+
String message = 'The email field is empty';
18+
EmptyUsernameException();
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2020, WooSignal Ltd.
2+
// All rights reserved.
3+
//
4+
// Redistribution and use in source and binary forms are permitted
5+
// provided that the above copyright notice and this paragraph are
6+
// duplicated in all such forms and that any documentation,
7+
// advertising materials, and other materials related to such
8+
// distribution and use acknowledge that the software was developed
9+
// by the WooSignal. The name of the
10+
// WooSignal may not be used to endorse or promote products derived
11+
// from this software without specific prior written permission.
12+
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13+
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14+
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15+
16+
class ExistingUserEmailException implements Exception {
17+
String message;
18+
ExistingUserEmailException(this.message);
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2020, WooSignal Ltd.
2+
// All rights reserved.
3+
//
4+
// Redistribution and use in source and binary forms are permitted
5+
// provided that the above copyright notice and this paragraph are
6+
// duplicated in all such forms and that any documentation,
7+
// advertising materials, and other materials related to such
8+
// distribution and use acknowledge that the software was developed
9+
// by the WooSignal. The name of the
10+
// WooSignal may not be used to endorse or promote products derived
11+
// from this software without specific prior written permission.
12+
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13+
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14+
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15+
16+
class ExistingUserLoginException implements Exception {
17+
String message;
18+
ExistingUserLoginException(this.message);
19+
}

0 commit comments

Comments
 (0)