8000 [Notifier] smsapi-notifier `fast` option to sending message with the … · symfony/symfony@cd266a0 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cd266a0

Browse files
marphifabpot
authored andcommitted
[Notifier] smsapi-notifier fast option to sending message with the highest priority
1 parent 1ebb5d9 commit cd266a0

File tree

6 files changed

+42
-6
lines changed

6 files changed

+42
-6
lines changed

src/Symfony/Component/Notifier/Bridge/Smsapi/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.1
5+
---
6+
7+
* Added `fast` option to the DSN that allows sending message with the highest priority that ensures the quickest possible time of delivery
8+
49
5.2
510
---
611

src/Symfony/Component/Notifier/Bridge/Smsapi/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ DSN example
77
-----------
88

99
```
10-
SMSAPI_DSN=smsapi://TOKEN@default?from=FROM
10+
SMSAPI_DSN=smsapi://TOKEN@default?from=FROM&fast=FAST
1111
```
1212

1313
where:
1414
- `TOKEN` is your API Token (OAuth)
1515
- `FROM` is the sender name
16+
- `FAST` setting this parameter to "1" (default "0") will result in sending message with the highest priority which ensures the quickest possible time of delivery. Attention! Fast messages cost more than normal messages.
1617

1718
See your account info at https://ssl.smsapi.pl/
1819

src/Symfony/Component/Notifier/Bridge/Smsapi/SmsapiTransport.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ final class SmsapiTransport extends AbstractTransport
3131

3232
private string $authToken;
3333
private string $from;
34+
private bool $fast = false;
3435

3536
public function __construct(string $authToken, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
3637
{
@@ -40,9 +41,19 @@ public function __construct(string $authToken, string $from, HttpClientInterface
4041
parent::__construct($client, $dispatcher);
4142
}
4243

44+
/**
45+
* @return $this
46+
*/
47+
public function setFast(bool $fast): static
48+
{
49+
$this->fast = $fast;
50+
51+
return $this;
52+
}
53+
4354
public function __toString(): string
4455
{
45-
return sprintf('smsapi://%s?from=%s', $this->getEndpoint(), $this->from);
56+
return sprintf('smsapi://%s?from=%s&fast=%d', $this->getEndpoint(), $this->from, (int) $this->fast);
4657
}
4758

4859
public function supports(MessageInterface $message): bool
@@ -63,6 +74,8 @@ protected function doSend(MessageInterface $message): SentMessage
6374
'from' => $this->from,
6475
'to' => $message->getPhone(),
6576
'message' => $message->getSubject(),
77+
'fast' => $this->fast,
78+
'encoding' => 'utf-8',
6679
'format' => 'json',
6780
],
6881
]);

src/Symfony/Component/Notifier/Bridge/Smsapi/SmsapiTransportFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ public function create(Dsn $dsn): SmsapiTransport
3131
$authToken = $this->getUser($dsn);
3232
$from = $dsn->getRequiredOption('from');
3333
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
34+
$fast = filter_var($dsn->getOption('fast', false), \FILTER_VALIDATE_BOOLEAN);
3435
$port = $dsn->getPort();
3536

36-
return (new SmsapiTransport($authToken, $from, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
37+
return (new SmsapiTransport($authToken, $from, $this->client, $this->dispatcher))->setFast($fast)->setHost($host)->setPort($port);
3738
}
3839

3940
protected function getSupportedSchemes(): array

src/Symfony/Component/Notifier/Bridge/Smsapi/Tests/SmsapiTransportFactoryTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,30 @@ public function createFactory(): SmsapiTransportFactory
2424
public function createProvider(): iterable
2525
{
2626
yield [
27-
'smsapi://host.test?from=testFrom',
27+
'smsapi://host.test?from=testFrom&fast=0',
2828
'smsapi://token@host.test?from=testFrom',
2929
];
30+
31+
yield [
32+
'smsapi://host.test?from=testFrom&fast=0',
33+
'smsapi://token@host.test?from=testFrom&fast=0',
34+
];
35+
36+
yield [
37+
'smsapi://host.test?from=testFrom&fast=1',
38+
'smsapi://token@host.test?from=testFrom&fast=1',
39+
];
40+
41+
yield [
42+
'smsapi://host.test?from=testFrom&fast=1',
43+
'smsapi://token@host.test?from=testFrom&fast=true',
44+
];
3045
}
3146

3247
public function supportsProvider(): iterable
3348
{
3449
yield [true, 'smsapi://host?from=testFrom'];
50+
yield [true, 'smsapi://host?from=testFrom&fast=1'];
3551
yield [false, 'somethingElse://host?from=testFrom'];
3652
}
3753

src/Symfony/Component/Notifier/Bridge/Smsapi/Tests/SmsapiTransportTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ final class SmsapiTransportTest extends TransportTestCase
2525
{
2626
public function createTransport(HttpClientInterface $client = null): SmsapiTransport
2727
{
28-
return (new SmsapiTransport('testToken', 'testFrom', $client ?? $this->createMock(HttpClientInterface::class)))->setHost('test.host');
28+
return (new SmsapiTransport('testToken', 'testFrom', $client ?? $this->createMock(HttpClientInterface::class)))->setFast(true)->setHost('test.host');
2929
}
3030

3131
public function toStringProvider(): iterable
3232
{
33-
yield ['smsapi://test.host?from=testFrom', $this->createTransport()];
33+
yield ['smsapi://test.host?from=testFrom&fast=1', $this->createTransport()];
3434
}
3535

3636
public function supportedMessagesProvider(): iterable

0 commit comments

Comments
 (0)
0