Skip to content

Commit 489ede5

Browse files
committed
Support for v2.0.0 wp-json-api WordPress plugin
1 parent fc22cb4 commit 489ede5

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [2.0.0] - 2020-11-18
2+
3+
* Support for v2.0.0 wp-json-api WordPress plugin
4+
15
## [0.1.4] - 2020-06-16
26

37
* Meta data now is returned for users

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ In your flutter project add the dependency:
2525
``` dart
2626
dependencies:
2727
...
28-
wp_json_api: ^0.1.4
28+
wp_json_api: ^2.0.0
2929
```
3030

3131
### Usage example #
@@ -208,6 +208,6 @@ For help getting started with WooSignal, view our
208208
To use this plugin, add `wp_json_api` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).
209209

210210
## Note
211-
Install WordPress plugin "WP JSON API" 2.0.x or later for version 0.1.4
211+
Install WordPress plugin "WP JSON API" 3.0.x or later for version 2.0.0
212212

213213
Disclaimer: This plugin is not affiliated with or supported by Automattic, Inc. All logos and trademarks are the property of their respective owners.

lib/networking/network_manager.dart

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class WPAppNetworkManager {
192192
Future<WPUserInfoResponse> wpGetUserInfo(String userToken) async {
193193
// send http request
194194
final json = await _http(
195-
method: "GET",
195+
method: "POST",
196196
url: _urlForRouteType(WPRouteType.UserInfo),
197197
userToken: userToken,
198198
);
@@ -267,7 +267,7 @@ class WPAppNetworkManager {
267267
Future<WCCustomerInfoResponse> wcCustomerInfo(String userToken) async {
268268
// send http request
269269
final json = await _http(
270-
method: "GET",
270+
method: "POST",
271271
url: _urlForRouteType(WPRouteType.WCCustomerInfo),
272272
userToken: userToken,
273273
);
@@ -376,22 +376,23 @@ class WPAppNetworkManager {
376376
Future<dynamic> _http(
377377
{@required String method,
378378
@required String url,
379-
dynamic body,
379+
Map<String, dynamic> body,
380380
String userToken}) async {
381381
var response;
382382
if (method == "GET") {
383383
response = await http.get(
384384
url,
385-
headers: (userToken == null ? null : _authHeader(userToken)),
386385
);
387386
} else if (method == "POST") {
388387
Map<String, String> headers = {
389388
HttpHeaders.contentTypeHeader: "application/json",
390389
};
390+
if (body == null) {
391+
body = {};
392+
}
391393
if (userToken != null) {
392-
headers.addAll(_authHeader(userToken));
394+
body.addAll({"token": userToken});
393395
}
394-
395396
response = await http.post(
396397
url,
397398
body: jsonEncode(body),
@@ -426,14 +427,6 @@ class WPAppNetworkManager {
426427
if (WPJsonAPI.instance.shouldDebug()) log(strOutput);
427428
}
428429

429-
/// Sets the authorization header for a request using the
430-
/// [userToken] has the API bearer token.
431-
///
432-
/// Returns a map of the authorizationHeader.
433-
Map<String, String> _authHeader(userToken) {
434-
return {HttpHeaders.authorizationHeader: "Bearer " + userToken};
435-
}
436-
437430
/// Checks if a response payload has a bad status (=> 500).
438431
///
439432
/// Returns [bool] true if status is => 500.
@@ -471,7 +464,7 @@ class WPAppNetworkManager {
471464
/// Returns [String] url path for request.
472465
String _getRouteUrlForType(
473466
WPRouteType wpRouteType, {
474-
String apiVersion = 'v1',
467+
String apiVersion = 'v2',
475468
}) {
476469
switch (wpRouteType) {
477470
// AUTH API

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: wp_json_api
22
description: WordPress and WooCommerce JSON API for Flutter Mobile. API allows you to login, register new users, get users info and more.
3-
version: 0.1.4
3+
version: 2.0.0
44
homepage: https://woosignal.com
55
repository: https://github.com/woosignal/wp-json-api-flutter
66
issue_tracker: https://github.com/woosignal/wp-json-api-flutter/issues

0 commit comments

Comments
 (0)