| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong |
| 4 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded |
| 5 |
namespace Yoast\WP\SEO\Dashboard\Infrastructure\Analytics_4; |
| 6 |
|
| 7 |
use Google\Site_Kit\Core\REST_API\REST_Routes; |
| 8 |
use WP_REST_Request; |
| 9 |
use WP_REST_Response; |
| 10 |
|
| 11 |
/** |
| 12 |
* Class that hold the code to do the REST call to the Site Kit api. |
| 13 |
* |
| 14 |
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded |
| 15 |
*/ |
| 16 |
class Site_Kit_Analytics_4_Api_Call { |
| 17 |
|
| 18 |
/** |
| 19 |
* The Analytics 4 API route path. |
| 20 |
*/ |
| 21 |
private const ANALYTICS_DATA_REPORT_ROUTE = '/modules/analytics-4/data/report'; |
| 22 |
|
| 23 |
/** |
| 24 |
* Runs the internal REST api call. |
| 25 |
* |
| 26 |
* @param array<string, array<string, string>> $api_parameters The api parameters. |
| 27 |
* |
| 28 |
* @return WP_REST_Response |
| 29 |
*/ |
| 30 |
public function do_request( array $api_parameters ): WP_REST_Response { |
| 31 |
$request = new WP_REST_Request( 'GET', '/' . REST_Routes::REST_ROOT . self::ANALYTICS_DATA_REPORT_ROUTE ); |
| 32 |
$request->set_query_params( $api_parameters ); |
| 33 |
return \rest_do_request( $request ); |
| 34 |
} |
| 35 |
} |
| 36 |
|