Skip to content

Commit

Permalink
Add V5 ads supported countries.
Browse files Browse the repository at this point in the history
  • Loading branch information
budzanowski committed Oct 13, 2023
1 parent ff326f6 commit c94ae22
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 {

Check failure on line 81 in src/API/APIV5.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 81 in src/API/APIV5.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 5 space(s) before asterisk; 4 found
* 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 c94ae22

Please sign in to comment.