/**
  * Make a call to the Eventbrite v3 REST API, or return an existing transient.
  *
  * @access public
  *
  * @param string $endpoint Valid Eventbrite v3 API endpoint.
  * @param array $params Parameters passed to the API during a call.
  * @param int|string|bool $id A specific event ID used for calls to the event_details endpoint.
  * @param bool $force Force a fresh API call, ignoring any existing transient.
  * @return object Request results
  */
 public function request($endpoint, $params = array(), $id = false, $force = false)
 {
     // Make sure the endpoint and parameters are valid.
     if (!$this->validate_endpoint_params($endpoint, $params)) {
         return false;
     }
     // If an ID has been passed, validate and sanitize it.
     if (!empty($id) && is_numeric($id) && 0 < absint($id)) {
         $id = absint($id);
     } else {
         $id = false;
     }
     // Return a cached result if we have one.
     if (!$force) {
         $cached = $this->get_cache($endpoint, $params);
         if (!empty($cached)) {
             return $cached;
         }
     }
     // Extend the HTTP timeout to account for Eventbrite API calls taking longer than ~5 seconds.
     add_filter('http_request_timeout', array($this, 'increase_timeout'));
     // Make a fresh request.
     $request = Eventbrite_API::call($endpoint, $params, $id);
     // Remove the timeout extension for any non-Eventbrite calls.
     remove_filter('http_request_timeout', array($this, 'increase_timeout'));
     // If we get back a proper response, cache it.
     if (!is_wp_error($request)) {
         $transient_name = $this->get_transient_name($endpoint, $params);
         set_transient($transient_name, $request, apply_filters('eventbrite_cache_expiry', DAY_IN_SECONDS));
         $this->register_transient($transient_name);
     }
     return $request;
 }
 /**
  * Constructor.
  */
 function __construct()
 {
     parent::__construct();
     // Remove duplicate UI elements caused by constructors.
     remove_action('keyring_eventbrite_manage_ui', array($this, 'basic_ui'));
     remove_filter('keyring_eventbrite_basic_ui_intro', array($this, 'basic_ui_intro'));
     self::$instance = $this;
     $token = get_option('eventbrite_api_token');
     if (!empty($token)) {
         $this->set_token(Keyring::init()->get_token_store()->get_token(array('type' => 'access', 'id' => $token)));
     }
     $this->define_endpoints();
     add_action('keyring_connection_verified', array($this, 'keyring_connection_verified'), 10, 3);
     add_action('keyring_connection_deleted', array($this, 'keyring_connection_deleted'));
 }