Skip to content

Commit

Permalink
chore: Bump wordpress_client version to 8.4.7 and fix bug in utility …
Browse files Browse the repository at this point in the history
…functions
  • Loading branch information
ArunPrakashG committed May 12, 2024
1 parent 7f9afb2 commit f110b7c
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@
- 🛠 Added validations for entered `baseUrl`.
- 💥Renamed `executeGuarded` to `guardAsync` and added a new `guard` method to guard synchronous functions.

## 🐛 8.4.7

- 🩹 Bug fixes
- 🛠 Fix validations for entered `baseUrl`; Supporting sites with custom REST Api paths

## Legend

- 🎉 New features or major changes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Add `wordpress_client` in your `pubspec.yaml`:

```dart
dependencies:
wordpress_client: ^8.4.6
wordpress_client: ^8.4.7
```

> 💡 Ensure you get the [latest version here](https://pub.dev/packages/wordpress_client).
Expand Down
2 changes: 1 addition & 1 deletion lib/src/operations/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ base mixin CreateOperation<T, R extends IRequest> on IRequestInterface {
Future<WordpressRawResponse> createRaw(R request) async {
final wpRequest = await request.build(baseUrl);

return executor.execute(wpRequest);
return executor.raw(wpRequest);
}
}
2 changes: 1 addition & 1 deletion lib/src/operations/custom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ base mixin CustomOperation<T, R extends IRequest> on IRequestInterface {
Future<WordpressRawResponse> raw(R request) async {
final wpRequest = await request.build(baseUrl);

return executor.execute(wpRequest);
return executor.raw(wpRequest);
}
}
2 changes: 1 addition & 1 deletion lib/src/operations/delete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ base mixin DeleteOperation<R extends IRequest> on IRequestInterface {
Future<WordpressRawResponse> deleteRaw(R request) async {
final wpRequest = await request.build(baseUrl);

return executor.execute(wpRequest);
return executor.raw(wpRequest);
}
}
2 changes: 1 addition & 1 deletion lib/src/operations/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ base mixin ListOperation<T, R extends IRequest> on IRequestInterface {
) async {
final wpRequest = await request.build(baseUrl);

return executor.execute(wpRequest);
return executor.raw(wpRequest);
}
}
2 changes: 1 addition & 1 deletion lib/src/operations/retrieve.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ base mixin RetrieveOperation<T, R extends IRequest> on IRequestInterface {
Future<WordpressRawResponse> retrieveRaw(R request) async {
final wpRequest = await request.build(baseUrl);

return executor.execute(wpRequest);
return executor.raw(wpRequest);
}
}
2 changes: 1 addition & 1 deletion lib/src/operations/update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ base mixin UpdateOperation<T, R extends IRequest> on IRequestInterface {
Future<WordpressRawResponse> updateRaw(R request) async {
final wpRequest = await request.build(baseUrl);

return executor.execute(wpRequest);
return executor.raw(wpRequest);
}
}
35 changes: 35 additions & 0 deletions lib/src/request_executor_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,41 @@ abstract base class IRequestExecutor {
);
}

@internal
Future<WordpressRawResponse> raw(WordpressRequest request) async {
return guardAsync<WordpressRawResponse>(
function: () async {
request = await _handleRequestMiddlewares(
request: request,
middlewares: middlewares,
);

return _handleResponseMiddlewares(
middlewares: middlewares,
response: await execute(request),
);
},
onError: (error, stackTrace) async {
final isMiddlewareAbortedException =
error is MiddlewareAbortedException;

return WordpressRawResponse(
data: null,
code: isMiddlewareAbortedException
? -RequestErrorType.middlewareAborted.index
: -RequestErrorType.internalGenericError.index,
extra: <String, dynamic>{
'error': error,
'stackTrace': stackTrace,
},
message: isMiddlewareAbortedException
? error.message
: '$error\n\n$stackTrace',
);
},
);
}

@internal
Future<WordpressResponse<T>> create<T>(
WordpressRequest request,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/responses/wordpress_raw_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ final class WordpressRawResponse {
);
}

/// Returns the error and stack trace if the response is a failure.
(Object, StackTrace) getError() => (extra['error'], extra['stackTrace']);

/// Maps this instance to a [WordpressResponse] instance.
///
/// The [onSuccess] is called if the response is a success.
Expand Down
3 changes: 2 additions & 1 deletion lib/src/utilities/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ bool isValidRestApiUrl(Uri uri, {bool forceHttps = false}) {
return false;
}

return uri.pathSegments.first == 'wp-json';
// It is possible to not have wp-json on some websites but I don't plan on supporting those in this package because it goes outside of the standards defined by WordPress.
return uri.pathSegments.contains('wp-json');
}

bool isValidPortNumber(int port) => port >= 0 && port <= 65535;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: wordpress_client
description: A library to interact with the Wordpress REST API. Supports most of the common endpoints and all of the CRUD operations on the endpoints.
version: 8.4.6
version: 8.4.7
topics:
- wordpress
- fluent
Expand Down

0 comments on commit f110b7c

Please sign in to comment.