Skip to content

Commit

Permalink
Merge e39004a into 79b570e
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Nov 22, 2017
2 parents 79b570e + e39004a commit 88f52b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Http/RequestManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace Lmc\Matej\Http;

use Http\Client\Common\Plugin\AuthenticationPlugin;
use Http\Client\Common\Plugin\HeaderSetPlugin;
use Http\Client\Common\PluginClient;
use Http\Client\HttpClient;
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Message\MessageFactory;
use Lmc\Matej\Http\Plugin\ExceptionPlugin;
use Lmc\Matej\Matej;
use Lmc\Matej\Model\Request;
use Lmc\Matej\Model\Response;
use Psr\Http\Message\RequestInterface;
Expand All @@ -19,6 +21,8 @@
*/
class RequestManager
{
public const CLIENT_VERSION_HEADER = 'Matej-Client-Version';

/** @var string */
protected $accountId;
/** @var string */
Expand Down Expand Up @@ -99,6 +103,7 @@ protected function createConfiguredHttpClient(): HttpClient
return new PluginClient(
$this->getHttpClient(),
[
new HeaderSetPlugin($this->getDefaultHeaders()),
new AuthenticationPlugin(new HmacAuthentication($this->apiKey)),
new ExceptionPlugin(),
]
Expand All @@ -123,4 +128,11 @@ protected function buildBaseUrl(): string
{
return sprintf('https://%s.matej.lmc.cz', $this->accountId);
}

private function getDefaultHeaders(): array
{
return [
self::CLIENT_VERSION_HEADER => Matej::CLIENT_ID . '/' . Matej::VERSION,
];
}
}
3 changes: 3 additions & 0 deletions src/Matej.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class Matej
{
public const CLIENT_ID = 'php-client';
public const VERSION = '0.0.0';

/** @var string */
private $clientId;
/** @var string */
Expand Down
5 changes: 5 additions & 0 deletions tests/Http/RequestManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Fig\Http\Message\RequestMethodInterface;
use Http\Mock\Client;
use Lmc\Matej\Matej;
use Lmc\Matej\Model\Request;
use Lmc\Matej\Model\Response;
use Lmc\Matej\TestCase;
Expand Down Expand Up @@ -53,5 +54,9 @@ public function shouldSendAndDecodeRequest(): void
$recordedRequests[0]->getBody()->__toString()
);
$this->assertSame(['application/json'], $recordedRequests[0]->getHeader('Content-Type'));
$this->assertSame(
'php-client/' . Matej::VERSION,
$recordedRequests[0]->getHeader(RequestManager::CLIENT_VERSION_HEADER)[0]
);
}
}

0 comments on commit 88f52b7

Please sign in to comment.