Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add non pretty url #3

Merged
merged 5 commits into from
Dec 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/Requests/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ protected function request(

$response = $http->{$method}($this->getUrl($path), $options);

if (!($response instanceof Response)) {
throw new UnexpectedValueException();
if (!($response instanceof Response) || $response->json() === null) {
$response = $http->{$method}($this->getNonPrettyUrl($path), $options);

if ((!($response instanceof Response) || $response->json() === null)) {
Lyrisbee marked this conversation as resolved.
Show resolved Hide resolved
throw new UnexpectedValueException();
}
}

if (!$response->successful()) {
Expand Down Expand Up @@ -82,6 +86,15 @@ public function getUrl(string $path): string
);
}

public function getNonPrettyUrl(string $path): string
Lyrisbee marked this conversation as resolved.
Show resolved Hide resolved
{
return sprintf('%s?rest_route=/wp/%s/%s',
rtrim($this->app->site(), '/'),
self::VERSION,
ltrim($path, '/')
);
}

/**
* @param array<string, array<int, string>> $headers
*
Expand Down
Loading