AS_CM_Helpers_Transfer::remove_environment_type_from_key( $key ),
'domain' => $domain,
'type' => implode( ',', $types )
)
);
if ( $data === FALSE || ! is_array( $data ) ) {
return new WP_Error( 'error_loading',
/* translators: %s: link to adsimple.at */
sprintf( __( 'Error loading data from %s. Please repeat your request later.', 'adsimple-cookie-manager-for-wp' ),
'adsimple.at'
)
);
}
switch ( $data['status'] ) {
case 'without_pricing_plan':
return new WP_Error( 'invalid_adsimple_id',
/* translators: %s: link to adsimple.at pricing plan page */
sprintf( __( 'First you should select pricing plan on %s', 'adsimple-cookie-manager-for-wp' ),
'adsimple.at' ),
array(
'link' => array(
'href' => static::get_prepared_url_based_on_environment( self::LINK_TO_COOKIE_MANAGER_SERVICE ),
'text' => __( 'Select pricing plan', 'adsimple-cookie-manager-for-wp' ),
'target' => '_blank'
)
)
);
case 'invalid_adsimple_id':
return new WP_Error( 'invalid_adsimple_id', __( 'Invalid AdSimple ID', 'adsimple-cookie-manager-for-wp' ) );
case 'domain_not_exist':
/* translators: %s: domain name */
return new WP_Error( 'domain_not_exist', sprintf( __( "License doesn't include domain %s.",
'adsimple-cookie-manager-for-wp' ),
$domain ) );
case 'success':
if ( empty( $data['result'] ) ) {
/* translators: %s: domain name */
return new WP_Error( 'invalid_domain', sprintf( __( "Domain %s doesn't exist.", 'adsimple-cookie-manager-for-wp' ), $domain ) );
}
break;
}
return $data;
}
/**
* send request to REST server
*
* @param string $method
* @param string|null $key
* @param array $args
*
* @return boolean|array
*
* @since 1.0.0
* @since 2.0.2 added key
*
*/
public static function send_request_to_server( $method, $key = null, $args = array() ) {
return AS_CM_Helpers_Transfer::send_request( self::get_full_url( $method, $key ), $args );
}
/**
* get full url
*
* @param string $method
* @param string|null $key
*
* @return string
*
* @since 1.0.0
* @since 2.0.2 added key
*
*/
public static function get_full_url( $method, $key = null ) {
return static::get_prepared_url_based_on_environment(
sprintf(
'%s/%s/%s/%s',
static::SERVER_URL,
static::REST_DIRECTORY,
static::REST_VERSION,
$method
),
$key
);
}
/**
* get prepared url based on environment
*
* @param string $url
* @param string|null $key
*
* @return string
*
* @since 2.0.2
*/
public static function get_prepared_url_based_on_environment( $url, $key = null ) {
if ( is_null( $key ) ) {
$key = AS_CM_Controllers_Options::get_option_adsimple_id();
}
$environment = AS_CM_Helpers_Transfer::get_environment( $key );
return sprintf( $url, empty( $environment ) ? 'www' : $environment );
}
private function __clone() {}
}