Skip to content

Commit

Permalink
Merge pull request #832 from woocommerce/pinterest-v5-adds-supported-…
Browse files Browse the repository at this point in the history
…countries

Add V5 ads supported countries.
  • Loading branch information
budzanowski authored Oct 13, 2023
2 parents ff326f6 + c91f36e commit 1ba4a7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @since 1.0.5
*/

use Automattic\WooCommerce\Pinterest\API\Base;
use Automattic\WooCommerce\Pinterest\API\APIV5;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down Expand Up @@ -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 ) {
Expand Down
20 changes: 20 additions & 0 deletions src/API/APIV5.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1ba4a7c

Please sign in to comment.