diff --git a/CHANGELOG.md b/CHANGELOG.md index 50a297d..cab6044 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/LICENSE b/LICENSE index 541ae49..adb4f6b 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index 52e8cd0..5697042 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ * Update Users Password * Add role to a user * Remove role from a user +* Delete a user **WooCommerce** @@ -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 # @@ -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 diff --git a/lib/enums/wp_auth_type.dart b/lib/enums/wp_auth_type.dart index 8d8368c..0c13169 100644 --- a/lib/enums/wp_auth_type.dart +++ b/lib/enums/wp_auth_type.dart @@ -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 diff --git a/lib/enums/wp_meta_data_action_type.dart b/lib/enums/wp_meta_data_action_type.dart index df56b18..6e53b69 100644 --- a/lib/enums/wp_meta_data_action_type.dart +++ b/lib/enums/wp_meta_data_action_type.dart @@ -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 diff --git a/lib/enums/wp_route_type.dart b/lib/enums/wp_route_type.dart index 8baa054..7145512 100644 --- a/lib/enums/wp_route_type.dart +++ b/lib/enums/wp_route_type.dart @@ -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 @@ -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, diff --git a/lib/exceptions/empty_username_exception.dart b/lib/exceptions/empty_username_exception.dart index 502d7a6..2506db6 100644 --- a/lib/exceptions/empty_username_exception.dart +++ b/lib/exceptions/empty_username_exception.dart @@ -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 diff --git a/lib/exceptions/existing_user_email_exception.dart b/lib/exceptions/existing_user_email_exception.dart index 169b241..5fcbd48 100644 --- a/lib/exceptions/existing_user_email_exception.dart +++ b/lib/exceptions/existing_user_email_exception.dart @@ -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 diff --git a/lib/exceptions/existing_user_login_exception.dart b/lib/exceptions/existing_user_login_exception.dart index 869df62..b518a15 100644 --- a/lib/exceptions/existing_user_login_exception.dart +++ b/lib/exceptions/existing_user_login_exception.dart @@ -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 diff --git a/lib/exceptions/incorrect_password_exception.dart b/lib/exceptions/incorrect_password_exception.dart index f323d8f..f5bc8a3 100644 --- a/lib/exceptions/incorrect_password_exception.dart +++ b/lib/exceptions/incorrect_password_exception.dart @@ -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 diff --git a/lib/exceptions/invalid_email_exception.dart b/lib/exceptions/invalid_email_exception.dart index 5e067fc..1d09f1d 100644 --- a/lib/exceptions/invalid_email_exception.dart +++ b/lib/exceptions/invalid_email_exception.dart @@ -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 diff --git a/lib/exceptions/invalid_nonce_exception.dart b/lib/exceptions/invalid_nonce_exception.dart index a34b34f..cb81ccb 100644 --- a/lib/exceptions/invalid_nonce_exception.dart +++ b/lib/exceptions/invalid_nonce_exception.dart @@ -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 diff --git a/lib/exceptions/invalid_params_exception.dart b/lib/exceptions/invalid_params_exception.dart index d63f85a..bf83d8b 100644 --- a/lib/exceptions/invalid_params_exception.dart +++ b/lib/exceptions/invalid_params_exception.dart @@ -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 diff --git a/lib/exceptions/invalid_user_token_exception.dart b/lib/exceptions/invalid_user_token_exception.dart index 6128bb6..6d0f1d2 100644 --- a/lib/exceptions/invalid_user_token_exception.dart +++ b/lib/exceptions/invalid_user_token_exception.dart @@ -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 diff --git a/lib/exceptions/invalid_username_exception.dart b/lib/exceptions/invalid_username_exception.dart index 4e285fa..996e3c5 100644 --- a/lib/exceptions/invalid_username_exception.dart +++ b/lib/exceptions/invalid_username_exception.dart @@ -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 diff --git a/lib/exceptions/user_already_exist_exception.dart b/lib/exceptions/user_already_exist_exception.dart index 642b479..9ce8b20 100644 --- a/lib/exceptions/user_already_exist_exception.dart +++ b/lib/exceptions/user_already_exist_exception.dart @@ -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 diff --git a/lib/exceptions/user_exists_exception.dart b/lib/exceptions/user_exists_exception.dart index 291defc..42fc842 100644 --- a/lib/exceptions/user_exists_exception.dart +++ b/lib/exceptions/user_exists_exception.dart @@ -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 diff --git a/lib/exceptions/username_taken_exception.dart b/lib/exceptions/username_taken_exception.dart index 4d4aa65..538ee9a 100644 --- a/lib/exceptions/username_taken_exception.dart +++ b/lib/exceptions/username_taken_exception.dart @@ -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 diff --git a/lib/exceptions/woocommerce_not_found_exception.dart b/lib/exceptions/woocommerce_not_found_exception.dart index af3b604..02f688f 100644 --- a/lib/exceptions/woocommerce_not_found_exception.dart +++ b/lib/exceptions/woocommerce_not_found_exception.dart @@ -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 diff --git a/lib/helpers/typedefs.dart b/lib/helpers/typedefs.dart index 7db5f25..b367460 100644 --- a/lib/helpers/typedefs.dart +++ b/lib/helpers/typedefs.dart @@ -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 diff --git a/lib/models/responses/wc_customer_info_response.dart b/lib/models/responses/wc_customer_info_response.dart index 51a9a8b..1177c9b 100644 --- a/lib/models/responses/wc_customer_info_response.dart +++ b/lib/models/responses/wc_customer_info_response.dart @@ -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 diff --git a/lib/models/responses/wc_customer_updated_response.dart b/lib/models/responses/wc_customer_updated_response.dart index 54050e4..fcafd6c 100644 --- a/lib/models/responses/wc_customer_updated_response.dart +++ b/lib/models/responses/wc_customer_updated_response.dart @@ -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 diff --git a/lib/models/responses/wp_nonce_response.dart b/lib/models/responses/wp_nonce_response.dart index 0839b75..a446685 100644 --- a/lib/models/responses/wp_nonce_response.dart +++ b/lib/models/responses/wp_nonce_response.dart @@ -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 diff --git a/lib/models/responses/wp_nonce_verified_response.dart b/lib/models/responses/wp_nonce_verified_response.dart index 6e3f74e..4887015 100644 --- a/lib/models/responses/wp_nonce_verified_response.dart +++ b/lib/models/responses/wp_nonce_verified_response.dart @@ -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 diff --git a/lib/models/responses/wp_user_add_role_response.dart b/lib/models/responses/wp_user_add_role_response.dart index 68876c8..aed4b19 100644 --- a/lib/models/responses/wp_user_add_role_response.dart +++ b/lib/models/responses/wp_user_add_role_response.dart @@ -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 diff --git a/lib/models/responses/wp_user_delete_response.dart b/lib/models/responses/wp_user_delete_response.dart new file mode 100644 index 0000000..5dbffa7 --- /dev/null +++ b/lib/models/responses/wp_user_delete_response.dart @@ -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? data; + String? message; + int? status; + + WPUserDeleteResponse({this.data, this.message, this.status}); + + WPUserDeleteResponse.fromJson(Map json) { + if (json['data'] != null) { + data = json['data']; + } + message = json['message']; + status = json['status']; + } + + Map toJson() { + final Map data = new Map(); + if (this.data != null) { + data['data'] = this.data!.map((v) => v.toJson()).toList(); + } + data['message'] = this.message; + data['status'] = this.status; + return data; + } +} diff --git a/lib/models/responses/wp_user_info_response.dart b/lib/models/responses/wp_user_info_response.dart index 950f1a2..214eb65 100644 --- a/lib/models/responses/wp_user_info_response.dart +++ b/lib/models/responses/wp_user_info_response.dart @@ -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 diff --git a/lib/models/responses/wp_user_info_updated_response.dart b/lib/models/responses/wp_user_info_updated_response.dart index dc60d2a..5a2e346 100644 --- a/lib/models/responses/wp_user_info_updated_response.dart +++ b/lib/models/responses/wp_user_info_updated_response.dart @@ -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 diff --git a/lib/models/responses/wp_user_login_response.dart b/lib/models/responses/wp_user_login_response.dart index 94f19fc..002885c 100644 --- a/lib/models/responses/wp_user_login_response.dart +++ b/lib/models/responses/wp_user_login_response.dart @@ -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 diff --git a/lib/models/responses/wp_user_register_response.dart b/lib/models/responses/wp_user_register_response.dart index da7b2d0..539d54c 100644 --- a/lib/models/responses/wp_user_register_response.dart +++ b/lib/models/responses/wp_user_register_response.dart @@ -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 diff --git a/lib/models/responses/wp_user_remove_role_response.dart b/lib/models/responses/wp_user_remove_role_response.dart index 1870387..4a98431 100644 --- a/lib/models/responses/wp_user_remove_role_response.dart +++ b/lib/models/responses/wp_user_remove_role_response.dart @@ -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 diff --git a/lib/models/responses/wp_user_reset_password_response.dart b/lib/models/responses/wp_user_reset_password_response.dart index 343c759..47d2de6 100644 --- a/lib/models/responses/wp_user_reset_password_response.dart +++ b/lib/models/responses/wp_user_reset_password_response.dart @@ -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 diff --git a/lib/models/wp_meta_meta.dart b/lib/models/wp_meta_meta.dart index 4f4508b..36aab32 100644 --- a/lib/models/wp_meta_meta.dart +++ b/lib/models/wp_meta_meta.dart @@ -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 diff --git a/lib/networking/network_manager.dart b/lib/networking/network_manager.dart index a1415f5..75065d5 100644 --- a/lib/networking/network_manager.dart +++ b/lib/networking/network_manager.dart @@ -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 @@ -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'; @@ -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 wpUserDelete(userToken, {int? reassign}) async { + Map 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. /// @@ -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: diff --git a/lib/wp_json_api.dart b/lib/wp_json_api.dart index 527c0ef..4fd7856 100644 --- a/lib/wp_json_api.dart +++ b/lib/wp_json_api.dart @@ -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 diff --git a/pubspec.lock b/pubspec.lock index caaa270..332c2e9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -21,14 +21,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -42,14 +42,14 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" flutter: dependency: "direct main" description: flutter @@ -66,7 +66,7 @@ packages: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.13.3" + version: "0.13.4" http_parser: dependency: transitive description: @@ -80,28 +80,28 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" - meta: + version: "0.12.11" + material_color_utilities: dependency: transitive description: - name: meta + name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" - path: + version: "0.1.4" + meta: dependency: transitive description: - name: path + name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" - pedantic: + version: "1.7.0" + path: dependency: transitive description: - name: pedantic + name: path url: "https://pub.dartlang.org" source: hosted - version: "1.11.0" + version: "1.8.1" sky_engine: dependency: transitive description: flutter @@ -113,7 +113,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -148,7 +148,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.9" typed_data: dependency: transitive description: @@ -162,6 +162,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.2" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=2.17.0 <3.0.0" + flutter: ">=1.17.0" diff --git a/pubspec.yaml b/pubspec.yaml index 0e91a44..d9223ab 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,16 +1,17 @@ name: wp_json_api description: WordPress and WooCommerce JSON API for Flutter Mobile. API allows you to login, register new users, get users info and more. -version: 3.1.3 +version: 3.2.0 homepage: https://woosignal.com repository: https://github.com/woosignal/wp-json-api-flutter issue_tracker: https://github.com/woosignal/wp-json-api-flutter/issues documentation: https://woosignal.com/docs/flutter/wp-json-api environment: - sdk: '>=2.12.0 <3.0.0' + sdk: ">=2.17.0 <3.0.0" + flutter: ">=1.17.0" dependencies: - http: ^0.13.3 + http: ^0.13.4 flutter: sdk: flutter collection: ^1.15.0