PluginProbe
Parse.ly / 3.11.0
Parse.ly v3.11.0
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 / RemoteAPI / class-analytics-posts-api.php

class-analytics-posts-api.php in Parse.ly 3.11.0, at src/RemoteAPI/class-analytics-posts-api.php

93 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class for Analytics Posts API (`/analytics/posts`).
4 *
5 * @package Parsely
6 * @since 3.4.0
7 */
8
9 declare(strict_types=1);
10
11 namespace Parsely\RemoteAPI;
12
13 use WP_Error;
14
15 /**
16 * Class for Analytics Posts API (`/analytics/posts`).
17 *
18 * @since 3.4.0
19 *
20 * @phpstan-type Analytics_Post_API_Params array{
21 * apikey?: string,
22 * secret?: string,
23 * period_start?: string,
24 * period_end?: string,
25 * pub_date_start?: string,
26 * pub_date_end?: string,
27 * sort?: string,
28 * limit?: int<0, 2000>,
29 * }
30 *
31 * @phpstan-type Analytics_Post array{
32 * title?: string,
33 * url?: string,
34 * link?: string,
35 * author?: string,
36 * authors?: string[],
37 * section?: string,
38 * tags?: string[],
39 * metrics?: Analytics_Post_Metrics,
40 * full_content_word_count?: int,
41 * image_url?: string,
42 * metadata?: string,
43 * pub_date?: string,
44 * thumb_url_medium?: string,
45 * }
46 *
47 * @phpstan-type Analytics_Post_Metrics array{
48 * avg_engaged?: float,
49 * views?: int,
50 * visitors?: int,
51 * }
52 */
53 class Analytics_Posts_API extends Base_Endpoint_Remote {
54 public const MAX_RECORDS_LIMIT = 2000;
55 public const ANALYTICS_API_DAYS_LIMIT = 7;
56
57 protected const ENDPOINT = '/analytics/posts';
58 protected const QUERY_FILTER = 'wp_parsely_analytics_posts_endpoint_args';
59
60 /**
61 * Indicates whether the endpoint is public or protected behind permissions.
62 *
63 * @since 3.7.0
64 * @var bool
65 */
66 protected $is_public_endpoint = false;
67
68 /**
69 * Calls Parse.ly Analytics API to get posts info.
70 *
71 * Main purpose of this function is to enforce typing.
72 *
73 * @param Analytics_Post_API_Params $api_params Parameters of the API.
74 * @return Analytics_Post[]|WP_Error|null
75 */
76 public function get_posts_analytics( $api_params ) {
77 return $this->get_items( $api_params, true ); // @phpstan-ignore-line
78 }
79
80 /**
81 * Returns the request's options for the remote API call.
82 *
83 * @since 3.9.0
84 *
85 * @return array<string, mixed> The array of options.
86 */
87 protected function get_request_options(): array {
88 return array(
89 'timeout' => 30, // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout
90 );
91 }
92 }
93