Skip to content

Commit

Permalink
Merge pull request #1 from dpdconnect/feature/meta-data
Browse files Browse the repository at this point in the history
Added metadata info
  • Loading branch information
dpdplugin authored May 28, 2019
2 parents d5cd43b + e15e744 commit 1c339b7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
Expand Down
29 changes: 24 additions & 5 deletions src/Common/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
}
}

0 comments on commit 1c339b7

Please sign in to comment.