示例#1
0
 /**
  * @param Request $request
  *
  * @throws UnexpectedResponseException
  *
  * @return Response
  */
 public function sendRequest(Request $request)
 {
     if ('' === $request->getBaseUrl()) {
         $request = $request->withBaseUrl($this->baseUrl);
     }
     $headers = ['Accept-Language: ' . $this->acceptLanguage, 'Accept: application/vnd.trivago.affiliate.hal+json;version=1', 'X-Trv-Api-Key: ' . $this->apiKey];
     if ($this->trackingIdHandler->get() !== '') {
         $headers[] = 'Cookie: tid=' . $this->trackingIdHandler->get();
     }
     $httpRequest = new HttpRequest($request, $request->getMethod(), $headers);
     $response = $this->httpHandler->sendRequest($httpRequest);
     $headers = $response->getHeaders();
     if (!isset($headers['content-type']) || !preg_match('/json$/', $headers['content-type'])) {
         throw new UnexpectedResponseException('The response is not a valid JSON response.');
     }
     $this->trackingIdHandler->store($response->getTrivagoTrackingId());
     return $response;
 }
示例#2
0
 private function createTas()
 {
     return new Tas(new Config([Config::API_KEY => '1234', Config::GET_TRACKING_ID_CALLBACK => function () {
     }, Config::STORE_TRACKING_ID_CALLBACK => function () {
     }, Config::HTTP_HANDLER => $this->httpHandler->reveal()]));
 }