Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Notifier] add Mailjet SMS bridge#41705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:5.4fromjnadaud:mailjet_notifier
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,6 +124,7 @@
use Symfony\Component\Notifier\Bridge\Iqsms\IqsmsTransportFactory;
use Symfony\Component\Notifier\Bridge\LightSms\LightSmsTransportFactory;
use Symfony\Component\Notifier\Bridge\LinkedIn\LinkedInTransportFactory;
use Symfony\Component\Notifier\Bridge\Mailjet\MailjetTransportFactory as MailjetNotifierTransportFactory;
use Symfony\Component\Notifier\Bridge\Mattermost\MattermostTransportFactory;
use Symfony\Component\Notifier\Bridge\Mercure\MercureTransportFactory;
use Symfony\Component\Notifier\Bridge\MessageBird\MessageBirdTransport;
Expand DownExpand Up@@ -2429,6 +2430,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
IqsmsTransportFactory::class => 'notifier.transport_factory.iqsms',
LightSmsTransportFactory::class => 'notifier.transport_factory.lightsms',
LinkedInTransportFactory::class => 'notifier.transport_factory.linkedin',
MailjetNotifierTransportFactory::class => 'notifier.transport_factory.mailjet',
MattermostTransportFactory::class => 'notifier.transport_factory.mattermost',
MercureTransportFactory::class => 'notifier.transport_factory.mercure',
MessageBirdTransport::class => 'notifier.transport_factory.messagebird',
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,6 +26,7 @@
use Symfony\Component\Notifier\Bridge\Iqsms\IqsmsTransportFactory;
use Symfony\Component\Notifier\Bridge\LightSms\LightSmsTransportFactory;
use Symfony\Component\Notifier\Bridge\LinkedIn\LinkedInTransportFactory;
use Symfony\Component\Notifier\Bridge\Mailjet\MailjetTransportFactory;
use Symfony\Component\Notifier\Bridge\Mattermost\MattermostTransportFactory;
use Symfony\Component\Notifier\Bridge\Mercure\MercureTransportFactory;
use Symfony\Component\Notifier\Bridge\MessageBird\MessageBirdTransportFactory;
Expand DownExpand Up@@ -199,5 +200,9 @@
->set('notifier.transport_factory.telnyx', TelnyxTransportFactory::class)
->parent('notifier.transport_factory.abstract')
->tag('texter.transport_factory')

->set('notifier.transport_factory.mailjet', MailjetTransportFactory::class)
->parent('notifier.transport_factory.abstract')
->tag('texter.transport_factory')
;
};
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
/Testsexport-ignore
/phpunit.xml.distexport-ignore
/.gitattributesexport-ignore
/.gitignoreexport-ignore
3 changes: 3 additions & 0 deletionssrc/Symfony/Component/Notifier/Bridge/Mailjet/.gitignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
vendor/
composer.lock
phpunit.xml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
CHANGELOG
=========

5.4
---

* Add the bridge
19 changes: 19 additions & 0 deletionssrc/Symfony/Component/Notifier/Bridge/Mailjet/LICENSE
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
Copyright (c) 2021 Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Mailjet;

