| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
|
| 5 |
namespace Yoast\WP\SEO\AI\HTTP_Request\Infrastructure; |
| 6 |
|
| 7 |
use Exception; |
| 8 |
use Yoast\WP\SEO\AI\HTTP_Request\Domain\Exceptions\WP_Request_Exception; |
| 9 |
|
| 10 |
/** |
| 11 |
* Interface for the API client. |
| 12 |
*/ |
| 13 |
|
| 14 |
interface API_Client_Interface { |
| 15 |
|
| 16 |
/** |
| 17 |
* Performs a request to the API. |
| 18 |
* |
| 19 |
* @param string $action_path The action path for the request. |
| 20 |
* @param array<string>|null $body The body of the request, or null/empty to send no body. |
| 21 |
* @param array<string> $headers The headers for the request. |
| 22 |
* @param string $http_method The HTTP method for the request. One of `Request::METHOD_*`. |
| 23 |
* |
| 24 |
* @return array<int|string|array<string>> The response from the API. |
| 25 |
* |
| 26 |
* @throws WP_Request_Exception When the underlying WordPress HTTP call returns an error. |
| 27 |
*/ |
| 28 |
public function perform_request( string $action_path, $body, $headers, string $http_method ): array; |
| 29 |
|
| 30 |
/** |
| 31 |
* Gets the timeout of the requests in seconds. |
| 32 |
* |
| 33 |
* @return int The timeout of the suggestion requests in seconds. |
| 34 |
*/ |
| 35 |
public function get_request_timeout(): int; |
| 36 |
|
| 37 |
/** |
| 38 |
* Builds the full URL for a request to the AI API, applying the same filter perform_request() uses. |
| 39 |
* |
| 40 |
* @param string $action_path The action path for the request. |
| 41 |
* |
| 42 |
* @return string The full URL for the request. |
| 43 |
*/ |
| 44 |
public function get_url( string $action_path ): string; |
| 45 |
|
| 46 |
/** |
| 47 |
* Returns the RFC 8707 resource indicator for the AI API: the origin of the configured base URL. |
| 48 |
* |
| 49 |
* @return string The AI resource server origin (e.g. https://ai.yoa.st). |
| 50 |
*/ |
| 51 |
public function get_resource_url(): string; |
| 52 |
} |
| 53 |
|