Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d98b7f3
Add files via upload
dommccarty Jan 8, 2017
8a5f0f5
Update README.md
dommccarty Jan 8, 2017
f0b18bf
Update README.md
dommccarty Jan 8, 2017
da554d7
Add files via upload
dommccarty Jan 8, 2017
60abcd7
Update Exception.php
dommccarty Jan 8, 2017
8f74f3e
Update README.md
dommccarty Jan 8, 2017
530f345
Update Response.php
dommccarty Jan 8, 2017
bf1d7e5
Stop storing raw response
dommccarty Jan 8, 2017
266823c
Update Response.php
dommccarty Jan 8, 2017
4e5bc71
Update Response.php
dommccarty Jan 8, 2017
bc6b5a5
Update README.md
dommccarty Jan 10, 2017
705fc9b
Update README.md
dommccarty Jan 10, 2017
b758c7c
Update README.md
dommccarty Jan 10, 2017
042ebb0
Update README.md
dommccarty Jan 10, 2017
cc44eb9
Respond to pull request remarks
dommccarty Jan 10, 2017
4b27d4e
Indentation
dommccarty Jan 10, 2017
712ea7c
Text editor problems ...
dommccarty Jan 10, 2017
235a667
Add files via upload
dommccarty Jan 10, 2017
8c4f381
Update Exception.php
dommccarty Jan 10, 2017
48d6ab3
Indentation gremlins
dommccarty Jan 10, 2017
7e85a44
Update Response.php
dommccarty Jan 10, 2017
ca976f3
Update Response.php
dommccarty Jan 10, 2017
93a27a2
Update Sender.php
dommccarty Jan 10, 2017
7e68f27
Update Message.php
dommccarty Jan 10, 2017
e428154
Update Message.php
dommccarty Jan 10, 2017
1761917
Update Response.php
dommccarty Jan 10, 2017
3bbc5ed
Update README.md
dommccarty Jan 10, 2017
2868047
Indentation ...
dommccarty Jan 10, 2017
418efd3
Indentation
dommccarty Jan 10, 2017
ec55ec9
Indentation
dommccarty Jan 10, 2017
ea3a222
Update Response.php
dommccarty Jan 10, 2017
1635a89
Indentation
dommccarty Jan 10, 2017
2e763b3
Respond to comments
dommccarty Jan 11, 2017
90c63ab
Delete Exception.php
dommccarty Jan 11, 2017
af89559
Delete Message.php
dommccarty Jan 11, 2017
79cf163
Delete Response.php
dommccarty Jan 11, 2017
a5cdd5e
Delete Sender.php
dommccarty Jan 11, 2017
5470a0c
Respond to comments
dommccarty Jan 11, 2017
c8fb000
Add files via upload
dommccarty Jan 11, 2017
3190ea4
Add files via upload
dommccarty Jan 11, 2017
268de47
Add files via upload
dommccarty Jan 11, 2017
68eea46
Strip out "\r" from headers too
dommccarty Jan 14, 2017
bcb07c9
Includes colon now.
dommccarty Jan 14, 2017
8fecb99
change ->notification to ->setNotification
dommccarty Jan 14, 2017
4b33453
Add files via upload
dommccarty Jan 14, 2017
d05d88f
Add files via upload
dommccarty Jan 14, 2017
ddfa5cf
Slimming down
dommccarty Jan 14, 2017
019602e
Add files via upload
dommccarty Jan 14, 2017
b978100
Add files via upload
dommccarty Jan 14, 2017
03db6b7
Add files via upload
dommccarty Jan 14, 2017
13a0bc2
Add files via upload
dommccarty Jan 14, 2017
c0e9cc9
Add files via upload
dommccarty Jan 14, 2017
033a9cc
Add files via upload
dommccarty Jan 14, 2017
45eb6ed
Add files via upload
dommccarty Jan 14, 2017
1d942c8
Add files via upload
dommccarty Jan 15, 2017
9e9dc81
Add files via upload
dommccarty Jan 15, 2017
2fa1df9
Rename travis.yml to .travis.yml
dommccarty Jan 15, 2017
4c2b90a
Add files via upload
dommccarty Jan 15, 2017
daa3bd4
Update README.md
dommccarty Jan 15, 2017
c1dce41
Add files via upload
dommccarty Jan 15, 2017
6caf321
Add files via upload
dommccarty Jan 15, 2017
bc3723c
Added Travis CI build status icon
dommccarty Jan 15, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: php
php:
- "5.6"
- "7.0"
- "7.1"
install: composer install
script:
- vendor/bin/phpunit
- vendor/bin/phpcs --standard=PSR2 library/ tests/
66 changes: 55 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Google Cloud Messaging (GCM) PHP Server Library
--------------------------------------------

