Tribe__Events__Aggregator__Service::get( string $endpoint, array $data = array() )
Performs a GET request against the Event Aggregator service
Contents
Parameters
- $endpoint
-
(string) (Required) Endpoint for the Event Aggregator service
- $data
-
(array) (Optional) Parameters to send to the endpoint
Default value: array()
Return
(stdClass|WP_Error)
Source
File: src/Tribe/Aggregator/Service.php
public function get( $endpoint, $data = array() ) {
$url = $this->build_url( $endpoint, $data );
// If we have an WP_Error we return it here
if ( is_wp_error( $url ) ) {
return $url;
}
/**
* Length of time to wait when initially connecting to Event Aggregator before abandoning the attempt.
* default is 60 seconds. We set this high so large files can be transfered on slow connections
*
* @var int $timeout_in_seconds
*/
$timeout_in_seconds = (int) apply_filters( 'tribe_aggregator_connection_timeout', 60 );
$response = $http_response = $this->requests->get(
esc_url_raw( $url ),
array( 'timeout' => $timeout_in_seconds )
);
if ( is_wp_error( $response ) ) {
if ( isset( $response->errors['http_request_failed'] ) ) {
$response->errors['http_request_failed'][0] = __( 'Connection timed out while transferring the feed. If you are dealing with large feeds you may need to customize the tribe_aggregator_connection_timeout filter.', 'the-events-calendar' );
}
return $response;
}
if ( 403 == wp_remote_retrieve_response_code( $response ) ) {
return new WP_Error(
'core:aggregator:request-denied',
esc_html__( 'Event Aggregator server has blocked your request. Please try your import again later or contact support to know why.', 'the-events-calendar' )
);
}
// we know it is not a 404 or 403 at this point
if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
return new WP_Error(
'core:aggregator:bad-response',
esc_html__( 'There may be an issue with the Event Aggregator server. Please try your import again later.', 'the-events-calendar' )
);
}
if ( isset( $response->data ) && isset( $response->data->status ) && '404' === $response->data->status ) {
return new WP_Error(
'core:aggregator:daily-limit-reached',
esc_html__( 'There may be an issue with the Event Aggregator server. Please try your import again later.', 'the-events-calendar' )
);
}
// if the response is not an image, let's json decode the body
if ( ! preg_match( '/image/', $response['headers']['content-type'] ) ) {
$response = json_decode( wp_remote_retrieve_body( $response ) );
}
// It's possible that the json_decode() operation will have failed
if ( null === $response ) {
return new WP_Error(
'core:aggregator:bad-json-response',
esc_html__( 'The response from the Event Aggregator server was badly formed and could not be understood. Please try again.', 'the-events-calendar' ),
$http_response
);
}
return $response;
}