| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Config; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Exceptions\OAuth\Tokens\Empty_Property_Exception; |
| 6 |
use Yoast\WP\SEO\Helpers\Options_Helper; |
| 7 |
use Yoast\WP\SEO\Wrappers\WP_Remote_Handler; |
| 8 |
use YoastSEO_Vendor\GuzzleHttp\Client; |
| 9 |
use YoastSEO_Vendor\League\OAuth2\Client\Provider\GenericProvider; |
| 10 |
|
| 11 |
/** |
| 12 |
* Class SEMrush_Client |
| 13 |
*/ |
| 14 |
class SEMrush_Client extends OAuth_Client { |
| 15 |
|
| 16 |
/** |
| 17 |
* The option's key. |
| 18 |
*/ |
| 19 |
const TOKEN_OPTION = 'semrush_tokens'; |
| 20 |
|
| 21 |
/** |
| 22 |
* SEMrush_Client constructor. |
| 23 |
* |
| 24 |
* @param Options_Helper $options_helper The Options_Helper instance. |
| 25 |
* @param WP_Remote_Handler $wp_remote_handler The request handler. |
| 26 |
* |
| 27 |
* @throws Empty_Property_Exception Throws when one of the required properties is empty. |
| 28 |
*/ |
| 29 |
public function __construct( |
| 30 |
Options_Helper $options_helper, |
| 31 |
WP_Remote_Handler $wp_remote_handler |
| 32 |
) { |
| 33 |
$provider = new GenericProvider( |
| 34 |
[ |
| 35 |
'clientId' => 'yoast', |
| 36 |
'clientSecret' => 'YdqNsWwnP4vE54WO1ugThKEjGMxMAHJt', |
| 37 |
'redirectUri' => 'https://oauth.semrush.com/oauth2/yoast/success', |
| 38 |
'urlAuthorize' => 'https://oauth.semrush.com/oauth2/authorize', |
| 39 |
'urlAccessToken' => 'https://oauth.semrush.com/oauth2/access_token', |
| 40 |
'urlResourceOwnerDetails' => 'https://oauth.semrush.com/oauth2/resource', |
| 41 |
], |
| 42 |
[ |
| 43 |
'httpClient' => new Client( [ 'handler' => $wp_remote_handler ] ), |
| 44 |
] |
| 45 |
); |
| 46 |
|
| 47 |
parent::__construct( |
| 48 |
self::TOKEN_OPTION, |
| 49 |
$provider, |
| 50 |
$options_helper |
| 51 |
); |
| 52 |
} |
| 53 |
} |
| 54 |
|