Skip to content

Commit 52f28b2

Browse files
committed
Added ability to specify x-request-id header
1 parent 16841cd commit 52f28b2

13 files changed

Lines changed: 198 additions & 139 deletions

src/Client/License.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ public function getContentInfo(LicenseRequest $request, string $access_token, Ht
103103
$end_point = $this->_config->getEndPoints()['license_info'];
104104
$request_url = $end_point . '?' . http_build_query($request);
105105
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
106+
if (!empty($request->getRequestId())) {
107+
$headers['headers']['x-request-id'] = $request->getRequestId();
108+
}
106109
$raw_response = $http_client->doGet($request_url, $headers);
107110
$license_response = new LicenseResponse(json_decode($raw_response, true));
108111
return $license_response;
@@ -126,7 +129,10 @@ public function getContentLicense(LicenseRequest $request, string $access_token,
126129
$end_point = $this->_config->getEndPoints()['license'];
127130
$request_url = $end_point . '?' . http_build_query($request);
128131
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
129-
132+
if (!empty($request->getRequestId())) {
133+
$headers['headers']['x-request-id'] = $request->getRequestId();
134+
}
135+
130136
if ($request->getLicenseReference() != null) {
131137
$raw_response = $http_client->doPost($request_url, $headers, $request->getLicenseReference());
132138
} else {
@@ -156,6 +162,9 @@ public function getMemberProfile(LicenseRequest $request, string $access_token,
156162
$end_point = $this->_config->getEndPoints()['user_profile'];
157163
$request_url = $end_point . '?' . http_build_query($request);
158164
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
165+
if (!empty($request->getRequestId())) {
166+
$headers['headers']['x-request-id'] = $request->getRequestId();
167+
}
159168
$raw_response = $http_client->doGet($request_url, $headers);
160169
$license_response = new LicenseResponse(json_decode($raw_response, true));
161170
return $license_response;
@@ -176,6 +185,9 @@ public function abandonLicense(LicenseRequest $request, string $access_token, Ht
176185
$end_point = $this->_config->getEndPoints()['abandon'];
177186
$request_url = $end_point . '?' . http_build_query($request);
178187
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
188+
if (!empty($request->getRequestId())) {
189+
$headers['headers']['x-request-id'] = $request->getRequestId();
190+
}
179191
$response = $http_client->doGet($request_url, $headers);
180192
$code = (int) $response->getContents();
181193

@@ -240,6 +252,9 @@ public function downloadAssetRequest(LicenseRequest $request, string $access_tok
240252

241253
$url = $purchase_details->getUrl();
242254
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
255+
if (!empty($request->getRequestId())) {
256+
$headers['headers']['x-request-id'] = $request->getRequestId();
257+
}
243258
$headers['allow_redirects'] = false;
244259
$client_handler = $http_client->getHandlerStack();
245260
//adds middleware in the client which controls the redirection behaviour.

src/Client/LicenseHistory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ private function _doOnError()
140140
private function _getFiles(LicenseHistoryRequest $license_file_request, string $access_token = null) : LicenseHistoryResponse
141141
{
142142
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
143+
if (!empty($license_file_request->getRequestId())) {
144+
$headers['headers']['x-request-id'] = $license_file_request->getRequestId();
145+
}
143146
$end_point = $this->_config->getEndPoints()['license_history'];
144147
$request_url = $end_point . '?' . http_build_query($license_file_request);
145148
$offset_value = $this->_offset;

src/Client/SearchCategory.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public function getCategory(SearchCategoryRequest $request, string $access_token
5252
$end_point = $this->_config->getEndPoints()['category'];
5353
$request_url = $end_point . '?' . http_build_query($request);
5454
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
55+
if (!empty($request->getRequestId())) {
56+
$headers['headers']['x-request-id'] = $request->getRequestId();
57+
}
5558
$raw_response = $http_client->doGet($request_url, $headers);
5659
$search_category_response = new SearchCategoryResponse(json_decode($raw_response, true));
5760
return $search_category_response;
@@ -75,6 +78,9 @@ public function getCategoryTree(SearchCategoryRequest $request, string $access_t
7578
$end_point = $this->_config->getEndPoints()['category_tree'];
7679
$request_url = $end_point . '?' . http_build_query($request);
7780
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
81+
if (!empty($request->getRequestId())) {
82+
$headers['headers']['x-request-id'] = $request->getRequestId();
83+
}
7884
$raw_response = $http_client->doGet($request_url, $headers);
7985
return $this->_createSearchCategoryResponseArray(json_decode($raw_response, true));
8086
}

src/Client/SearchFiles.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class SearchFiles
8282

8383
/**
8484
* Custom http client object
85-
* @var HttpInterface
85+
* @var HttpClientInterface
8686
*/
8787
private $_http_client;
8888

@@ -134,6 +134,9 @@ public function getFiles(SearchFilesRequest $search_file_request, string $access
134134
{
135135
$this->_http_method = $this->_getHttpMethod($search_file_request);
136136
$headers = APIUtils::generateCommonAPIHeaders($this->_config, null);
137+
if (!empty($search_file_request->getRequestId())) {
138+
$headers['headers']['x-request-id'] = $search_file_request->getRequestId();
139+
}
137140
$end_point = $this->_config->getEndPoints()['search'];
138141
$request_url = $end_point . '?' . http_build_query($search_file_request);
139142

@@ -180,7 +183,7 @@ private function _doOnSuccess(SearchFilesResponse $response)
180183
{
181184
$this->_current_response = $response;
182185
$this->_api_in_progress = false;
183-
186+
184187
if ($this->_initial_invalid_state) {
185188
$this->_initial_invalid_state = false;
186189
}

src/Request/AbstractRequest.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright 2017 Adobe Systems Incorporated. All rights reserved.
4+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License. You may obtain a copy
6+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
*/
8+
9+
namespace AdobeStock\Api\Request;
10+
11+
use AdobeStock\Api\Exception\StockApi as StockApiException;
12+
13+
/**
14+
* Class AbstractRequest
15+
*/
16+
class AbstractRequest
17+
{
18+
/**
19+
* Language location code
20+
*
21+
* @var string
22+
*/
23+
public $locale;
24+
25+
/**
26+
* x-request-id header
27+
*
28+
* @var string
29+
*/
30+
private $requestId;
31+
32+
/**
33+
* Getter for Locale.
34+
*
35+
* @return string Language location code.
36+
*/
37+
public function getLocale(): ?string
38+
{
39+
return $this->locale;
40+
}
41+
42+
/**
43+
* Setter for Locale.
44+
*
45+
* @param string $locale Language location code.
46+
* @return AbstractRequest
47+
* @throws StockApiException if locale is empty.
48+
*/
49+
public function setLocale(string $locale) : AbstractRequest
50+
{
51+
if (!empty($locale)) {
52+
$this->locale = $locale;
53+
} else {
54+
throw StockApiException::withMessage('Locale cannot be empty string');
55+
}
56+
57+
return $this;
58+
}
59+
60+
/**
61+
* Set x-request-id header
62+
*
63+
* @param string $requestId
64+
* @return AbstractRequest
65+
*/
66+
public function setRequestId(string $requestId): AbstractRequest
67+
{
68+
$this->requestId = $requestId;
69+
return $this;
70+
}
71+
72+
/**
73+
* Get x-request-id header
74+
*
75+
* @return string|null
76+
*/
77+
public function getRequestId(): ?string
78+
{
79+
return $this->requestId;
80+
}
81+
}

src/Request/License.php

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@
1313
use \AdobeStock\Api\Models\LicenseReference;
1414
use \AdobeStock\Api\Core\Constants as CoreConstants;
1515

16-
class License
16+
class License extends AbstractRequest
1717
{
18-
/**
19-
* Language location code
20-
* @var string
21-
*/
22-
public $locale;
23-
2418
/**
2519
* Asset's unique identifer
2620
* @var int
@@ -53,32 +47,6 @@ class License
5347
*/
5448
public $license_reference;
5549

56-
/**
57-
* Getter for Locale.
58-
* @return string Language location code.
59-
*/
60-
public function getLocale(): string
61-
{
62-
return $this->locale;
63-
}
64-
65-
/**
66-
* Setter for Locale.
67-
* @param string $locale Language location code.
68-
* @return License
69-
* @throws StockApiException if locale is empty.
70-
*/
71-
public function setLocale(string $locale): License
72-
{
73-
if (!empty($locale)) {
74-
$this->locale = $locale;
75-
} else {
76-
throw StockApiException::withMessage('Locale cannot be empty string');
77-
}
78-
79-
return $this;
80-
}
81-
8250
/**
8351
* Getter for ContentId.
8452
* @return int|null Asset identifier for an existing asset.

src/Request/LicenseHistory.php

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@
1111
use \AdobeStock\Api\Exception\StockApi as StockApiException;
1212
use \AdobeStock\Api\Models\SearchParamLicenseHistory as SearchParamLicenseHistoryModel;
1313

14-
class LicenseHistory
14+
class LicenseHistory extends AbstractRequest
1515
{
16-
/**
17-
* @var string Language location code
18-
*/
19-
public $locale;
20-
2116
/**
2217
* @var SearchParamLicenseHistoryModel search params.
2318
*/
@@ -27,32 +22,7 @@ class LicenseHistory
2722
* @var array result column constants
2823
*/
2924
public $result_columns;
30-
31-
/**
32-
* Getter for Locale.
33-
* @return string|null Language location code.
34-
*/
35-
public function getLocale() : ?string
36-
{
37-
return $this->locale;
38-
}
39-
40-
/**
41-
* Setter for Locale.
42-
* @param string $locale Language location code.
43-
* @throws StockApiException if locale is null
44-
* @return LicenseHistory
45-
*/
46-
public function setLocale(string $locale = null) : LicenseHistory
47-
{
48-
if ($locale === null) {
49-
throw StockApiException::withMessage('Locale cannot be null');
50-
}
51-
52-
$this->locale = $locale;
53-
return $this;
54-
}
55-
25+
5626
/**
5727
* Get SearchParameters array that consists of various search params
5828
* @return SearchParamLicenseHistoryModel|null

src/Request/SearchCategory.php

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,14 @@
1010

1111
use \AdobeStock\Api\Exception\StockApi as StockApiException;
1212

13-
class SearchCategory
13+
class SearchCategory extends AbstractRequest
1414
{
15-
/**
16-
* Language location code
17-
* @var string
18-
*/
19-
public $locale;
20-
2115
/**
2216
* Unique identifier for an existing category.
2317
* @var integer
2418
*/
2519
public $category_id;
2620

27-
/**
28-
* Getter for Locale.
29-
* @return string Language location code.
30-
*/
31-
public function getLocale()
32-
{
33-
return $this->locale;
34-
}
35-
36-
/**
37-
* Setter for Locale.
38-
* @param string $locale Language location code.
39-
* @return SearchCategory
40-
* @throws StockApiException if locale is empty.
41-
*/
42-
public function setLocale(string $locale) : SearchCategory
43-
{
44-
if (!empty($locale)) {
45-
$this->locale = $locale;
46-
} else {
47-
throw StockApiException::withMessage('Locale cannot be empty string');
48-
}
49-
50-
return $this;
51-
}
52-
5321
/**
5422
* Getter for CategoryId.
5523
* @return int|null Unique identifier for an existing category.

src/Request/SearchFiles.php

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@
1212
use \AdobeStock\Api\Core\Constants as Constants;
1313
use \AdobeStock\Api\Models\SearchParameters as SearchParametersModel;
1414

15-
class SearchFiles
15+
class SearchFiles extends AbstractRequest
1616
{
17-
/**
18-
* @var string Language location code
19-
*/
20-
public $locale;
21-
2217
/**
2318
* @var SearchParametersModel search params.
2419
*/
@@ -33,31 +28,7 @@ class SearchFiles
3328
* @var string Similar Image Path
3429
*/
3530
public $similar_image;
36-
37-
/**
38-
* Getter for Locale.
39-
* @return string|null Language location code.
40-
*/
41-
public function getLocale() : ?string
42-
{
43-
return $this->locale;
44-
}
45-
46-
/**
47-
* Setter for Locale.
48-
* @param string $locale Language location code.
49-
* @return SearchFiles
50-
*/
51-
public function setLocale(string $locale = null) : SearchFiles
52-
{
53-
if ($locale == null) {
54-
throw StockApiException::withMessage('Locale cannot be null');
55-
}
56-
57-
$this->locale = $locale;
58-
return $this;
59-
}
60-
31+
6132
/**
6233
* Get SearchParameters array that consists of various search params
6334
* @return SearchParametersModel|null

0 commit comments

Comments
 (0)