Skip to content

Commit df5c40d

Browse files
committed
Add push/one, alias and testing support
1 parent 4e103e9 commit df5c40d

File tree

6 files changed

+132
-7
lines changed

6 files changed

+132
-7
lines changed

README.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,69 @@ require 'vendor/autoload.php';
3535
use Pushbots\PushbotsClient;
3636

3737
$client = new PushbotsClient("APPLICATION_ID", "APPLICATION_SECRET");
38+
39+
//Sample sending campaign to all users
3840
$client->campaign->send([
3941
//Platforms
40-
"platform" => [0,1,2],
42+
//0 => iOS
43+
//1 => Android
44+
//2 => Chrome
45+
//3 => Firefox
46+
//4 => Safari
47+
"platform" => [0,1,2,3,4],
4148
//Message
42-
"msg" => "test",
49+
"msg" => "Notification message"
4350
//Badge [iOS only]
4451
"badge" => "+1",
4552
//Notification payload
4653
"payload"=>[
4754
"key"=> "value"
4855
]
4956
]);
57+
58+
```
59+
60+
Alias
61+
------------
62+
63+
```php
64+
//Sample sending campaign to an alias
65+
$client->campaign->alias("ALIAS", "Notification message");
5066
```
5167

5268

69+
Test notification
70+
------------
71+
72+
```php
73+
//Sample sending campaign to an alias
74+
$client->campaign->test();
75+
```
76+
77+
Sending to one device [Transactional]
78+
------------
79+
80+
```php
81+
//Sample sending campaign to an alias
82+
$client->transactional->send([
83+
// iOS and Android only supported
84+
//0 => iOS
85+
//1 => Android
86+
"platform" => 0,
87+
//token
88+
"token" => "71e7aef2f01d055b11c958dc48d06a655541b054196dd33b071777e1557dcb48",
89+
//Message
90+
"msg" => "Notification message"
91+
]);
92+
```
5393

5494
Changelog
5595
-------------
5696

97+
Version 1.1.0
98+
* Add testing notification.
99+
* Add Push/one support.
100+
* Add alias support.
101+
57102
Version 1.0.0
58103
* Release PushBots PHP package

src/.htaccess

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/PushbotsCampaign.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,29 @@ public function send($options)
3131
{
3232
return $this->_client->post("push/all", $options);
3333
}
34+
35+
/**
36+
* Sends a notification using alias [v1]
37+
*
38+
* @param string $alias Alias
39+
* @param string $msg Notification message
40+
* @param string $payload
41+
* @return mixed
42+
* @throws \GuzzleHttp\Exception\GuzzleException
43+
*/
44+
public function alias($alias, $msg, $payload = [])
45+
{
46+
return $this->_client->post("push/all", ["platform" => [0,1,2,3,4], "alias" => $alias, "msg" => $msg, "payload"=> $payload]);
47+
}
48+
49+
/**
50+
* Sends a test notification to test devices [v1]
51+
*
52+
* @return mixed
53+
* @throws \GuzzleHttp\Exception\GuzzleException
54+
*/
55+
public function test()
56+
{
57+
return $this->_client->post("push/all", ["platform" => [0,1,2,3,4], "alias" => "PB_TESTING_DEVICE", "msg" => "Testing notification from PushBots"]);
58+
}
3459
}

src/PushbotsClient.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class PushbotsClient
4141
*/
4242
public $campaign;
4343

44+
/**
45+
* @var PushbotsTransactional $$transactional Sends a notification to single user using Pushbots API.
46+
*/
47+
public $transactional;
4448

4549
/**
4650
* PushbotsClient constructor.
@@ -52,6 +56,7 @@ public function __construct($applicationId, $applicationSecret)
5256
{
5357
$this->_setClient();
5458
$this->campaign = new PushbotsCampaign($this);
59+
$this->transactional = new PushbotsTransactional($this);
5560

5661
$this->applicationId = $applicationId;
5762
$this->applicationSecret = $applicationSecret;

src/PushbotsTransactional.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Pushbots;
4+
5+
class PushbotsTransactional
6+
{
7+
/**
8+
* @var PushbotsTransactional
9+
*/
10+
private $_client;
11+
12+
/**
13+
* PushbotsTransactional constructor.
14+
*
15+
* @param PushbotsClient $client
16+
*/
17+
public function __construct($client)
18+
{
19+
$this->_client = $client;
20+
}
21+
22+
/**
23+
* Sends a notification [v1]
24+
*
25+
* @see https://developer.pushbots.com/api/v2/#/Devices/pushOne
26+
* @param array $options
27+
* @return mixed
28+
* @throws \GuzzleHttp\Exception\GuzzleException
29+
*/
30+
public function send($options)
31+
{
32+
return $this->_client->post("push/one", $options);
33+
}
34+
}

test/PushbotsTransactionalTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Pushbots\PushbotsTransactional;
4+
use Pushbots\PushbotsClient;
5+
use GuzzleHttp\Client;
6+
use GuzzleHttp\Handler\MockHandler;
7+
use GuzzleHttp\Psr7\Response;
8+
use GuzzleHttp\HandlerStack;
9+
use GuzzleHttp\Middleware;
10+
11+
class PushbotsTransactionalTest extends PHPUnit_Framework_TestCase
12+
{
13+
public function testCampaignSend()
14+
{
15+
$stub = $this->getMockBuilder('Pushbots\PushbotsClient')->disableOriginalConstructor()->getMock();
16+
$stub->method('send')->willReturn(null);
17+
18+
$campaign = new PushbotsTransactional($stub);
19+
$this->assertEquals(null, $campaign->send([]));
20+
}
21+
}

0 commit comments

Comments
 (0)