PluginProbe
Parse.ly / 3.24.2
Parse.ly v3.24.2
3.24.2 3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 All 106 releases
wp-parsely / src / services / content-api / endpoints / class-endpoint-related.php

class-endpoint-related.php in Parse.ly 3.24.2, at src/services/content-api/endpoints/class-endpoint-related.php

92 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Parse.ly Content API Endpoint: Related
4 *
5 * @package Parsely
6 * @since 3.17.0
7 */
8
9 declare(strict_types=1);
10
11 namespace Parsely\Services\Content_API\Endpoints;
12
13 use Parsely\Services\Base_Service_Endpoint;
14 use WP_Error;
15
16 /**
17 * The endpoint for the /related API request.
18 *
19 * @since 3.17.0
20 *
21 * @link https://docs.parse.ly/content-recommendations/#h-get-related
22 *
23 * @phpstan-import-type WP_HTTP_Request_Args from Base_Service_Endpoint
24 */
25 class Endpoint_Related extends Content_API_Base_Endpoint {
26 /**
27 * Returns the endpoint for the API request.
28 *
29 * @since 3.17.0
30 *
31 * @return string
32 */
33 public function get_endpoint(): string {
34 return '/related';
35 }
36
37 /**
38 * Returns the request options for the remote API request.
39 *
40 * This request also serves site visitors, through the Recommendations
41 * Block, so it uses a short timeout.
42 *
43 * @since 3.24.2
44 *
45 * @param string $method The HTTP method to use for the request.
46 * @return WP_HTTP_Request_Args The request options for the remote API request.
47 */
48 protected function get_request_options( string $method ): array {
49 $options = parent::get_request_options( $method );
50 $options['timeout'] = 5; // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout
51
52 return $options;
53 }
54
55 /**
56 * Returns the common query arguments to send to the remote API.
57 *
58 * Omits the API Secret, which /related doesn't need.
59 *
60 * @since 3.24.2
61 *
62 * @param array<mixed> $args Additional query arguments to send to the remote API.
63 * @return array<mixed> The query arguments to send to the remote API.
64 */
65 protected function get_query_args( array $args = array() ): array {
66 $query_args = parent::get_query_args( $args );
67 unset( $query_args['secret'] );
68
69 return $query_args;
70 }
71
72 /**
73 * Executes the API request.
74 *
75 * @since 3.17.0
76 *
77 * @param array<mixed> $args The arguments to pass to the API request.
78 * @return WP_Error|array<mixed> The response from the API request.
79 */
80 public function call( array $args = array() ) {
81 // Filter out the empty values.
82 $args = array_filter( $args );
83
84 // When the URL is provided, the UUID cannot be provided.
85 if ( isset( $args['uuid'] ) && isset( $args['url'] ) ) {
86 unset( $args['uuid'] );
87 }
88
89 return $this->request( 'GET', $args );
90 }
91 }
92