Пример #1
0
 /**
  * @return array
  */
 public function getBody()
 {
     $body = $this->request->getBody();
     if ($this->fields !== null) {
         $fields = $this->fields->getFields();
         if (is_array($fields)) {
             $fields = implode(' ', $fields);
         }
         $body[FieldsInterface::NAME] = $fields;
     }
     return $body;
 }
Пример #2
0
 /**
  * @param GuzzleClient $client
  * @param RequestInterface $request
  * @return ResponseInterface
  */
 public function handle(GuzzleClient $client, RequestInterface $request)
 {
     try {
         $response = $client->send(new HttpRequest($request->getMethod(), $request->getUri(), $request->getHeaders(), $this->jsonEncoder->encode($request->getBody())));
     } catch (\Exception $e) {
         $this->logger->debug(sprintf('Exception thrown during Guzzle request'), ['message' => $e->getMessage(), 'line' => $e->getLine(), 'file' => $e->getFile(), 'trace' => $e->getTraceAsString()]);
         $response = new Response(500);
         if ($e instanceof ClientException) {
             $response = new Response(401);
         }
     }
     return $request->getResponseFactory()->create($response);
 }
Пример #3
0
 /**
  * @inheritDoc
  */
 public function getResponseFactory()
 {
     return $this->request->getResponseFactory();
 }
Пример #4
0
 /**
  * @param RequestInterface $request
  * @return ResponseInterface
  */
 public function send(RequestInterface $request)
 {
     $request->addHeader('x-api-key', $this->credentialsProvider->getKey());
     $request->addHeader('content-type', 'application/json');
     return $this->requesthandler->handle($this->client, $request);
 }