Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/optimize calls to advertisers countries #805

Merged
merged 7 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* @since 1.0.5
*/

use Automattic\WooCommerce\Pinterest\API\Base;
use Automattic\WooCommerce\Pinterest\API\Base;
use \Exception;
budzanowski marked this conversation as resolved.
Show resolved Hide resolved

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand All @@ -24,10 +25,21 @@
*
* @see https://help.pinterest.com/en/business/availability/ads-availability
*
* @since x.x.x Don't fetch the list of supported countries if the user is not connected. Use a fallback instead.
*

Check failure on line 29 in includes/class-pinterest-for-woocommerce-ads-supported-countries.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
* @throws Exception If the user is not connected and the list of supported countries can't be fetched.
*
* @return string[]
*/
public static function get_countries() {
try {
/*
* If the user is not connected, we can't get the list of supported countries.
* We throw an exception and use a fallback.
*/
if ( ! Pinterest_For_Woocommerce()::is_connected() ) {
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 ) {
Expand All @@ -41,7 +53,7 @@
);

return $allowed_countries_codes;
} catch ( \Exception $th ) {
} catch ( Exception $th ) {
// A fallback in case of error.
return array(
'AR', // Argentina.
Expand Down
2 changes: 1 addition & 1 deletion src/API/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,6 @@ public static function get_available_discounts( $advertiser_id ) {
*/
public static function get_list_of_ads_supported_countries() {
$request_url = 'advertisers/countries';
return self::make_request( $request_url, 'GET', array(), 'ads', DAY_IN_SECONDS );
return self::make_request( $request_url, 'GET', array(), 'ads', 2 * DAY_IN_SECONDS );
}
}
Loading