Skip to content

appricos/pushinator-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pushinator PHP Client

A PHP Composer package that enables developers to send push notifications seamlessly through the Pushinator API.

Installation

Install the package using Composer:

composer require appricos/pushinator-php

Make sure Composer's autoloader is included in your project:

require 'vendor/autoload.php';

Usage

Initializing the Client

To start using the PushinatorClient, create an instance by passing your API token:

use Pushinator\PushinatorClient;

$client = new PushinatorClient('PUSHINATOR_API_TOKEN');

Sending Notifications

To send a notification to a specific channel, use the sendNotification method. Provide your channel ID and the notification content as arguments:

use Pushinator\PushinatorClient;

$client = new PushinatorClient('PUSHINATOR_API_TOKEN');

try {
    $client->sendNotification('PUSHINATOR_CHANNEL_ID', 'Hello from PHP!');
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

Managing Channels

All channel methods return an array with the decoded JSON response from the API. On failure, a RuntimeException is thrown.

List channels

$channels = $client->listChannels();
// $channels['data'] — array of channel objects

Create a channel

$channel = $client->createChannel(
    name: 'My Channel',
    description: 'Optional description',  // optional
);
// $channel['data'] — created channel object

Get a channel

$channel = $client->getChannel('PUSHINATOR_CHANNEL_ID');
// $channel['data'] — channel object

Update a channel

$channel = $client->updateChannel(
    channelId: 'PUSHINATOR_CHANNEL_ID',
    name: 'Updated Name',
    description: 'Updated description',   // optional
);
// $channel['data'] — updated channel object

Delete a channel

$channel = $client->deleteChannel('PUSHINATOR_CHANNEL_ID');
// $channel['data'] — deleted channel object

Channel object structure

{
  "data": {
    "id": "channel-id",
    "name": "My Channel",
    "description": "Optional description",
    "acknowledgment_enabled": false,
    "created_at": "2024-01-01T00:00:00.000000Z",
    "updated_at": "2024-01-01T00:00:00.000000Z"
  }
}

About

Send push notifications with PHP via Pushinator

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages