Skip to content

Commit

Permalink
v3.2.0 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
agordn52 committed Jul 7, 2022
1 parent 06968d1 commit 4987249
Show file tree
Hide file tree
Showing 37 changed files with 150 additions and 56 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [3.2.0] - 2022-07-07

* New API to delete an account
* Update code docs

## [3.1.3] - 2021-09-03

* Add roles to wp_user_info_response
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 2-Clause License

Copyright (c) 2021, WooSignal Ltd
Copyright (c) 2022, WooSignal Ltd
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Update Users Password
* Add role to a user
* Remove role from a user
* Delete a user

**WooCommerce**

Expand All @@ -27,7 +28,7 @@ In your flutter project add the dependency:
``` dart
dependencies:
...
wp_json_api: ^3.1.3
wp_json_api: ^3.2.0
```

### Usage example #
Expand Down Expand Up @@ -179,6 +180,18 @@ WPUserRemoveRoleResponse wpUserRemoveRoleResponse = await WPJsonAPI.instance
));
```

#### WordPress - Delete a user
- Used to delete a user in WordPress
- The first parameter is the **userToken** which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
- You can pass an optional argument 'reassign' to reassign posts and links to new User ID.

``` dart
WPUserDeleteResponse wpUserDeleteResponse = await WPJsonAPI.instance
.api((request) => request.wpUserDelete(
userToken
));
```

#### WooCommerce - Get users info in WooCommerce
- Used to get WooCommerce info for a given user
- The first parameter is the **userToken** which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
Expand Down
2 changes: 1 addition & 1 deletion lib/enums/wp_auth_type.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/enums/wp_meta_data_action_type.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
6 changes: 5 additions & 1 deletion lib/enums/wp_route_type.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down Expand Up @@ -42,6 +42,10 @@ enum WPRouteType {
/// For WordPress
UserLogin,

/// Route type [WPRouteType.UserDelete] is used to delete a user from WordPress.
/// For WordPress
UserDelete,

/// Route type [WPRouteType.AuthNonce] is used to get a nonce token to authenticate future API requests.
/// For WordPress
AuthNonce,
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/empty_username_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/existing_user_email_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/existing_user_login_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/incorrect_password_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/invalid_email_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/invalid_nonce_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/invalid_params_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/invalid_user_token_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/invalid_username_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/user_already_exist_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/user_exists_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/username_taken_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/woocommerce_not_found_exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/typedefs.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/models/responses/wc_customer_info_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/models/responses/wc_customer_updated_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/models/responses/wp_nonce_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/models/responses/wp_nonce_verified_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/models/responses/wp_user_add_role_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
40 changes: 40 additions & 0 deletions lib/models/responses/wp_user_delete_response.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
// provided that the above copyright notice and this paragraph are
// duplicated in all such forms and that any documentation,
// advertising materials, and other materials related to such
// distribution and use acknowledge that the software was developed
// by the WooSignal. The name of the
// WooSignal may not be used to endorse or promote products derived
// from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

class WPUserDeleteResponse {
List<dynamic>? data;
String? message;
int? status;

WPUserDeleteResponse({this.data, this.message, this.status});

WPUserDeleteResponse.fromJson(Map<String, dynamic> json) {
if (json['data'] != null) {
data = json['data'];
}
message = json['message'];
status = json['status'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.data != null) {
data['data'] = this.data!.map((v) => v.toJson()).toList();
}
data['message'] = this.message;
data['status'] = this.status;
return data;
}
}
2 changes: 1 addition & 1 deletion lib/models/responses/wp_user_info_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/models/responses/wp_user_info_updated_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/models/responses/wp_user_login_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/models/responses/wp_user_register_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/models/responses/wp_user_remove_role_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/models/responses/wp_user_reset_password_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
2 changes: 1 addition & 1 deletion lib/models/wp_meta_meta.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
32 changes: 31 additions & 1 deletion lib/networking/network_manager.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down Expand Up @@ -35,6 +35,7 @@ import 'package:wp_json_api/models/responses/wc_customer_updated_response.dart';
import 'package:wp_json_api/models/responses/wp_nonce_response.dart';
import 'package:wp_json_api/models/responses/wp_nonce_verified_response.dart';
import 'package:wp_json_api/models/responses/wp_user_add_role_response.dart';
import 'package:wp_json_api/models/responses/wp_user_delete_response.dart';
import 'package:wp_json_api/models/responses/wp_user_info_updated_response.dart';
import 'package:wp_json_api/models/responses/wp_user_login_response.dart';
import 'package:wp_json_api/models/responses/wp_user_register_response.dart';
Expand Down Expand Up @@ -262,6 +263,31 @@ class WPAppNetworkManager {
: WPUserAddRoleResponse.fromJson(json);
}

/// Sends a request to delete a WordPress user. Include a valid
/// [userToken] and an optional [reassign] argument to send a successful request.
///
/// Returns a [WPUserDeleteResponse] future.
/// Throws an [Exception] if fails.
Future<WPUserDeleteResponse> wpUserDelete(userToken, {int? reassign}) async {
Map<String, dynamic> payload = {};
if (reassign != null) {
payload["reassign"] = reassign;
}

// send http request
final json = await _http(
method: "POST",
url: _urlForRouteType(WPRouteType.UserDelete),
userToken: userToken,
body: payload,
);

// return response
return _jsonHasBadStatus(json)
? this._throwExceptionForStatusCode(json)
: WPUserDeleteResponse.fromJson(json);
}

/// Sends a request to remove a role from a WordPress user. Include a valid
/// [userToken] and [role] to send a successful request.
///
Expand Down Expand Up @@ -556,6 +582,10 @@ class WPAppNetworkManager {
{
return "/wpapp/api/$apiVersion/update/user/password";
}
case WPRouteType.UserDelete:
{
return "/wpapp/api/$apiVersion/user/delete";
}

// WOOCOMMERCE API
case WPRouteType.WCCustomerInfo:
Expand Down
2 changes: 1 addition & 1 deletion lib/wp_json_api.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, WooSignal Ltd.
// Copyright (c) 2022, WooSignal Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
Expand Down
Loading

0 comments on commit 4987249

Please sign in to comment.