コード例 #1
0
 public function run(Config $config)
 {
     $client = RestClient::create(['base_url' => $this->baseUrl, 'defaults' => ['headers' => UserFunction::build($this->headers, ['attr' => $config->getAttributes()])]], JuicerRest::convertRetry($this->retryConfig));
     if (!empty($this->defaultRequestOptions)) {
         $client->setDefaultRequestOptions($this->defaultRequestOptions);
     }
     $this->auth->authenticateClient($client);
     // Verbose Logging of all requests
     $client->getClient()->getEmitter()->attach(new LogRequest());
     if ($this->cache) {
         CacheSubscriber::attach($client->getClient(), ['storage' => $this->cache, 'validate' => false, 'can_cache' => function (RequestInterface $requestInterface) {
             return true;
         }]);
     }
     $this->initParser($config);
     $builder = new Builder();
     foreach ($config->getJobs() as $jobConfig) {
         $this->runJob($jobConfig, $client, $config, $builder);
     }
     if ($this->parser instanceof Json) {
         // FIXME fallback from JsonMap
         $this->metadata = array_replace_recursive($this->metadata, $this->parser->getMetadata());
     }
     //         return $this->parser->getResults();
 }
コード例 #2
0
 public function testConvert()
 {
     $oldConfig = ['maxRetries' => 6, 'curlCodes' => [6], 'httpCodes' => [503], 'headerName' => 'Retry-After', 'custom' => 'value'];
     $newConfig = JuicerRest::convertRetry($oldConfig);
     // items
     $this->assertArrayHasKey('maxRetries', $newConfig);
     $this->assertArrayHasKey('custom', $newConfig);
     $this->assertArrayHasKey('curl', $newConfig);
     $this->assertArrayHasKey('codes', $newConfig['curl']);
     $this->assertArrayHasKey('http', $newConfig);
     $this->assertArrayHasKey('codes', $newConfig['http']);
     $this->assertArrayHasKey('retryHeader', $newConfig['http']);
     // item values
     $this->assertSame($oldConfig['custom'], $newConfig['custom']);
     $this->assertSame($oldConfig['maxRetries'], $newConfig['maxRetries']);
     $this->assertSame($oldConfig['curlCodes'], $newConfig['curl']['codes']);
     $this->assertSame($oldConfig['httpCodes'], $newConfig['http']['codes']);
     $this->assertSame($oldConfig['headerName'], $newConfig['http']['retryHeader']);
     // removed items
     $this->assertArrayNotHasKey('curlCodes', $newConfig);
     $this->assertArrayNotHasKey('httpCodes', $newConfig);
     $this->assertArrayNotHasKey('headerName', $newConfig);
 }