From e15e744996a31e1d5024d021c11a81b2cdbfb06a Mon Sep 17 00:00:00 2001 From: dpdplugin Date: Tue, 28 May 2019 16:37:07 +0200 Subject: [PATCH] Added metadata info --- src/ClientBuilder.php | 11 +++++++++-- src/Common/HttpClient.php | 29 ++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/ClientBuilder.php b/src/ClientBuilder.php index 312358f..0954e1e 100644 --- a/src/ClientBuilder.php +++ b/src/ClientBuilder.php @@ -20,14 +20,21 @@ class ClientBuilder implements ClientBuilderInterface */ protected $httpClient; + /** + * @var array meta + */ + private $meta; + /** * @param string $endpoint */ - public function __construct($endpoint = null) + public function __construct($endpoint = null, $meta = null) { if (!is_null($endpoint)) { $this->endpoint = $endpoint; } + + $this->meta = $meta; } /** @@ -44,7 +51,7 @@ public function getEndpoint() private function getHttpClient() { if (null === $this->httpClient) { - $this->httpClient = new HttpClient($this->endpoint); + $this->httpClient = new HttpClient($this->endpoint, $this->meta); } return $this->httpClient; diff --git a/src/Common/HttpClient.php b/src/Common/HttpClient.php index 5ce1b40..7918abe 100644 --- a/src/Common/HttpClient.php +++ b/src/Common/HttpClient.php @@ -2,6 +2,7 @@ namespace DpdConnect\Sdk\Common; +use DpdConnect\Sdk\Client; use DpdConnect\Sdk\Common; use DpdConnect\Sdk\Exceptions; use DpdConnect\Sdk\Exceptions\HttpException; @@ -164,16 +165,19 @@ public function sendRequest($method, $resourceName, $query = null, $headers = [] // throw new Exceptions\AuthenticateException('Can not perform API Request without Authentication'); // } + list($webshopType, $webshopVersion, $pluginVersion) = $this->parseMeta(); + $baseHeaders = [ 'User-agent: ' . implode(' ', $this->userAgent), 'Accept: application/json', 'Content-Type: application/json', 'Accept-Charset: utf-8', - 'x-webshop-type: none', - 'x-webshop-version: none', - 'x-plugin-version: 1.0.0', - 'x-php-version: 1.0.0', - 'x-os: none' + 'x-php-version: ' . $this->getPhpVersion(), + 'x-webshop-type: ' . $webshopType, + 'x-webshop-version: ' . $webshopVersion, + 'x-plugin-version: ' . $pluginVersion, + 'x-sdk-version: ' . Client::CLIENT_VERSION, + 'x-os: ' . php_uname(), ]; $baseHeaders = array_merge($baseHeaders, $headers, $this->headers); @@ -237,4 +241,19 @@ private function getPhpVersion() return 'PHP/' . PHP_VERSION_ID; } + + private function parseMeta() + { + if (!$this->meta) { + $this->meta = []; + } + + $meta = $this->meta; + + $webshopType = isset($meta['webshopType']) ? $meta['webshopType'] : 'unknown'; + $webshopVersion = isset($meta['webshopVersion']) ? $meta['webshopVersion'] : 'unknown'; + $pluginVersion = isset($meta['pluginVersion']) ? $meta['pluginVersion'] : 'unknown'; + + return [$webshopType, $webshopVersion, $pluginVersion]; + } }