serhiy / pushover
Light, simple and fast, yet comprehensive wrapper for the Pushover API.
Installs: 76 538
Dependents: 2
Suggesters: 0
Security: 0
Stars: 21
Watchers: 2
Forks: 2
Open Issues: 5
Requires
- php: >=7.4
- ext-curl: *
- ext-json: *
Requires (Dev)
- ergebnis/composer-normalize: ^2.43
- ergebnis/php-cs-fixer-config: ^6.34
- friendsofphp/php-cs-fixer: ^3.61
- phpstan/phpstan: ^1.11
- phpunit/phpunit: *
- rector/rector: ^1.2
This package is auto-updated.
Last update: 2024-09-03 10:53:57 UTC
README
Light, simple and fast, yet comprehensive wrapper for the Pushover API.
Features
- Message API (Example)
- Image attachment
- User's device name(s)
- Message's title
- HTML messages
- Supplementary URL and its title
- Notification priority
- Notification sound (including custom sound)
- Message time
- Time to live
- User/Group Validation API (Example)
- Validation by user or group key
- Validation by user and device
- Receipt API (Example)
- Query emergency priority receipt
- Cancel emergency priority retry
- Groups API (Example)
- Create a group
- List groups
- Retrieve information about the group
- Add / Remove users
- Enable / Disable users
- Rename the group
- Glances API (Example)
- Title
- Text
- Subtext
- Count
- Percent
- Licensing API (Example)
- Check remaining credits
- Assign license (not tested)
- Subscription API (Example)
- User Key Migration
Getting Started
These instructions will get you a copy of the project up and running.
Installing
composer require serhiy/pushover
Requirements
I aim to keep the project as simple as possible. All you need to run it is a PHP supported version,
plus its curl and json extensions. See below the require
section of project's composer.json file:
{ "require": { "php": ">=8.2", "ext-curl": "*", "ext-json": "*" } }
Pushing Messages
Note: For more code examples, see examples folder in the root of the project. You may also generate and see code documentation.
Instantiate pushover application and recipient of the notification:
use Serhiy\Pushover\Application; use Serhiy\Pushover\Recipient; $application = new Application('replace_with_pushover_application_api_token'); $recipient = new Recipient('replace_with_pushover_user_key');
Or use Dependency Injection to inject them into the services of your app.
Compose a message:
use Serhiy\Pushover\Api\Message\Message; $message = new Message('This is a test message', 'This is a title of the message');
Create notification:
use Serhiy\Pushover\Api\Message\Notification; $notification = new Notification($application, $recipient, $message);
Push it:
/** @var \Serhiy\Pushover\Client\Response\MessageResponse $response */ $response = $notification->push();
Working with response
Note: For complete example refer to ResponseExample.php
Client returns Response object. Checking if the message was accepted is easy:
if ($response->isSuccessful()) { // ... }
One can get status and token returned by Pushover:
$response->getRequestStatus(); $response->getRequestToken();
Or even unmodified json response from the API (json_decode into an array if needed):
$response->getCurlResponse();
Response also contains original Request object:
/** @var \Serhiy\Pushover\Client\Request\Request $request */ $request = $response->getRequest();
Request contains array for CURLOPT_POSTFIELDS curl argument and full API URL.
$request->getCurlPostFields(); $request->getApiUrl();
Contributing
Contributions are very welcome. If you would like to add functionality, before starting your work, please open an issue to discuss the feature you would like to work on.
Please read CONTRIBUTING.md for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
There are many PHP wrappers for Pushover API. However, most of them seem abandoned, missing features or require extra libraries to work. Nevertheless, many of them inspired me to work on this project.