use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Transport\AbstractTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
* @author Jérôme Nadaud <jerome@nadaud.io>
*/
final class MailjetTransport extends AbstractTransport
{
protected const HOST = 'api.mailjet.com';

private $authToken;
private $from;

public function __construct(string $authToken, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
{
$this->authToken = $authToken;
$this->from = $from;

parent::__construct($client, $dispatcher);
}

public function __toString(): string
{
return sprintf('mailjet://%s@%s', $this->from, $this->getEndpoint());
}

public function supports(MessageInterface $message): bool
{
return $message instanceof SmsMessage;
}

protected function doSend(MessageInterface $message): SentMessage
{
if (!$message instanceof SmsMessage) {
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
}

$endpoint = sprintf('https://%s/v4/sms-send', $this->getEndpoint());

$response = $this->client->request('POST', $endpoint, [
'auth_bearer' => $this->authToken,
'json' => [
'From' => $this->from,
'To' => $message->getPhone(),
'Text' => $message->getSubject(),
],
]);

if (200 !== $response->getStatusCode()) {
$content = $response->toArray(false);
$errorMessage = $content['requestError']['serviceException']['messageId'] ?? '';
$errorInfo = $content['requestError']['serviceException']['text'] ?? '';

throw new TransportException(sprintf('Unable to send the SMS: '.$errorMessage.' (%s).', $errorInfo), $response);
}

return new SentMessage($message, (string) $this);
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Mailjet;

use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Transport\TransportInterface;

/**
* @author Jérôme Nadaud <jerome@nadaud.io>
*/
final class MailjetTransportFactory extends AbstractTransportFactory
{
/**
* @return MailjetTransport
*/
public function create(Dsn $dsn): TransportInterface
{
$scheme = $dsn->getScheme();

if ('mailjet' !== $scheme) {
throw new UnsupportedSchemeException($dsn, 'mailjet', $this->getSupportedSchemes());
}

$authToken = $this->getPassword($dsn);
$from = $this->getUser($dsn);
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

return (new MailjetTransport($authToken, $from, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
}

protected function getSupportedSchemes(): array
{
return ['mailjet'];
}
}
23 changes: 23 additions & 0 deletionssrc/Symfony/Component/Notifier/Bridge/Mailjet/README.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
Mailjet Notifier
================

Provides [Mailjet](https://mailjet.com) SMS integration for Symfony Notifier.

DSN example
-----------

```
MAILJET_DSN=mailjet://FROM:AUTH_TOKEN@default
```

where:
- `AUTH_TOKEN` is your Mailjet SMS auth token
- `FROM` is an alphanumeric sender ID

Resources
---------

* [Contributing](https://symfony.com/doc/current/contributing/index.html)
* [Report issues](https://github.com/symfony/symfony/issues) and
[send Pull Requests](https://github.com/symfony/symfony/pulls)
in the [main Symfony repository](https://github.com/symfony/symfony)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Mailjet\Tests;

use Symfony\Component\Notifier\Bridge\Mailjet\MailjetTransportFactory;
use Symfony\Component\Notifier\Test\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;

final class MailjetTransportFactoryTest extends TransportFactoryTestCase
{
/**
* @return MailjetTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new MailjetTransportFactory();
}

public function createProvider(): iterable
{
yield [
'mailjet://Mailjet@host.test',
'mailjet://Mailjet:authtoken@host.test',
];
}

public function supportsProvider(): iterable
{
yield [true, 'mailjet://Mailjet:authtoken@default'];
yield [false, 'somethingElse://Mailjet:authtoken@default'];
}

public function missingRequiredOptionProvider(): iterable
{
yield 'missing option: from' => ['mailjet://authtoken@default'];
}

public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://default']; // missing "from" and "token" option
yield ['somethingElse://authtoken@default']; // missing "from" option
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Mailjet\Tests;

use Symfony\Component\Notifier\Bridge\Mailjet\MailjetTransport;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Test\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

final class MailjetTransportTest extends TransportTestCase
{
/**
* @return MailjetTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
return (new MailjetTransport('authtoken', 'Mailjet', $client ?? $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}

public function toStringProvider(): iterable
{
yield ['mailjet://Mailjet:authtoken@host.test', $this->createTransport()];
}

public function supportedMessagesProvider(): iterable
{
yield [new SmsMessage('0611223344', 'Hello!')];
}

public function unsupportedMessagesProvider(): iterable
{
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
}
34 changes: 34 additions & 0 deletionssrc/Symfony/Component/Notifier/Bridge/Mailjet/composer.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
{
"name": "symfony/mailjet-notifier",
"type": "symfony-bridge",
"description": "Symfony Mailjet Notifier Bridge",
"keywords": ["sms", "mailjet", "notifier"],
"homepage": "https://symfony.com",
"license": "MIT",
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Jérôme Nadaud",
"email": "jerome@nadaud.io"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Mailjet\\": "" },
"exclude-from-classmap": [
"/Tests/"
]
},
"minimum-stability": "dev"
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
>
<php>
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
<testsuite name="Symfony Mailjet Notifier Bridge Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
Loading

[8]ページ先頭

©2009-2025 Movatter.jp