serhiy/pushover

Light, simple and fast, yet comprehensive wrapper for the Pushover API.

v1.6.0 2024-08-29 08:23 UTC

README

Build Status Latest Stable Version Total Downloads License

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

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();

Tip

For more code examples, see examples folder in the root of the project.

Working with response

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();

Tip

For complete example refer to ResponseExample.php.

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.