PluginProbe
Parse.ly / 3.16.1
Parse.ly v3.16.1
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.16.1, at src/Endpoints/class-related-api-proxy.php

62 lines 1.4 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 Parsely\Parsely;
14 use stdClass;
15 use WP_REST_Request;
16 use WP_Error;
17
18 /**
19 * Configures the `/related` REST API endpoint.
20 */
21 final class Related_API_Proxy extends Base_API_Proxy {
22
23 /**
24 * Registers the endpoint's WP REST route.
25 */
26 public function run(): void {
27 $this->register_endpoint( '/related' );
28 }
29
30 /**
31 * Cached "proxy" to the Parse.ly `/related` API endpoint.
32 *
33 * @param WP_REST_Request $request The request object.
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 $itm_source = $this->itm_source;
48
49 return array_map(
50 static function ( stdClass $item ) use ( $itm_source ) {
51 return (object) array(
52 'image_url' => $item->image_url,
53 'thumb_url_medium' => $item->thumb_url_medium,
54 'title' => $item->title,
55 'url' => Parsely::get_url_with_itm_source( $item->url, $itm_source ),
56 );
57 },
58 $response
59 );
60 }
61 }
62