PluginProbe
Parse.ly / 3.8.4
Parse.ly v3.8.4
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 3.20.3 All 105 releases
wp-parsely / src / Endpoints / class-related-api-proxy.php

class-related-api-proxy.php in Parse.ly 3.8.4, at src/Endpoints/class-related-api-proxy.php

60 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Endpoints: Parse.ly `/related` API proxy endpoint class
4 *
5 * @package Parsely
6 * @since 3.2.0
7 */
8
9 declare(strict_types=1);
10
11 namespace Parsely\Endpoints;
12
13 use stdClass;
14 use WP_REST_Request;
15 use WP_Error;
16
17 /**
18 * Configures the `/related` REST API endpoint.
19 */
20 final class Related_API_Proxy extends Base_API_Proxy {
21
22 /**
23 * Registers the endpoint's WP REST route.
24 */
25 public function run(): void {
26 $this->register_endpoint( '/related' );
27 }
28
29 /**
30 * Cached "proxy" to the Parse.ly `/related` API endpoint.
31 *
32 * @param WP_REST_Request $request The request object.
33 *
34 * @return stdClass|WP_Error stdClass containing the data or a WP_Error object on failure.
35 */
36 public function get_items( WP_REST_Request $request ) {
37 return $this->get_data( $request, false, 'query' );
38 }
39
40 /**
41 * Generates the final data from the passed response.
42 *
43 * @param array<stdClass> $response The response received by the proxy.
44 * @return array<stdClass> The generated data.
45 */
46 protected function generate_data( $response ): array {
47 return array_map(
48 static function( stdClass $item ) {
49 return (object) array(
50 'image_url' => $item->image_url,
51 'thumb_url_medium' => $item->thumb_url_medium,
52 'title' => $item->title,
53 'url' => $item->url,
54 );
55 },
56 $response
57 );
58 }
59 }
60