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();
 }
Esempio n. 2
0
 /**
  * @param array $config
  * @return RestRequest
  */
 protected function getAuthRequest(array $config)
 {
     if (empty($config['endpoint'])) {
         throw new UserException('Request endpoint must be set for the Login authentication method.');
     }
     if (!empty($config['params'])) {
         $config['params'] = UserFunction::build($config['params'], $this->params);
     }
     if (!empty($config['headers'])) {
         $config['headers'] = UserFunction::build($config['headers'], $this->params);
     }
     return RestRequest::create($config);
 }
 /**
  * @param JobConfig $config
  * @return array
  */
 protected function buildParams(JobConfig $config)
 {
     $params = UserFunction::build($config->getParams(), ['attr' => $this->attributes, 'time' => $this->metadata['time']], $this->stringBuilder);
     $config->setParams($params);
     return $params;
 }
 public function testBuild()
 {
     $functions = ['str' => 'aaa', 'attribute' => ['attr' => 'attrName'], 'fn' => ['function' => 'md5', 'args' => ['hashMe']]];
     $data = ['attr' => ['attrName' => 'attrValue']];
     self::assertEquals(['str' => 'aaa', 'attribute' => $data['attr']['attrName'], 'fn' => md5($functions['fn']['args'][0])], UserFunction::build($functions, $data));
 }