Skip to content

Commit

Permalink
feat(PushMe): adds PushMe package
Browse files Browse the repository at this point in the history
- Adds `Authenticator` class to handle PushMe authentication
- Adds `Client` class for PushMe API communication
- Adds `Message` class for creating PushMe messages
- Includes documentation and related links
  • Loading branch information
guanguans committed Jan 13, 2025
1 parent ae2085d commit 39ee13b
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down Expand Up @@ -38,6 +38,7 @@
"Pushback",
"PushBullet",
"PushDeer",
"PushMe",
"Pushover",
"PushPlus",
"QQ",
Expand Down
30 changes: 30 additions & 0 deletions ide.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
28 changes: 28 additions & 0 deletions src/PushMe/Authenticator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021-2025 guanguans<[email protected]>
*
* 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
);
}
}
25 changes: 25 additions & 0 deletions src/PushMe/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021-2025 guanguans<[email protected]>
*
* 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');
}
}
40 changes: 40 additions & 0 deletions src/PushMe/Messages/Message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021-2025 guanguans<[email protected]>
*
* 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'],
];
}
9 changes: 9 additions & 0 deletions src/PushMe/README.md
Original file line number Diff line number Diff line change
@@ -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)
44 changes: 44 additions & 0 deletions tests/PushMe/ClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/** @noinspection StaticClosureCanBeUsedInspection */
/** @noinspection PhpUnhandledExceptionInspection */

declare(strict_types=1);

/**
* Copyright (c) 2021-2025 guanguans<[email protected]>
*
* 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__);

0 comments on commit 39ee13b

Please sign in to comment.