Skip to content

Commit

Permalink
chore(Message): Update message class properties
Browse files Browse the repository at this point in the history
- Updated properties in the Message class:
  - attachment
  - device
  - html
  - priority
  - sound
  - timestamp
  - title
  - ttl
  - url
  - url_title
  - retry
  - expire
  - monospace
  - callback
- Removed 'title' and 'timestamp' methods
- Updated README with Pushover API links
  • Loading branch information
guanguans committed Mar 1, 2024
1 parent fff5689 commit 1bb9bf3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 86 deletions.
103 changes: 17 additions & 86 deletions src/Pushover/Messages/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,23 @@

use Guanguans\Notify\Foundation\Concerns\AsMultipart;
use Guanguans\Notify\Foundation\Concerns\AsPost;
use Guanguans\Notify\Foundation\Exceptions\InvalidOptionsException;
use Guanguans\Notify\Foundation\Exceptions\MissingOptionsException;
use GuzzleHttp\Psr7\Utils;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @method self message($message)
* @method self title($title)
* @method self timestamp($timestamp)
* @method self attachment($attachment)
* @method self device($device)
* @method self html($html)
* @method self priority($priority)
* @method self sound($sound)
* @method self timestamp($timestamp)
* @method self title($title)
* @method self ttl($ttl)
* @method self url($url)
* @method self urlTitle($urlTitle)
* @method self sound($sound)
* @method self retry($retry)
* @method self expire($expire)
* @method self html($html)
* @method self monospace($monospace)
* @method self callback($callback)
* @method self device($device)
* @method self attachment($attachment)
*/
class Message extends \Guanguans\Notify\Foundation\Message
{
Expand All @@ -44,21 +41,23 @@ class Message extends \Guanguans\Notify\Foundation\Message
// 'token',
// 'user',
'message',
'title',
'timestamp',
'attachment',
// 'attachment_base64',
// 'attachment_type',
'device',
'html',
'priority',
'sound',
'timestamp',
'title',
'ttl',
'url',
'url_title',
'sound',

'retry',
'expire',
'html',
'monospace',
'callback',
'device',
'attachment',
// 'attachment_base64',
// 'attachment_type',
];

protected array $required = [
Expand All @@ -67,76 +66,8 @@ class Message extends \Guanguans\Notify\Foundation\Message
'message',
];

protected array $allowedTypes = [
'timestamp' => 'int',
'priority' => 'int',
'retry' => 'int',
'expire' => 'int',
'html' => 'int',
'monospace' => 'int',
'attachment' => ['string', 'resource'],
];

/**
* @var array<array<\int>>
*/
protected array $allowedValues = [
'priority' => [-2, -1, 0, 1, 2],
'html' => [0, 1],
'monospace' => [0, 1],
];

public function toHttpUri(): string
{
return 'https://api.pushover.net/1/messages.json';
}

protected function configureOptionsResolver(OptionsResolver $optionsResolver): void
{
$optionsResolver->setNormalizer(
'priority',
static function (OptionsResolver $optionsResolver, $value): int {
if (2 !== $value) {
return $value;
}

if (isset($optionsResolver['retry'], $optionsResolver['expire'])) {
return $value;
}

throw new MissingOptionsException('The required option "retry" or "expire" is missing.');
}
);

$optionsResolver->setNormalizer(
'html',
static function (OptionsResolver $optionsResolver, $value): int {
if (1 !== $value) {
return $value;
}

if (! isset($optionsResolver['monospace'])) {
return $value;
}

if (1 !== $optionsResolver['monospace']) {
return $value;
}

throw new InvalidOptionsException('Html cannot be set with monospace, Monospace cannot be set with html, Html and monospace are mutually.');
}
);

// $optionsResolver->setNormalizer(
// 'attachment',
// static function (OptionsResolver $optionsResolver, $value) {
// if (\is_string($value)) {
// // $value = fopen($value, 'r');
// $value = Utils::tryFopen($value, 'r');
// }
//
// return $value;
// }
// );
}
}
2 changes: 2 additions & 0 deletions src/Pushover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

## Related links

* [https://pushover.net/api](https://pushover.net/api)
* [https://pushover.net/login](https://pushover.net/login)
* [https://pushover.net/](https://pushover.net/)

0 comments on commit 1bb9bf3

Please sign in to comment.