Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Client/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public function getContentInfo(LicenseRequest $request, string $access_token, Ht
$end_point = $this->_config->getEndPoints()['license_info'];
$request_url = $end_point . '?' . http_build_query($request);
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
if (!empty($request->getRequestId())) {
$headers['headers']['x-request-id'] = $request->getRequestId();
}
$raw_response = $http_client->doGet($request_url, $headers);
$license_response = new LicenseResponse(json_decode($raw_response, true));
return $license_response;
Expand All @@ -127,7 +130,10 @@ public function getContentLicense(LicenseRequest $request, string $access_token,
$end_point = $this->_config->getEndPoints()['license'];
$request_url = $end_point . '?' . http_build_query($request);
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);

if (!empty($request->getRequestId())) {
$headers['headers']['x-request-id'] = $request->getRequestId();
}

if ($request->getLicenseReference() != null) {
$raw_response = $http_client->doPost($request_url, $headers, $request->getLicenseReference());
} else {
Expand Down Expand Up @@ -157,6 +163,9 @@ public function getMemberProfile(LicenseRequest $request, string $access_token,
$end_point = $this->_config->getEndPoints()['user_profile'];
$request_url = $end_point . '?' . http_build_query($request);
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
if (!empty($request->getRequestId())) {
$headers['headers']['x-request-id'] = $request->getRequestId();
}
$raw_response = $http_client->doGet($request_url, $headers);
$license_response = new LicenseResponse(json_decode($raw_response, true));
return $license_response;
Expand All @@ -177,6 +186,9 @@ public function abandonLicense(LicenseRequest $request, string $access_token, Ht
$end_point = $this->_config->getEndPoints()['abandon'];
$request_url = $end_point . '?' . http_build_query($request);
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
if (!empty($request->getRequestId())) {
$headers['headers']['x-request-id'] = $request->getRequestId();
}
$response = $http_client->doGet($request_url, $headers);
$code = (int) $response->getContents();

Expand Down Expand Up @@ -241,6 +253,9 @@ public function downloadAssetRequest(LicenseRequest $request, string $access_tok

$url = $purchase_details->getUrl();
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
if (!empty($request->getRequestId())) {
$headers['headers']['x-request-id'] = $request->getRequestId();
}
$headers['allow_redirects'] = false;
$client_handler = $http_client->getHandlerStack();
//adds middleware in the client which controls the redirection behaviour.
Expand Down
3 changes: 3 additions & 0 deletions src/Client/LicenseHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ private function _doOnError()
private function _getFiles(LicenseHistoryRequest $license_file_request, string $access_token = null) : LicenseHistoryResponse
{
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
if (!empty($license_file_request->getRequestId())) {
$headers['headers']['x-request-id'] = $license_file_request->getRequestId();
}
$end_point = $this->_config->getEndPoints()['license_history'];
$request_url = $end_point . '?' . http_build_query($license_file_request);
$offset_value = $this->_offset;
Expand Down
6 changes: 6 additions & 0 deletions src/Client/SearchCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public function getCategory(SearchCategoryRequest $request, string $access_token
$end_point = $this->_config->getEndPoints()['category'];
$request_url = $end_point . '?' . http_build_query($request);
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
if (!empty($request->getRequestId())) {
$headers['headers']['x-request-id'] = $request->getRequestId();
}
$raw_response = $http_client->doGet($request_url, $headers);
$search_category_response = new SearchCategoryResponse(json_decode($raw_response, true));
return $search_category_response;
Expand All @@ -75,6 +78,9 @@ public function getCategoryTree(SearchCategoryRequest $request, string $access_t
$end_point = $this->_config->getEndPoints()['category_tree'];
$request_url = $end_point . '?' . http_build_query($request);
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
if (!empty($request->getRequestId())) {
$headers['headers']['x-request-id'] = $request->getRequestId();
}
$raw_response = $http_client->doGet($request_url, $headers);
return $this->_createSearchCategoryResponseArray(json_decode($raw_response, true));
}
Expand Down
7 changes: 5 additions & 2 deletions src/Client/SearchFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SearchFiles

/**
* Custom http client object
* @var HttpInterface
* @var HttpClientInterface
*/
private $_http_client;

Expand Down Expand Up @@ -134,6 +134,9 @@ public function getFiles(SearchFilesRequest $search_file_request, string $access
{
$this->_http_method = $this->_getHttpMethod($search_file_request);
$headers = APIUtils::generateCommonAPIHeaders($this->_config, $access_token);
if (!empty($search_file_request->getRequestId())) {
$headers['headers']['x-request-id'] = $search_file_request->getRequestId();
}
$end_point = $this->_config->getEndPoints()['search'];
$request_url = $end_point . '?' . http_build_query($search_file_request);

Expand Down Expand Up @@ -180,7 +183,7 @@ private function _doOnSuccess(SearchFilesResponse $response)
{
$this->_current_response = $response;
$this->_api_in_progress = false;

if ($this->_initial_invalid_state) {
$this->_initial_invalid_state = false;
}
Expand Down
81 changes: 81 additions & 0 deletions src/Request/AbstractRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* Copyright 2017 Adobe Systems Incorporated. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

namespace AdobeStock\Api\Request;

use AdobeStock\Api\Exception\StockApi as StockApiException;

/**
* Class AbstractRequest
*/
class AbstractRequest
{
/**
* Language location code
*
* @var string
*/
public $locale;

/**
* x-request-id header
*
* @var string
*/
private $requestId;

/**
* Getter for Locale.
*
* @return string Language location code.
*/
public function getLocale(): ?string
{
return $this->locale;
}

/**
* Setter for Locale.
*
* @param string $locale Language location code.
* @return AbstractRequest
* @throws StockApiException if locale is empty.
*/
public function setLocale(string $locale) : AbstractRequest
{
if (!empty($locale)) {
$this->locale = $locale;
} else {
throw StockApiException::withMessage('Locale cannot be empty string');
}

return $this;
}

/**
* Set x-request-id header
*
* @param string $requestId
* @return AbstractRequest
*/
public function setRequestId(string $requestId): AbstractRequest
{
$this->requestId = $requestId;
return $this;
}

/**
* Get x-request-id header
*
* @return string|null
*/
public function getRequestId(): ?string
{
return $this->requestId;
}
}
34 changes: 1 addition & 33 deletions src/Request/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@
use \AdobeStock\Api\Models\LicenseReference;
use \AdobeStock\Api\Core\Constants as CoreConstants;

class License
class License extends AbstractRequest
{
/**
* Language location code
* @var string
*/
public $locale;

/**
* Asset's unique identifer
* @var int
Expand Down Expand Up @@ -53,32 +47,6 @@ class License
*/
public $license_reference;

/**
* Getter for Locale.
* @return string Language location code.
*/
public function getLocale(): string
{
return $this->locale;
}

/**
* Setter for Locale.
* @param string $locale Language location code.
* @return License
* @throws StockApiException if locale is empty.
*/
public function setLocale(string $locale): License
{
if (!empty($locale)) {
$this->locale = $locale;
} else {
throw StockApiException::withMessage('Locale cannot be empty string');
}

return $this;
}

/**
* Getter for ContentId.
* @return int|null Asset identifier for an existing asset.
Expand Down
34 changes: 2 additions & 32 deletions src/Request/LicenseHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@
use \AdobeStock\Api\Exception\StockApi as StockApiException;
use \AdobeStock\Api\Models\SearchParamLicenseHistory as SearchParamLicenseHistoryModel;

class LicenseHistory
class LicenseHistory extends AbstractRequest
{
/**
* @var string Language location code
*/
public $locale;

/**
* @var SearchParamLicenseHistoryModel search params.
*/
Expand All @@ -27,32 +22,7 @@ class LicenseHistory
* @var array result column constants
*/
public $result_columns;

/**
* Getter for Locale.
* @return string|null Language location code.
*/
public function getLocale() : ?string
{
return $this->locale;
}

/**
* Setter for Locale.
* @param string $locale Language location code.
* @throws StockApiException if locale is null
* @return LicenseHistory
*/
public function setLocale(string $locale = null) : LicenseHistory
{
if ($locale === null) {
throw StockApiException::withMessage('Locale cannot be null');
}

$this->locale = $locale;
return $this;
}


/**
* Get SearchParameters array that consists of various search params
* @return SearchParamLicenseHistoryModel|null
Expand Down
34 changes: 1 addition & 33 deletions src/Request/SearchCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,14 @@

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

class SearchCategory
class SearchCategory extends AbstractRequest
{
/**
* Language location code
* @var string
*/
public $locale;

/**
* Unique identifier for an existing category.
* @var integer
*/
public $category_id;

/**
* Getter for Locale.
* @return string Language location code.
*/
public function getLocale()
{
return $this->locale;
}

/**
* Setter for Locale.
* @param string $locale Language location code.
* @return SearchCategory
* @throws StockApiException if locale is empty.
*/
public function setLocale(string $locale) : SearchCategory
{
if (!empty($locale)) {
$this->locale = $locale;
} else {
throw StockApiException::withMessage('Locale cannot be empty string');
}

return $this;
}

/**
* Getter for CategoryId.
* @return int|null Unique identifier for an existing category.
Expand Down
33 changes: 2 additions & 31 deletions src/Request/SearchFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@
use \AdobeStock\Api\Core\Constants as Constants;
use \AdobeStock\Api\Models\SearchParameters as SearchParametersModel;

class SearchFiles
class SearchFiles extends AbstractRequest
{
/**
* @var string Language location code
*/
public $locale;

/**
* @var SearchParametersModel search params.
*/
Expand All @@ -33,31 +28,7 @@ class SearchFiles
* @var string Similar Image Path
*/
public $similar_image;

/**
* Getter for Locale.
* @return string|null Language location code.
*/
public function getLocale() : ?string
{
return $this->locale;
}

/**
* Setter for Locale.
* @param string $locale Language location code.
* @return SearchFiles
*/
public function setLocale(string $locale = null) : SearchFiles
{
if ($locale == null) {
throw StockApiException::withMessage('Locale cannot be null');
}

$this->locale = $locale;
return $this;
}


/**
* Get SearchParameters array that consists of various search params
* @return SearchParametersModel|null
Expand Down
Loading