/** * @param array $config * @return Client */ public static function factory($config = array()) { $default = array('url' => self::DEFAULT_API_URL); $required = array('token'); $config = Collection::fromConfig($config, $default, $required); $config['curl.options'] = array(CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0); $config['request.options'] = array('headers' => array('X-StorageApi-Token' => $config->get('token'))); $client = new self($config->get('url'), $config); // Attach a service description to the client $description = ServiceDescription::factory(__DIR__ . '/service.json'); $client->setDescription($description); $client->setBaseUrl($config->get('url')); // Setup exponential backoff $backoffPlugin = BackoffPlugin::getExponentialBackoff(); $client->addSubscriber($backoffPlugin); return $client; }
/** * Factory method to create a new Client * * The following array keys and values are available options: * - url: Base URL of web service * - token: Storage API token * * @param array|Collection $config Configuration data * * @return self */ public static function factory($config = []) { $default = ['url' => 'https://syrup.keboola.com/gooddata-writer']; $required = ['token']; $config = Collection::fromConfig($config, $default, $required); $config['request.options'] = ['headers' => ['X-StorageApi-Token' => $config->get('token')], 'config' => ['curl' => [CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0]]]; $client = new self($config->get('url'), $config); // Attach a service description to the client $description = ServiceDescription::factory(__DIR__ . '/service.json'); $client->setDescription($description); $client->setBaseUrl($config->get('url')); // Setup exponential backoff // 503 retry always, other errors five times $backoffPlugin = new BackoffPlugin(new TruncatedBackoffStrategy(5, new HttpBackoffStrategy(null, new CurlBackoffStrategy(null, new ExponentialBackoffStrategy())))); $client->addSubscriber($backoffPlugin); return $client; }