Skip to content

Commit 4987249

Browse files
committed
v3.2.0 updates
1 parent 06968d1 commit 4987249

37 files changed

+150
-56
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [3.2.0] - 2022-07-07
2+
3+
* New API to delete an account
4+
* Update code docs
5+
16
## [3.1.3] - 2021-09-03
27

38
* Add roles to wp_user_info_response

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 2-Clause License
22

3-
Copyright (c) 2021, WooSignal Ltd
3+
Copyright (c) 2022, WooSignal Ltd
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Update Users Password
1414
* Add role to a user
1515
* Remove role from a user
16+
* Delete a user
1617

1718
**WooCommerce**
1819

@@ -27,7 +28,7 @@ In your flutter project add the dependency:
2728
``` dart
2829
dependencies:
2930
...
30-
wp_json_api: ^3.1.3
31+
wp_json_api: ^3.2.0
3132
```
3233

3334
### Usage example #
@@ -179,6 +180,18 @@ WPUserRemoveRoleResponse wpUserRemoveRoleResponse = await WPJsonAPI.instance
179180
));
180181
```
181182

183+
#### WordPress - Delete a user
184+
- Used to delete a user in WordPress
185+
- The first parameter is the **userToken** which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
186+
- You can pass an optional argument 'reassign' to reassign posts and links to new User ID.
187+
188+
``` dart
189+
WPUserDeleteResponse wpUserDeleteResponse = await WPJsonAPI.instance
190+
.api((request) => request.wpUserDelete(
191+
userToken
192+
));
193+
```
194+
182195
#### WooCommerce - Get users info in WooCommerce
183196
- Used to get WooCommerce info for a given user
184197
- The first parameter is the **userToken** which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref

lib/enums/wp_auth_type.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/enums/wp_meta_data_action_type.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/enums/wp_route_type.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted
@@ -42,6 +42,10 @@ enum WPRouteType {
4242
/// For WordPress
4343
UserLogin,
4444

45+
/// Route type [WPRouteType.UserDelete] is used to delete a user from WordPress.
46+
/// For WordPress
47+
UserDelete,
48+
4549
/// Route type [WPRouteType.AuthNonce] is used to get a nonce token to authenticate future API requests.
4650
/// For WordPress
4751
AuthNonce,

lib/exceptions/empty_username_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/exceptions/existing_user_email_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/exceptions/existing_user_login_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/exceptions/incorrect_password_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/exceptions/invalid_email_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/exceptions/invalid_nonce_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/exceptions/invalid_params_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/exceptions/invalid_user_token_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/exceptions/invalid_username_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/exceptions/user_already_exist_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/exceptions/user_exists_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/exceptions/username_taken_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/exceptions/woocommerce_not_found_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/helpers/typedefs.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/models/responses/wc_customer_info_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/models/responses/wc_customer_updated_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/models/responses/wp_nonce_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/models/responses/wp_nonce_verified_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/models/responses/wp_user_add_role_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2022, 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 WPUserDeleteResponse {
17+
List<dynamic>? data;
18+
String? message;
19+
int? status;
20+
21+
WPUserDeleteResponse({this.data, this.message, this.status});
22+
23+
WPUserDeleteResponse.fromJson(Map<String, dynamic> json) {
24+
if (json['data'] != null) {
25+
data = json['data'];
26+
}
27+
message = json['message'];
28+
status = json['status'];
29+
}
30+
31+
Map<String, dynamic> toJson() {
32+
final Map<String, dynamic> data = new Map<String, dynamic>();
33+
if (this.data != null) {
34+
data['data'] = this.data!.map((v) => v.toJson()).toList();
35+
}
36+
data['message'] = this.message;
37+
data['status'] = this.status;
38+
return data;
39+
}
40+
}

lib/models/responses/wp_user_info_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/models/responses/wp_user_info_updated_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/models/responses/wp_user_login_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/models/responses/wp_user_register_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/models/responses/wp_user_remove_role_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/models/responses/wp_user_reset_password_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/models/wp_meta_meta.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

lib/networking/network_manager.dart

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted
@@ -35,6 +35,7 @@ import 'package:wp_json_api/models/responses/wc_customer_updated_response.dart';
3535
import 'package:wp_json_api/models/responses/wp_nonce_response.dart';
3636
import 'package:wp_json_api/models/responses/wp_nonce_verified_response.dart';
3737
import 'package:wp_json_api/models/responses/wp_user_add_role_response.dart';
38+
import 'package:wp_json_api/models/responses/wp_user_delete_response.dart';
3839
import 'package:wp_json_api/models/responses/wp_user_info_updated_response.dart';
3940
import 'package:wp_json_api/models/responses/wp_user_login_response.dart';
4041
import 'package:wp_json_api/models/responses/wp_user_register_response.dart';
@@ -262,6 +263,31 @@ class WPAppNetworkManager {
262263
: WPUserAddRoleResponse.fromJson(json);
263264
}
264265

266+
/// Sends a request to delete a WordPress user. Include a valid
267+
/// [userToken] and an optional [reassign] argument to send a successful request.
268+
///
269+
/// Returns a [WPUserDeleteResponse] future.
270+
/// Throws an [Exception] if fails.
271+
Future<WPUserDeleteResponse> wpUserDelete(userToken, {int? reassign}) async {
272+
Map<String, dynamic> payload = {};
273+
if (reassign != null) {
274+
payload["reassign"] = reassign;
275+
}
276+
277+
// send http request
278+
final json = await _http(
279+
method: "POST",
280+
url: _urlForRouteType(WPRouteType.UserDelete),
281+
userToken: userToken,
282+
body: payload,
283+
);
284+
285+
// return response
286+
return _jsonHasBadStatus(json)
287+
? this._throwExceptionForStatusCode(json)
288+
: WPUserDeleteResponse.fromJson(json);
289+
}
290+
265291
/// Sends a request to remove a role from a WordPress user. Include a valid
266292
/// [userToken] and [role] to send a successful request.
267293
///
@@ -556,6 +582,10 @@ class WPAppNetworkManager {
556582
{
557583
return "/wpapp/api/$apiVersion/update/user/password";
558584
}
585+
case WPRouteType.UserDelete:
586+
{
587+
return "/wpapp/api/$apiVersion/user/delete";
588+
}
559589

560590
// WOOCOMMERCE API
561591
case WPRouteType.WCCustomerInfo:

lib/wp_json_api.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, WooSignal Ltd.
1+
// Copyright (c) 2022, WooSignal Ltd.
22
// All rights reserved.
33
//
44
// Redistribution and use in source and binary forms are permitted

0 commit comments

Comments
 (0)