Skip to content

Commit 4516db5

Browse files
committed
Refactoring base url #38
1 parent a35e1a2 commit 4516db5

8 files changed

Lines changed: 35 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ $client = new \BushlanovDev\MaxMessengerBot\Client(
8585
httpClient: $guzzle,
8686
requestFactory: $httpFactory,
8787
streamFactory: $httpFactory,
88-
baseUrl: 'https://platform-api2.max.ru',
88+
baseUrl: BushlanovDev\MaxMessengerBot\Api::API_BASE_URL,
8989
);
9090

9191
$api = new BushlanovDev\MaxMessengerBot\Api(

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ $client = new \BushlanovDev\MaxMessengerBot\Client(
9999
httpClient: $guzzle,
100100
requestFactory: $httpFactory,
101101
streamFactory: $httpFactory,
102-
baseUrl: 'https://platform-api2.max.ru',
102+
baseUrl: BushlanovDev\MaxMessengerBot\Api::API_BASE_URL,
103103
);
104104

105105
$api = new BushlanovDev\MaxMessengerBot\Api(

src/Api.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@
4848
*/
4949
class Api
5050
{
51-
public const string LIBRARY_VERSION = '1.6.5';
51+
public const string API_BASE_URL = 'https://platform-api2.max.ru';
5252

53-
public const string API_VERSION = '1.2.5';
53+
public const string LIBRARY_VERSION = '1.6.6';
5454

55-
private const string API_BASE_URL = 'https://platform-api2.max.ru';
55+
public const string API_VERSION = '1.2.5';
5656

5757
private const string METHOD_GET = 'GET';
5858
private const string METHOD_POST = 'POST';

src/Enums/ChatAdminPermission.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ enum ChatAdminPermission: string
1717
case Write = 'write';
1818
case CanCall = 'can_call';
1919
case EditLink = 'edit_link';
20-
case PostEditDeleteMessage = 'post_edit_delete_message';
21-
case EditMessage = 'edit_message';
20+
case PostEditDeleteMessage = 'post_edit_delete_message'; // @deprecated use write
21+
case EditMessage = 'edit_message'; // @deprecated use edit
2222
case DeleteMessage = 'delete_message';
2323
case Delete = 'delete';
2424
case Edit = 'edit';

src/Laravel/MaxBotServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function register(): void
7676
$guzzle,
7777
$httpFactory,
7878
$httpFactory,
79-
$config->get('maxbot.base_url', 'https://platform-api2.max.ru'),
79+
empty($config->get('maxbot.base_url')) ? Api::API_BASE_URL : $config->get('maxbot.base_url'),
8080
$config->get('maxbot.api_version'),
8181
$logger,
8282
);

src/Laravel/config/maxbot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
| Configuration for the Max Bot API connection.
3737
|
3838
*/
39-
'base_url' => env('MAXBOT_BASE_URL', 'https://botapi.max.ru'),
39+
'base_url' => env('MAXBOT_BASE_URL', \BushlanovDev\MaxMessengerBot\Api::API_BASE_URL),
4040
'api_version' => env('MAXBOT_API_VERSION'),
4141

4242
/*

tests/ClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
final class ClientTest extends TestCase
3838
{
3939
private const string FAKE_TOKEN = '12345:abcdef';
40-
private const string API_VERSION = '0.0.6';
41-
private const string API_BASE_URL = 'https://platform-api.max.ru';
40+
private const string API_VERSION = '1.2.5';
41+
private const string API_BASE_URL = 'https://platform-api2.max.ru';
4242

4343
private MockObject&ClientInterface $httpClientMock;
4444
private MockObject&RequestFactoryInterface $requestFactoryMock;

tests/Laravel/MaxBotServiceProviderTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,30 @@ public function clientIsConfiguredCorrectlyFromConfig(): void
182182
$this->assertSame('test-version', $apiVersionProp->getValue($client));
183183
}
184184

185+
/**
186+
* @return array<string, array{0: mixed}>
187+
*/
188+
public static function falsyBaseUrlProvider(): array
189+
{
190+
return [
191+
'null (MAXBOT_BASE_URL unset)' => [null],
192+
'empty string' => [''],
193+
];
194+
}
195+
196+
#[Test]
197+
#[DataProvider('falsyBaseUrlProvider')]
198+
public function clientFallsBackToApiBaseUrlConstantWhenBaseUrlIsFalsy(mixed $falsyBaseUrl): void
199+
{
200+
$this->app['config']->set('maxbot.base_url', $falsyBaseUrl);
201+
202+
/** @var Client $client */
203+
$client = $this->app->make(ClientApiInterface::class);
204+
205+
$baseUrlProp = (new ReflectionClass($client))->getProperty('baseUrl');
206+
$this->assertSame(Api::API_BASE_URL, $baseUrlProp->getValue($client));
207+
}
208+
185209
#[Test]
186210
public function clientIsConfiguredWithApplicationLoggerWhenLoggingIsEnabled(): void
187211
{

0 commit comments

Comments
 (0)