/**
* Calls the API and, if successfull, returns the object delivered by the API.
*
* @uses get_bloginfo()
* @uses wp_remote_post()
* @uses is_wp_error()
*
* @return false||object
*/
protected function call_remote_api()
{
// only check if a transient is not set (or if it's expired)
if (get_transient($this->product->get_slug() . '-update-check-error') !== false) {
return false;
}
// setup api parameters
$api_params = array('edd_action' => 'get_version', 'license' => $this->license_key, 'name' => $this->product->get_item_name(), 'slug' => $this->product->get_slug(), 'author' => $this->product->get_author());
// setup request parameters
$request_params = array('method' => 'POST', 'body' => $api_params);
require_once dirname(__FILE__) . '/class-api-request.php';
$request = new Yoast_API_Request($this->product->get_api_url(), $request_params);
if ($request->is_valid() !== true) {
// show error message
$this->error_message = $request->get_error_message();
add_action('admin_notices', array($this, 'show_update_error'));
// set a transient to prevent checking for updates on every page load
set_transient($this->product->get_slug() . '-update-check-error', 1, DAY_IN_SECONDS);
// 30 mins
return false;
}
// decode response
$response = $request->get_response();
$response->sections = maybe_unserialize($response->sections);
return $response;
}