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