Skip to content

Commit

Permalink
v3.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
agordn52 committed Mar 18, 2024
1 parent 1a43178 commit 1e0f113
Show file tree
Hide file tree
Showing 15 changed files with 1,222 additions and 179 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## [3.5.0] - 2024-03-18

* Breaking change `WPJsonAPI.initWith` is now `WPJsonAPI.init`
* Refactor project
* Ability to save user token for future requests
* New WpUser model for user data
* New wcRegister method for networking class
* Add more data to `WpUserLoginResponse` and `WpUserInfoResponse`
* Added `version` to `WpJsonAPI` class
* New `WPJsonAPI.wpLogin` method to login a user
* New `WPJsonAPI.wpLogout` method to logout a user
* New `WPJsonAPI.wpUserLoggedIn` method to check if a user is logged in
* New `WPJsonAPI.wpUser` method to get the current user
* New `WPJsonAPI.wpUserId` method to get the current user's ID
* New `WPJsonAPI.wpUserToken` method to get the current user's token
* New `WPJsonAPI.wpAuth` method to authenticate the previously logged in user
* Added Storage key to `WPJsonAPI` class
* New docs added to Readme
* Dependency updates

## [3.4.0] - 2024-03-15

* Added new networking methods for WooCommerce Points and Rewards
Expand Down
57 changes: 28 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ In your flutter project add the dependency:
``` dart
dependencies:
...
wp_json_api: ^3.4.0
wp_json_api: ^3.5.0
```