A PHP library for sending messages to devices registered through Google Cloud Messaging.
A PHP library for sending messages to devices registered through Google Cloud Messaging. [![Build Status](https://travis-ci.org/dommccarty/GCMMessage.svg?branch=master)](https://travis-ci.org/dommccarty/GCMMessage)

See:
http://developer.android.com/guide/google/gcm/index.html
Expand All @@ -20,7 +20,7 @@ $message = new GCM\Message(
);

$message
->notification(array("title" => "foo", "body" => "bar"))
->setNotification(array("title" => "foo", "body" => "bar"))
->setCollapseKey("collapse_key")
->setDelayWhileIdle(true)
->setTtl(123)
Expand All @@ -40,7 +40,21 @@ try {
}

if ($response->getFailureCount() > 0) {
$invalidRegistrationIds = $GCMresponse->getInvalidRegistrationIds();

if ($response->getExistsInvalidDataKey()) {
//You used a reserved data key
$error_msg = 'Invalid data key in payload. ' . json_encode($message->getNotification());
throw new Exception($error_msg, Exception::INVALID_DATA_KEY);
}

if ($response->getExistsMismatchSenderId()) {
//A client sent the wrong senderId when it registered for pushes
$error_msg = 'Mismatch senderId. Problem clients are '
. json_encode($response->getMismatchSenderIdIds());
throw new Exception($error_msg, Exception::MISMATCH_SENDER_ID);
}

$invalidRegistrationIds = $response->getInvalidRegistrationIds();
foreach($invalidRegistrationIds as $invalidRegistrationId) {
//Remove $invalidRegistrationId from DB
//TODO
Expand All @@ -53,11 +67,20 @@ try {
} catch (GCM\Exception $e) {

switch ($e->getCode()) {

case GCM\Exception::UNKNOWN_ERROR:
if ($e->getMustRetry()) {
$waitSeconds = $e->getWaitSeconds();
//retry in that many seconds, and use exponential back-off subsequently.
//TODO
break;
}
case GCM\Exception::ILLEGAL_API_KEY:
case GCM\Exception::AUTHENTICATION_ERROR:
case GCM\Exception::MALFORMED_REQUEST:
case GCM\Exception::UNKNOWN_ERROR:
case GCM\Exception::MALFORMED_REQUEST:
case GCM\Exception::MALFORMED_RESPONSE:
case GCM\Exception::INVALID_DATA_KEY: //you used a forbidden key in the notification
case GCM\Exception::MISMATCH_SENDER_ID; //a client sent the wrong senderId when it registered for pushes
//Deal with it
break;
}
Expand Down Expand Up @@ -89,7 +112,21 @@ try {
}

if ($response->getFailureCount() > 0) {
$invalidRegistrationIds = $GCMresponse->getInvalidRegistrationIds();

if ($response->getExistsInvalidDataKey()) {
//You used a reserved data key
$error_msg = 'Invalid data key in payload. ' . json_encode($message->getNotification());
throw new Exception($error_msg, Exception::INVALID_DATA_KEY);
}

if ($response->getExistsMismatchSenderId()) {
//A client sent the wrong senderId when it registered for pushes
$error_msg = 'Mismatch senderId. Problem clients are '
. json_encode($response->getMismatchSenderIdIds());
throw new Exception($error_msg, Exception::MISMATCH_SENDER_ID);
}

$invalidRegistrationIds = $response->getInvalidRegistrationIds();
foreach($invalidRegistrationIds as $invalidRegistrationId) {
//Remove $invalidRegistrationId from DB
//TODO
Expand All @@ -102,11 +139,20 @@ try {
} catch (GCM\Exception $e) {

switch ($e->getCode()) {

case GCM\Exception::UNKNOWN_ERROR:
if ($e->getMustRetry()) {
$waitSeconds = $e->getWaitSeconds();
//retry in that many seconds, and use exponential back-off subsequently.
//TODO
break;
}
case GCM\Exception::ILLEGAL_API_KEY:
case GCM\Exception::AUTHENTICATION_ERROR:
case GCM\Exception::MALFORMED_REQUEST:
case GCM\Exception::UNKNOWN_ERROR:
case GCM\Exception::MALFORMED_REQUEST:
case GCM\Exception::MALFORMED_RESPONSE:
case GCM\Exception::INVALID_DATA_KEY: //you used a forbidden key in the notification
case GCM\Exception::MISMATCH_SENDER_ID; //a client sent the wrong senderId when it registered for pushes
//Deal with it
break;
}
Expand All @@ -131,8 +177,6 @@ $sender = new GCM\Sender("YOUR GOOGLE API KEY", false, "/path/to/cacert.crt");

ChangeLog
----------------------
* v0.3 - Content-available added (https://github.com/CodeMonkeysRu/GCMMessage/pull/11)
* v0.2 - Notifications added
* v0.1 - Initial release


Licensed under MIT license.
52 changes: 30 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
{
"name": "codemonkeys-ru/gcm-message",
"type": "library",
"description": "Google Cloud Messaging (GCM) PHP Server Library",
"keywords": ["GCM", "push message", "android"],
"authors": [
{
"name": "Vladimir Savenkov",
"email": "ivariable@gmail.com",
"homepage": "http://ivariable.ru",
"role": "Developer"
}
],
"license": "MIT",
"require": {
"php": ">=5.3.2"
},
"minimum-stability": "dev",
"autoload": {
"psr-0": {
"CodeMonkeysRu\\GCM": "library/"
}
}
"name": "codemonkeys-ru/gcm-message",
"minimum-stability": "stable",
"type": "library",
"description": "Google Cloud Messaging (GCM) PHP Server Library",
"keywords": [
"GCM",
"push message",
"android"
],
"authors": [
{
"name": "Vladimir Savenkov",
"email": "ivariable@gmail.com",
"homepage": "https://github.com/iVariable",
"role": "Maintainer"
}
],
"license": "MIT",
"autoload": {
"psr-0": {
"CodeMonkeysRu\\GCM": "library/"
}
},
"require": {
"php": ">=5.6"
},
"require-dev": {
"squizlabs/php_codesniffer": "2.*",
"phpunit/phpunit": "5.7.*"
}
}
25 changes: 23 additions & 2 deletions library/CodeMonkeysRu/GCM/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,26 @@ class Exception extends \Exception
const MALFORMED_REQUEST = 3;
const UNKNOWN_ERROR = 4;
const MALFORMED_RESPONSE = 5;

}
const INVALID_DATA_KEY = 6;
const MISMATCH_SENDER_ID = 7;

private $mustRetry = false;
private $waitSeconds = null;

public function setMustRetry($bool)
{
$this->mustRetry = $bool;
}
public function getMustRetry()
{
return $this->mustRetry;
}
public function setWaitSeconds($int)
{
$this->waitSeconds = $int;
}
public function getWaitSeconds()
{
return $this->waitSeconds;
}
}
6 changes: 3 additions & 3 deletions library/CodeMonkeysRu/GCM/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public function __construct($registrationIds = null, $data = null, $collapseKey
/**
* Set multiple fields at once.
*
* @param string[] $registrationIds
* @param array|null $data
* @param string[] $registrationIds
* @param array|null $data
* @param string|null $collapseKey
*/
public function bulkSet($registrationIds = array(), $data = null, $collapseKey = null)
Expand Down Expand Up @@ -222,4 +222,4 @@ public function setContentAvailable($contentAvailable)
$this->contentAvailable = $contentAvailable;
return $this;
}
}
}
Loading