function bullhorn_sync_now() { $bullhorn_connection = new Bullhorn_Connection(); return $bullhorn_connection->sync(); }
/** * Every 10 minutes we need to refresh our access token for continued access * to the API. We first determine if we need to refresh, and then we need to * request a new token from Bullhorn if our current one has expired. * * @return boolean */ protected static function refresh_token($force = false) { // error_log( 'refresh token start' ); // TODO: stop re-calling every time $eight_mins_ago = strtotime('8 minutes ago'); if (false !== $force && $eight_mins_ago <= self::$api_access['last_refreshed']) { error_log('refresh token last refreshed' . self::$api_access['last_refreshed']); return true; } // ok lets not do this if we have already done it in the last 20 sec if (false !== get_transient('get_bullhorn_token')) { // error_log( 'bullhorn token transient set action' ); return true; } set_transient('get_bullhorn_token', self::$api_access['last_refreshed'], 20); // TODO: return false if client not set and add handlers for the call if (null === self::$api_access['refresh_token'] || null === self::$settings['client_id'] || null === self::$settings['client_secret']) { add_action('admin_notices', array(__CLASS__, 'no_token_admin_notice')); return false; } $url = add_query_arg(array('grant_type' => 'refresh_token', 'refresh_token' => self::$api_access['refresh_token'], 'client_id' => self::$settings['client_id'], 'client_secret' => self::$settings['client_secret']), 'https://auth.bullhornstaffing.com/oauth/token'); $response = wp_remote_post($url); if (!is_array($response)) { return false; } $body = json_decode($response['body'], true); if (isset($body['access_token'])) { $body['last_refreshed'] = time(); update_option('bullhorn_api_access', $body); self::$api_access = $body; // error_log( 'refresh token finish' ); return true; } elseif (isset($body['error_description'])) { wp_die($body['error_description']); } return false; }