Skip to content

Commit

Permalink
v0.1.4 update, class filenames refactored, now throws exceptions from…
Browse files Browse the repository at this point in the history
… responses plus other varies changes. Read Changelog for more info
  • Loading branch information
WooSignal committed Jun 15, 2020
1 parent b5c02c5 commit fc22cb4
Show file tree
Hide file tree
Showing 35 changed files with 793 additions and 200 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [0.1.4] - 2020-06-16

* Meta data now is returned for users
* Ability to store, update and delete meta data on WP_User
* Throw exceptions for requests
* Handle async await in callback
* Updated models
* Refactor model file names
* More documentation added in code

## [0.1.3] - 2020-06-03

* pubspec.yaml update
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ In your flutter project add the dependency:
``` dart
dependencies:
...
wp_json_api: ^0.1.3
wp_json_api: ^0.1.4
```

### Usage example #
Expand All @@ -50,11 +50,15 @@ WPJsonAPI.instance.initWith(baseUrl: "https://mysite.com");

### Call a method from the request callback
``` dart
try {
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
.api((request) => request.wpLogin(
email: email,
password: password
));
} on Exception catch (e) {
print(e);
}
```

### Available API Requests
Expand Down Expand Up @@ -203,4 +207,7 @@ For help getting started with WooSignal, view our
## Usage
To use this plugin, add `wp_json_api` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).

## Note
Install WordPress plugin "WP JSON API" 2.0.x or later for version 0.1.4

Disclaimer: This plugin is not affiliated with or supported by Automattic, Inc. All logos and trademarks are the property of their respective owners.
21 changes: 13 additions & 8 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:wp_json_api/enums/WPAuthType.dart';
import 'package:wp_json_api/models/responses/WPUserInfoResponse.dart';
import 'package:wp_json_api/models/responses/WPUserLoginResponse.dart';
import 'package:wp_json_api/enums/wp_auth_type.dart';
import 'package:wp_json_api/models/responses/wp_user_info_response.dart';
import 'package:wp_json_api/models/responses/wp_user_login_response.dart';
import 'package:wp_json_api/wp_json_api.dart';

void main() => runApp(MyApp());
Expand Down Expand Up @@ -50,12 +50,17 @@ class _MyHomePageState extends State<MyHomePage> {
String email = _tfEmailController.text;
String password = _tfPasswordController.text;

WPUserLoginResponse wpUserLoginResponse;
// LOGIN
WPUserLoginResponse wpUserLoginResponse =
await WPJsonAPI.instance.api((request) {
return request.wpLogin(
email: email, password: password, authType: WPAuthType.WpEmail);
});
try {
wpUserLoginResponse =
await WPJsonAPI.instance.api((request) {
return request.wpLogin(
email: email, password: password, authType: WPAuthType.WpEmail);
});
} on Exception catch (e) {
print(e);
}

if (wpUserLoginResponse != null) {
print(wpUserLoginResponse.data.userToken);
Expand Down
64 changes: 11 additions & 53 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
async:
dependency: transitive
description:
Expand All @@ -36,27 +22,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
collection:
clock:
dependency: transitive
description:
name: collection
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
convert:
version: "1.0.1"
collection:
dependency: transitive
description:
name: convert
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
version: "1.14.12"
fake_async:
dependency: transitive
description:
name: crypto
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
version: "1.1.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -81,13 +67,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.12"
matcher:
dependency: transitive
description:
Expand All @@ -108,28 +87,14 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
version: "1.7.0"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -197,13 +162,6 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.2"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.6.1"
version: "0.1.4"
sdks:
dart: ">=2.6.0 <3.0.0"
File renamed without changes.
30 changes: 30 additions & 0 deletions lib/enums/wp_meta_data_action_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2020, 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.

enum WPMetaDataActionType {
/// MetaData action type [WPMetaDataActionType.Create] is used for
/// creating/adding additional meta data to a key.
Create,

/// MetaData action type [WPMetaDataActionType.Update] is used for
/// updating a meta data key.
/// If the meta field for the user does not exist, it will be added.
Update,

/// MetaData action type [WPMetaDataActionType.Delete] is used for
/// deleting a meta data key and value. You can optionally pass in a [value]
/// to only remove that value from the the array of data.
Delete,
}
File renamed without changes.
19 changes: 19 additions & 0 deletions lib/exceptions/empty_username_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2020, 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 EmptyUsernameException implements Exception {
String message = 'The email field is empty';
EmptyUsernameException();
}
19 changes: 19 additions & 0 deletions lib/exceptions/existing_user_email_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2020, 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 ExistingUserEmailException implements Exception {
String message;
ExistingUserEmailException(this.message);
}
19 changes: 19 additions & 0 deletions lib/exceptions/existing_user_login_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2020, 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 ExistingUserLoginException implements Exception {
String message;
ExistingUserLoginException(this.message);
}
19 changes: 19 additions & 0 deletions lib/exceptions/incorrect_password_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2020, 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 IncorrectPasswordException implements Exception {
String message;
IncorrectPasswordException(this.message);
}
19 changes: 19 additions & 0 deletions lib/exceptions/invalid_email_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2020, 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 InvalidEmailException implements Exception {
String message;
InvalidEmailException(this.message);
}
19 changes: 19 additions & 0 deletions lib/exceptions/invalid_nonce_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2020, 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 InvalidNonceException implements Exception {
String message = 'Invalid nonce token';
InvalidNonceException();
}
19 changes: 19 additions & 0 deletions lib/exceptions/invalid_params_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2020, 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 InvalidParamsException implements Exception {
String message = 'Invalid parameters, please check the data';
InvalidParamsException();
}
19 changes: 19 additions & 0 deletions lib/exceptions/invalid_user_token_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2020, 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 InvalidUserTokenException implements Exception {
String message = 'Invalid user API token';
InvalidUserTokenException();
}
Loading

0 comments on commit fc22cb4

Please sign in to comment.