Skip to content

Commit 58a32be

Browse files
author
WooSignal
committed
pubspec.yaml desc change, updates to networking class and readme
1 parent f43db25 commit 58a32be

File tree

14 files changed

+729
-174
lines changed

14 files changed

+729
-174
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.0.2] - 2020-04-11
2+
3+
* pubspec.yaml desc change, updates to networking class and readme
4+
15
## [0.0.1] - 2020-04-06
26

37
* Initial Release

README.md

Lines changed: 152 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# WordPress and WooCommerce JSON API Dart package for Flutter
22

3-
[Official WooSignal WooCommerce package](https://woosignal.com)
3+
[Official WooSignal WordPress/WooCommerce package](https://woosignal.com)
44

55
API features:
66

@@ -15,27 +15,170 @@ API features:
1515
- Get Customers Info (Billing and Shipping)
1616
- Update Customers details
1717

18-
To use this API you must have the [WP Json API Plugin](https://woosignal.com/plugins/wp-json-api) installed first on your WordPress site, you can download it via the WooSignal website.
18+
To use this API you must have the [WP Json API Plugin](https://woosignal.com/plugins/wordpress/wpapp-json-api) installed first on your WordPress site, you can download it via the WooSignal website.
1919

2020
### Examples using Wp JSON API
2121

2222
``` dart
2323
import 'package:woosignal/wp_json_api.dart';
24+
...
25+
26+
void main() {
27+
28+
WPJsonAPI.instance.initWith(baseUrl: "https://mysite.com");
2429
2530
...
2631
27-
#1 - Set the base url (e.g. https://mysite.com)
32+
33+
##2 - Call a method from the request callback
2834
``` dart
29-
String base_url = "https://mywordpress-site.com";
30-
WPJsonAPI.instance.initWith(baseUrl: base_url);
35+
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
36+
.api((request) => request.wpLogin(
37+
email: email,
38+
password: password
39+
));
3140
```
3241

33-
#2 - Call a method from the request api
42+
### Available API Requests
43+
44+
###WordPress - Get Nonce
45+
- Used for returning a valid nonce
3446
``` dart
35-
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance.api((request) {
36-
return request.wpLogin(email: email, password: password);
37-
});
47+
WPNonceResponse wpNonceResponse = await WPJsonAPI.instance
48+
.api((request) => request.wpNonce());
3849
```
50+
51+
###WordPress - Verify Nonce
52+
- Used for verifying register and login request
53+
``` dart
54+
WPNonceVerifiedResponse wpNonceVerifiedResponse = await WPJsonAPI.instance
55+
.api((request) => request.wpNonceVerify(
56+
nonce: nonce
57+
));
58+
```
59+
60+
###WordPress - Login with email
61+
- Used to login a user
62+
63+
``` dart
64+
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
65+
.api((request) => request.wpLogin(
66+
email: email,
67+
password: password,
68+
authType: WPAuthType.WpEmail
69+
));
70+
```
71+
72+
###WordPress - Login with username
73+
- Used to login a user
74+
75+
``` dart
76+
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
77+
.api((request) => request.wpLogin(
78+
email: email,
79+
password: password,
80+
authType: WPAuthType.WpUsername
81+
));
82+
```
83+
84+
###WordPress - Register
85+
- Used to register a user
86+
- The username parameter is required, ensure that this is unquie
87+
88+
``` dart
89+
WPUserRegisterResponse wpUserRegisterResponse = await WPJsonAPI.instance
90+
.api((request) => request.wpRegister(
91+
email: email,
92+
password: password,
93+
username: username
94+
));
95+
```
96+
97+
###WordPress - Get Users Info
98+
- Used to get a WordPress users info
99+
- The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
100+
101+
``` dart
102+
WPUserInfoResponse wpUserInfoResponse = await WPJsonAPI.instance
103+
.api((request) => request.wpGetUserInfo(
104+
userToken
105+
));
106+
```
107+
108+
###WordPress - Update Users Info
109+
- Used to update a WordPress users info
110+
- The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
111+
112+
``` dart
113+
WPUserInfoUpdatedResponse wpUserInfoUpdatedResponse = await WPJsonAPI.instance
114+
.api((request) => request.wpUpdateUserInfo(
115+
userToken,
116+
firstName: firstName,
117+
lastName: lastName,
118+
displayName: displayName
119+
));
120+
```
121+
122+
###WordPress - Update users password
123+
- Used to update a users password
124+
- The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
125+
126+
``` dart
127+
WPUserResetPasswordResponse wpUserResetPasswordResponse = await WPJsonAPI.instance
128+
.api((request) => request.wpResetPassword(
129+
userToken,
130+
password: password
131+
));
132+
```
133+
134+
###WooCommerce - Get users info in WooCommerce
135+
- Used to get WooCommerce info for a given user, pass in the userToken which you should have stored somewhere safe in shared_pref or other
136+
- The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
137+
138+
``` dart
139+
WCCustomerInfoResponse wcCustomerInfoResponse = await WPJsonAPI.instance
140+
.api((request) => request.wcCustomerInfo(
141+
userToken
142+
));
143+
```
144+
145+
###WooCommerce - Update users info in WooCommerce
146+
- Used to update a users WooCommerce details
147+
- All the parameter are optional so if you wanted to just update the name, you could just add first_name and last_name
148+
- The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
149+
150+
``` dart
151+
WCCustomerUpdatedResponse wcCustomerUpdatedResponse = await WPJsonAPI.instance
152+
.api((request) => request.wcUpdateCustomerInfo(
153+
userToken,
154+
firstName: firstName,
155+
lastName: lastName,
156+
displayName: displayName,
157+
billingFirstName: billingFirstName,
158+
billingLastName: billingLastName,
159+
billingCompany: billingCompany,
160+
billingAddress1: billingAddress1,
161+
billingAddress2: billingAddress2,
162+
billingCity: billingCity,
163+
billingState: billingState,
164+
billingPostcode: billingPostcode,
165+
billingCountry: billingCountry,
166+
billingEmail: billingEmail,
167+
billingPhone: billingPhone,
168+
shippingFirstName: shippingFirstName,
169+
shippingLastName: shippingLastName,
170+
shippingCompany: shippingCompany,
171+
shippingAddress1: shippingAddress1,
172+
shippingAddress2: shippingAddress2,
173+
shippingCity: shippingCity,
174+
shippingState: shippingState,
175+
shippingPostcode: shippingPostcode,
176+
shippingCountry: shippingCountry,
177+
shippingEmail: shippingEmail,
178+
shippingPhone: shippingPhone
179+
));
180+
```
181+
39182
For help getting started with WooSignal, view our
40183
[online documentation](https://woosignal.com/docs/wordpress-json-api-flutter/1.0/overview), which offers a more detailed guide.
41184

example/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Example - Login as a user
2+
3+
A new WooCommerce Flutter project.
4+
5+
## Getting Started
6+
7+
Follow our easy guide online to generate a new app key to start making WooCommerce API requests.
8+
[documentation](https://woosignal.com/plugins/wordpress/wpapp-json-api).
9+
10+
For help getting started with Flutter, view our online
11+
[documentation](https://flutter.io/)

example/main.dart

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
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';
5+
import 'package:wp_json_api/wp_json_api.dart';
6+
7+
void main() => runApp(MyApp());
8+
9+
class MyApp extends StatelessWidget {
10+
@override
11+
Widget build(BuildContext context) {
12+
return MaterialApp(
13+
title: 'WooSignal Demo',
14+
theme: ThemeData(
15+
primarySwatch: Colors.blue,
16+
),
17+
home: MyHomePage(title: 'WooSignal Demo Home Page'),
18+
);
19+
}
20+
}
21+
22+
class MyHomePage extends StatefulWidget {
23+
MyHomePage({Key key, this.title}) : super(key: key);
24+
25+
final String title;
26+
27+
@override
28+
_MyHomePageState createState() => _MyHomePageState();
29+
}
30+
31+
class _MyHomePageState extends State<MyHomePage> {
32+
TextEditingController _tfEmailController;
33+
TextEditingController _tfPasswordController;
34+
35+
@override
36+
void initState() {
37+
super.initState();
38+
39+
// INSTALL THE WP JSON API PLUGIN
40+
// FIRST ON YOUR WORDPRESS STORE
41+
// LINK https://woosignal.com/plugins/wordpress/wpapp-json-api
42+
43+
WPJsonAPI.instance.initWith(baseUrl: "http://mysite.com");
44+
45+
_tfEmailController = TextEditingController();
46+
_tfPasswordController = TextEditingController();
47+
}
48+
49+
_login() async {
50+
String email = _tfEmailController.text;
51+
String password = _tfPasswordController.text;
52+
53+
// LOGIN
54+
WPUserLoginResponse wpUserLoginResponse =
55+
await WPJsonAPI.instance.api((request) {
56+
return request.wpLogin(
57+
email: email, password: password, authType: WPAuthType.WpEmail);
58+
});
59+
60+
if (wpUserLoginResponse != null) {
61+
print(wpUserLoginResponse.data.userToken);
62+
print(wpUserLoginResponse.data.userId);
63+
64+
// GET USER INFO
65+
WPUserInfoResponse wpUserInfoResponse =
66+
await WPJsonAPI.instance.api((request) {
67+
return request.wpGetUserInfo(wpUserLoginResponse.data.userToken);
68+
});
69+
70+
if (wpUserInfoResponse != null) {
71+
print(wpUserInfoResponse.data.firstName);
72+
print(wpUserInfoResponse.data.lastName);
73+
} else {
74+
print("something went wrong");
75+
}
76+
} else {
77+
print("invalid login details");
78+
}
79+
}
80+
81+
@override
82+
Widget build(BuildContext context) {
83+
return Scaffold(
84+
appBar: AppBar(
85+
title: Text(widget.title),
86+
),
87+
body: Center(
88+
child: Column(
89+
mainAxisAlignment: MainAxisAlignment.center,
90+
children: <Widget>[
91+
TextField(
92+
controller: _tfEmailController,
93+
keyboardType: TextInputType.emailAddress,
94+
),
95+
TextField(
96+
controller: _tfPasswordController,
97+
keyboardType: TextInputType.text,
98+
obscureText: true,
99+
),
100+
MaterialButton(
101+
child: Text("Login"),
102+
onPressed: _login,
103+
)
104+
],
105+
),
106+
),
107+
);
108+
}
109+
}

0 commit comments

Comments
 (0)