コード例 #1
0
ファイル: Client.php プロジェクト: trivago/tas-sdk-php
 /**
  * @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
ファイル: TasTest.php プロジェクト: trivago/tas-sdk-php
 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()]));
 }