Skip to content

Commit 14f6160

Browse files
committed
Added: user agent header
1 parent 1efd756 commit 14f6160

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/Client.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
class Client {
1515
public const DEFAULT_URL = 'https://sms.capcom.me/api/3rdparty/v1';
16+
public const USER_AGENT = 'AndroidSmsGateway-Client/1.0 (php)';
1617

1718
protected string $basicAuth;
1819
protected string $baseUrl;
@@ -66,10 +67,7 @@ public function GetState(string $id): MessageState {
6667
}
6768

6869
/**
69-
* Выполняет запрос к серверу
70-
* @param string $method http-метод
71-
* @param string $path адрес
72-
* @param \AndroidSmsGateway\Interfaces\SerializableInterface|null $payload тело запроса
70+
* @param \AndroidSmsGateway\Interfaces\SerializableInterface|null $payload
7371
* @throws HttpException
7472
* @throws \RuntimeException
7573
* @return object|array<object>|null
@@ -87,7 +85,8 @@ protected function sendRequest(string $method, string $path, $payload = null) {
8785
$method,
8886
$this->baseUrl . $path
8987
)
90-
->withAddedHeader('Authorization', 'Basic ' . $this->basicAuth);
88+
->withAddedHeader('Authorization', 'Basic ' . $this->basicAuth)
89+
->withAddedHeader('User-Agent', self::USER_AGENT);
9190
if (isset($data)) {
9291
$request = $request
9392
->withAddedHeader('Content-Type', 'application/json')

tests/ClientTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ public function testServer(): void {
9090
$this->markTestSkipped();
9191
}
9292

93-
$curlClient = new CurlClient(null, null, [
94-
CURLOPT_TIMEOUT => 1,
95-
]);
93+
$curlClient = new CurlClient(
94+
null,
95+
null,
96+
[
97+
CURLOPT_TIMEOUT => 1,
98+
]
99+
);
96100
$client = new Client($login, $password, Client::DEFAULT_URL, $curlClient);
97101

98102
$message = new Message(date('Y-m-d H:i:s'), [$phoneNumber]);

0 commit comments

Comments
 (0)