2017 © Pedro Peláez
 

library pushbots-php

PushBots API

image

pushbots/pushbots-php

PushBots API

  • Thursday, March 1, 2018
  • by AbdullahDiaa
  • Repository
  • 2 Watchers
  • 0 Stars
  • 27 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 50 % Grown

The README.md

Build
Status Maintainability, (*1)

pushbots-php

Official PHP package for PushBots, (*2)

Installation

Requires PHP 5.5., (*3)

Install with Composer

$ php composer.phar require pushbots/pushbots-php

Then require the library in your PHP code:, (*4)

require "vendor/autoload.php";

Example

<?php
// load dependencies
require 'vendor/autoload.php';

use Pushbots\PushbotsClient;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Psr7;

$client = new PushbotsClient("APPLICATION_ID", "APPLICATION_SECRET");

try {
    //Sample sending campaign to all users
    $res = $client->campaign->send([
        //Platforms
        //0 => iOS
        //1 => Android
        //2 => Chrome
        //3 => Firefox
        //4 => Opera
        //5=> Safari
        "platform" => [0,1,2,3,4,5], 
        //Message
        "msg" => "Notification message",
        //Badge [iOS only]
        "badge" => "+1",
        //Notification payload
        "payload"=>[
            "key"=> "value"
        ]
    ]);
} catch (ClientException $e) {
    echo Psr7\str($e->getRequest());
    echo Psr7\str($e->getResponse());
} catch (ServerException $e) {
    echo Psr7\str($e->getRequest());
    echo Psr7\str($e->getResponse());
}

Alias

//Sample sending campaign to an alias
$client->campaign->alias("ALIAS", "Notification message");

Test notification

//Sample sending campaign to an alias
$client->campaign->test();

Exceptions

Guzzle throws exceptions for errors that occur during a transfer., (*5)

Sending to one device [Transactional]

use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Psr7;
......
try {
    $client->transactional->send([
        //topic [Required] of the transactional notification [can be any value, used only for tracking]
        "topic" => "welcome_campaign",
        //Platform [Required]
        //0 => iOS
        //1 => Android
        //2 => Chrome
        //3 => Firefox
        //4 => Opera
        //5=> Safari
        "platform" => 0,
        //recipients [Required]
        "recipients"=> [
            "tokens"=> ["343aa292e2bb642db2abb24124417cdf945a03e18c9434499d0dcef8b0d7dd0f"]
            //==OR== "ids"=>["ID"]
        ],
        //Message [Required]
        "message" => [
            "title"=>"title", //[Optional]
            "body" => "Notification message",
            "payload"   => ["key"=>"value"] //[Optional]
        ]
    ]);
} catch (ClientException $e) {
    echo Psr7\str($e->getRequest());
    echo Psr7\str($e->getResponse());
} catch (ServerException $e) {
    echo Psr7\str($e->getRequest());
    echo Psr7\str($e->getResponse());
}

Changelog

Version 1.2.1 * Add campaign V3 support. * Bug fixes., (*6)

Version 1.2.0 * Bug fixes. * Add transactional API support v3. * Catch GuzzleExceptions in sample code., (*7)

Version 1.1.0 * Add testing notification. * Add Push/one support. * Add alias support., (*8)

Version 1.0.0 * Release PushBots PHP package, (*9)

The Versions

01/03 2018

dev-master

9999999-dev

PushBots API

  Sources   Download

MIT

The Requires

 

The Development Requires

api guzzle pushbots pushbots.com

27/02 2018

1.1.0

1.1.0.0

PushBots API

  Sources   Download

MIT

The Requires

 

The Development Requires

api guzzle pushbots pushbots.com

22/02 2018

1.0.0

1.0.0.0

PushBots API

  Sources   Download

MIT

The Requires

 

The Development Requires

api guzzle pushbots pushbots.com