### Usage example #
Expand All @@ -45,7 +45,7 @@ import 'package:wp_json_api/wp_json_api.dart';
void main() {
WPJsonAPI.instance.initWith(baseUrl: "https://mysite.com");
WPJsonAPI.instance.init(baseUrl: "https://mysite.com");
...
```
Expand Down Expand Up @@ -115,29 +115,26 @@ WPUserRegisterResponse wpUserRegisterResponse = await WPJsonAPI.instance
.api((request) => request.wpRegister(
email: email,
password: password,
username: username
// username: username // optional - the library will automatically generate a username if not provided
));
```

#### WordPress - Get Users Info
- Used to get a WordPress users info
- The first parameter is the **userToken** which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
- After you login/register, you can all this method to get the users info

``` dart
WPUserInfoResponse wpUserInfoResponse = await WPJsonAPI.instance
.api((request) => request.wpGetUserInfo(
userToken
));
.api((request) => request.wpGetUserInfo());
```

#### WordPress - Update Users Info
- Used to update a WordPress users info
- The first parameter is the **userToken** which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
- After you login/register, you can all this method to update the users info

``` dart
WPUserInfoUpdatedResponse wpUserInfoUpdatedResponse = await WPJsonAPI.instance
.api((request) => request.wpUpdateUserInfo(
userToken,
firstName: firstName,
lastName: lastName,
displayName: displayName
Expand All @@ -146,55 +143,61 @@ WPUserInfoUpdatedResponse wpUserInfoUpdatedResponse = await WPJsonAPI.instance

#### WordPress - Update users password
- Used to update a users password
- The first parameter is the **userToken** which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
- After you login/register, you can all this method to update the users password

``` dart
WPUserResetPasswordResponse wpUserResetPasswordResponse = await WPJsonAPI.instance
.api((request) => request.wpResetPassword(
userToken,
password: password
));
```

#### WordPress - Add a role to a user
- Used to add a role to 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
- After you login/register, you can all this method to add a role to the user

``` dart
WPUserAddRoleResponse wpUserAddRoleResponse = await WPJsonAPI.instance
.api((request) => request.wpUserAddRole(
userToken,
role: "customer" // e.g. customer, subscriber
));
```

#### WordPress - Remove a role from a user
- Used to remove a role from 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
- After you login/register, you can all this method to remove a role from the user

``` dart
WPUserRemoveRoleResponse wpUserRemoveRoleResponse = await WPJsonAPI.instance
.api((request) => request.wpUserRemoveRole(
userToken,
role: "customer" // e.g. customer, subscriber
));
```

#### 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
- After you login/register, you can all this method to delete the user
- 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
));
.api((request) => request.wpUserDelete());
```

#### WooCommerce - Register
- Used to register a user

``` dart
WPUserRegisterResponse wpUserRegisterResponse = await WPJsonAPI.instance
.api((request) => request.wpRegister(
email: email,
password: password
));
```

#### 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
- After you login/register, you can all this method to get the users WooCommerce info

``` dart
WCCustomerInfoResponse wcCustomerInfoResponse = await WPJsonAPI.instance
Expand All @@ -206,12 +209,11 @@ WCCustomerInfoResponse wcCustomerInfoResponse = await WPJsonAPI.instance
#### WooCommerce - Update users info in WooCommerce
- Used to update a users WooCommerce details
- All the parameter are optional so if you wanted to just update the name, you could just add first_name and last_name
- The first parameter is the **userToken** which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
- After you login/register, you can all this method to update the users WooCommerce info

``` dart
WCCustomerUpdatedResponse wcCustomerUpdatedResponse = await WPJsonAPI.instance
.api((request) => request.wcUpdateCustomerInfo(
userToken,
firstName: firstName,
lastName: lastName,
displayName: displayName,
Expand Down Expand Up @@ -242,23 +244,20 @@ WCCustomerUpdatedResponse wcCustomerUpdatedResponse = await WPJsonAPI.instance

#### WooCommerce Points and Rewards - Get user's points
- This is used to get the user's current points in the [WooCommerce Points and Rewards](https://woo.com/products/woocommerce-points-and-rewards/) plugin
- The first parameter is the **userToken** which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
- After you login/register, you can all this method to get the users points

``` dart
WcPointsAndRewardUser wcPointsAndRewardUser = await WPJsonAPI.instance
.api((request) => request.wcPointsAndRewardsUser(
userToken
));
.api((request) => request.wcPointsAndRewardsUser());
```

#### WooCommerce Points and Rewards - Calculate the value of points
- This is used to calculate the value of points in the [WooCommerce Points and Rewards](https://woo.com/products/woocommerce-points-and-rewards/) plugin
- The first parameter is the **userToken** which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
- After you login/register, you can all this method to calculate the value of points

``` dart
WcPointsAndRewardCalculatePoints wcPointsAndRewardsCalculatePoints = await WPJsonAPI.instance
.api((request) => request.wcPointsAndRewardsCalculatePoints(
userToken,
points: 100
));
```
Expand All @@ -270,6 +269,6 @@ For help getting started with WooSignal, view our
To use this plugin, add `wp_json_api` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).

## Note
Install our WordPress plugin "[WP JSON API](https://woosignal.com/plugins/wordpress/wp-json-api)" v3.3.2 to use this flutter plugin.
Install our WordPress plugin "[WP JSON API](https://woosignal.com/plugins/wordpress/wp-json-api)" v3.4.0 to use this flutter plugin.

Disclaimer: This plugin is not affiliated with or supported by Automattic, Inc. All logos and trademarks are the property of their respective owners.
42 changes: 19 additions & 23 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
late TextEditingController _tfEmailController;
late TextEditingController _tfPasswordController;
TextEditingController _tfEmailController = TextEditingController();
TextEditingController _tfPasswordController = TextEditingController();

@override
void initState() {
Expand All @@ -40,10 +40,7 @@ class _MyHomePageState extends State<MyHomePage> {
// FIRST ON YOUR WORDPRESS STORE
// LINK https://woosignal.com/plugins/wordpress/wp-json-api

WPJsonAPI.instance.initWith(baseUrl: "http://mysite.com");

_tfEmailController = TextEditingController();
_tfPasswordController = TextEditingController();
WPJsonAPI.instance.init(baseUrl: "http://mysite.com");
}

_login() async {
Expand All @@ -60,24 +57,23 @@ class _MyHomePageState extends State<MyHomePage> {
print(e);
}

if (wpUserLoginResponse != null) {
print(wpUserLoginResponse.data?.userToken);
print(wpUserLoginResponse.data?.userId);

// GET USER INFO
WPUserInfoResponse? wpUserInfoResponse =
await WPJsonAPI.instance.api((request) {
return request.wpGetUserInfo(wpUserLoginResponse!.data!.userToken!);
});

if (wpUserInfoResponse != null) {
print(wpUserInfoResponse.data?.firstName);
print(wpUserInfoResponse.data?.lastName);
} else {
print("something went wrong");
}
} else {
if (wpUserLoginResponse == null) {
print("invalid login details");
return;
}

print(wpUserLoginResponse.data?.userToken);
print(wpUserLoginResponse.data?.userId);

// GET USER INFO
WPUserInfoResponse? wpUserInfoResponse =
await WPJsonAPI.instance.api((request) => request.wpGetUserInfo());

if (wpUserInfoResponse != null) {
print(wpUserInfoResponse.data?.firstName);
print(wpUserInfoResponse.data?.lastName);
} else {
print("something went wrong");
}
}

Expand Down
Loading

0 comments on commit 1e0f113

Please sign in to comment.