From c94ae22c3d417fb3089e87ba1544d8eacd973609 Mon Sep 17 00:00:00 2001 From: Bartosz Budzanowski Date: Fri, 13 Oct 2023 02:18:44 +0200 Subject: [PATCH 1/2] Add V5 ads supported countries. --- ...or-woocommerce-ads-supported-countries.php | 12 +++-------- src/API/APIV5.php | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/includes/class-pinterest-for-woocommerce-ads-supported-countries.php b/includes/class-pinterest-for-woocommerce-ads-supported-countries.php index 08ba0a405..cf078e2af 100644 --- a/includes/class-pinterest-for-woocommerce-ads-supported-countries.php +++ b/includes/class-pinterest-for-woocommerce-ads-supported-countries.php @@ -6,7 +6,7 @@ * @since 1.0.5 */ -use Automattic\WooCommerce\Pinterest\API\Base; +use Automattic\WooCommerce\Pinterest\API\APIV5; if ( ! defined( 'ABSPATH' ) ) { exit; @@ -40,16 +40,10 @@ public static function get_countries() { throw new Exception( 'Pinterest user is not connected, using fallback list of supported countries.' ); } - $allowed_countries = Base::get_list_of_ads_supported_countries(); - $get_country_code = function( $country_object ) { - return $country_object->code; - }; + $allowed_countries = APIV5::get_list_of_ads_supported_countries(); // Extract codes. - $allowed_countries_codes = array_map( - $get_country_code, - $allowed_countries['data'], - ); + $allowed_countries_codes = array_column( $allowed_countries['items'], 'code' ); return $allowed_countries_codes; } catch ( Exception $th ) { diff --git a/src/API/APIV5.php b/src/API/APIV5.php index 21654be25..ab965d97a 100644 --- a/src/API/APIV5.php +++ b/src/API/APIV5.php @@ -73,6 +73,26 @@ public static function get_account_info() { return self::make_request( 'user_account', 'GET' ); } + /** + * Pull ads supported countries information from the API. + * + * @since x.x.x + * + * @return array { + * Ad Accounts countries + * + * @type array[] $items { + * @type string $code Country ID from ISO 3166-1 alpha-2. + * @type string $currency Country currency. + * @type int $index Country index + * @type string $name Country name. + * } + * } + */ + public static function get_list_of_ads_supported_countries() { + $request_url = 'resources/ad_account_countries'; + return self::make_request( $request_url, 'GET', array(), '', 2 * DAY_IN_SECONDS ); + } /** * Returns the list of the user's websites. From c91f36eab8d5d60641a73ec9efb4a8507e518ea0 Mon Sep 17 00:00:00 2001 From: Bartosz Budzanowski Date: Fri, 13 Oct 2023 02:27:22 +0200 Subject: [PATCH 2/2] Fix whitespace. --- src/API/APIV5.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/API/APIV5.php b/src/API/APIV5.php index ab965d97a..905247e45 100644 --- a/src/API/APIV5.php +++ b/src/API/APIV5.php @@ -78,7 +78,7 @@ public static function get_account_info() { * * @since x.x.x * - * @return array { + * @return array { * Ad Accounts countries * * @type array[] $items {