diff --git a/README.md b/README.md index 479a13d..e3f0176 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # notify > [!NOTE] -> Push notification SDK(AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、Zulip). +> Push notification SDK(AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、Zulip). [![tests](https://github.com/guanguans/notify/actions/workflows/tests.yml/badge.svg)](https://github.com/guanguans/notify/actions/workflows/tests.yml) [![check & fix styling](https://github.com/guanguans/notify/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/guanguans/notify/actions/workflows/php-cs-fixer.yml) @@ -35,6 +35,7 @@ * [Pushback](./src/Pushback/README.md) * [PushBullet](./src/PushBullet/README.md) * [PushDeer](./src/PushDeer/README.md) +* [PushMe](./src/PushMe/README.md) * [Pushover](./src/Pushover/README.md) * [PushPlus](./src/PushPlus/README.md) * [QQ](./src/QQ/README.md) diff --git a/composer.json b/composer.json index 548e874..dcdd19f 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "guanguans/notify", - "description": "Push notification SDK(AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、Zulip).", + "description": "Push notification SDK(AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、Zulip).", "license": "MIT", "type": "library", "keywords": [ @@ -38,6 +38,7 @@ "Pushback", "PushBullet", "PushDeer", + "PushMe", "Pushover", "PushPlus", "QQ", diff --git a/ide.json b/ide.json index a69f242..3a084d6 100644 --- a/ide.json +++ b/ide.json @@ -995,6 +995,36 @@ ] } }, + { + "complete": "staticStrings", + "condition": [ + { + "classFqn": [ + "\\Guanguans\\Notify\\PushMe\\Messages\\Message" + ], + "newClassFqn": [ + "\\Guanguans\\Notify\\PushMe\\Messages\\Message" + ], + "methodNames": [ + "make" + ], + "parameters": [ + 1 + ], + "place": "arrayKey" + } + ], + "options": { + "strings": [ + "content", + "date", + "push_key", + "temp_key", + "title", + "type" + ] + } + }, { "complete": "staticStrings", "condition": [ diff --git a/src/PushMe/Authenticator.php b/src/PushMe/Authenticator.php new file mode 100644 index 0000000..dd99c76 --- /dev/null +++ b/src/PushMe/Authenticator.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + * + * @see https://github.com/guanguans/notify + */ + +namespace Guanguans\Notify\PushMe; + +use Guanguans\Notify\Foundation\Authenticators\OptionsAuthenticator; +use GuzzleHttp\RequestOptions; + +class Authenticator extends OptionsAuthenticator +{ + public function __construct(?string $pushKey = null, ?string $tempKey = null) + { + parent::__construct( + [RequestOptions::JSON => ['push_key' => $pushKey, 'temp_key' => $tempKey]], + true + ); + } +} diff --git a/src/PushMe/Client.php b/src/PushMe/Client.php new file mode 100644 index 0000000..7c3a284 --- /dev/null +++ b/src/PushMe/Client.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + * + * @see https://github.com/guanguans/notify + */ + +namespace Guanguans\Notify\PushMe; + +use Guanguans\Notify\Foundation\Contracts\Authenticator; + +class Client extends \Guanguans\Notify\Foundation\Client +{ + public function __construct(Authenticator $authenticator) + { + parent::__construct($authenticator); + $this->baseUri('https://push.i-i.me'); + } +} diff --git a/src/PushMe/Messages/Message.php b/src/PushMe/Messages/Message.php new file mode 100644 index 0000000..b6e21c4 --- /dev/null +++ b/src/PushMe/Messages/Message.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + * + * @see https://github.com/guanguans/notify + */ + +namespace Guanguans\Notify\PushMe\Messages; + +use Guanguans\Notify\Foundation\Concerns\AsNullUri; + +/** + * @method self content($content) + * @method self date($date) + * @method self pushKey($pushKey) + * @method self tempKey($tempKey) + * @method self title($title) + * @method self type($type) + */ +class Message extends \Guanguans\Notify\Foundation\Message +{ + use AsNullUri; + protected array $defined = [ + 'push_key', + 'temp_key', + 'title', + 'content', + 'type', + 'date', + ]; + protected array $allowedValues = [ + // 'type' => ['text', 'markdown', 'data', 'markdata'], + ]; +} diff --git a/src/PushMe/README.md b/src/PushMe/README.md new file mode 100644 index 0000000..2993bb0 --- /dev/null +++ b/src/PushMe/README.md @@ -0,0 +1,9 @@ +# PushMe + +## [Usage example](./../../tests/PushMe/ClientTest.php) + +## Related links + +* [https://push.i-i.me](https://push.i-i.me) +* [https://push.i-i.me/docs](https://push.i-i.me/docs) +* [https://github.com/yafoo/pushme](https://github.com/yafoo/pushme) diff --git a/tests/PushMe/ClientTest.php b/tests/PushMe/ClientTest.php new file mode 100644 index 0000000..028b27a --- /dev/null +++ b/tests/PushMe/ClientTest.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + * + * @see https://github.com/guanguans/notify + */ + +namespace Guanguans\NotifyTests\PushMe; + +use Guanguans\Notify\PushMe\Authenticator; +use Guanguans\Notify\PushMe\Client; +use Guanguans\Notify\PushMe\Messages\Message; + +it('can send message', function (): void { + $authenticator = new Authenticator( + 'uhDXKk3UXJtdT3dE6', + // 'hLzPCm6Y1y26iddAy' + ); + $client = new Client($authenticator); + $message = Message::make([ + // 'push_key' => 'uhDXKk3UXJtdT3dE6', + // 'temp_key' => 'hLzPCm6Y1y26iddAy', + 'title' => 'This is title.', + 'content' => '> This is content.', + 'date' => date('Y-m-d H:i:s'), + 'type' => 'markdown', + ]); + + expect($client) + ->mock([ + response('success'), + response('请检查push_key是否正确'), + ]) + ->assertCanSendMessage($message); +})->group(__DIR__, __FILE__);