Coder Social home page Coder Social logo

pushover-php's Introduction

Pushover PHP API Wrapper

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
  • 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)
    • 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": ">=7.4",
        "ext-curl": "*",
        "ext-json": "*"
    }
}

Pushing Messages

Note: For more code examples, see Example 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.

pushover-php's People

Contributors

slunak avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.