Skip to content

Commit

Permalink
Merge pull request #17 from CodeMonkeysRu/release/v0.5
Browse files Browse the repository at this point in the history
Release/v0.5
  • Loading branch information
iVariable authored Jan 13, 2017
2 parents c32e240 + 1b8e4f9 commit c7e5c81
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ $message
->setTtl(123)
->setRestrictedPackageName("com.example.trololo")
->setDryRun(true)
->setPriority(GCM\MessageMessage::PRIORITY_HIGH)
;

try {
Expand Down Expand Up @@ -132,6 +133,7 @@ $sender = new GCM\Sender("YOUR GOOGLE API KEY", false, "/path/to/cacert.crt");

ChangeLog
----------------------
* v0.5 - Added support for "priority" flag (https://github.com/CodeMonkeysRu/GCMMessage/pull/16)
* v0.4 - Code cleanup, PHP5.5 support dropped
* v0.3 - Content-available added (https://github.com/CodeMonkeysRu/GCMMessage/pull/11)
* v0.2 - Notifications added
Expand Down
36 changes: 36 additions & 0 deletions library/CodeMonkeysRu/GCM/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
class Message
{
const PRIORITY_NORMAL = 'normal';
const PRIORITY_HIGH = 'high';

/**
* A string array with the list of devices (registration IDs) receiving the message.
Expand Down Expand Up @@ -96,6 +98,21 @@ class Message
*/
private $contentAvailable = true;

/**
* Sets the priority of the message. Valid values are "normal" and "high." On iOS, these
* correspond to APNs priority 5 and 10. By default, messages are sent with normal
* priority. Normal priority optimizes the client app's battery consumption, and should
* be used unless immediate delivery is required. For messages with normal priority, the
* app may receive the message with unspecified delay.
* When a message is sent with high priority, it is sent immediately, and the app can wake
* a sleeping device and open a network connection to your server.
*
* Optional.
*
* @var string
*/
private $priority = self::PRIORITY_NORMAL;

/**
* Allows developers to test their request without actually sending a message.
*
Expand Down Expand Up @@ -222,4 +239,23 @@ public function setContentAvailable($contentAvailable)
$this->contentAvailable = $contentAvailable;
return $this;
}

public function getPriority()
{
return $this->priority;
}

public function setPriority($priority)
{
$allowedPriorities = array(self::PRIORITY_HIGH, self::PRIORITY_NORMAL);

if (!in_array($priority, $allowedPriorities, true)) {
throw new \InvalidArgumentException(
'Invalid priority "' . $priority . '", allowed are only these: ' . implode(', ', $allowedPriorities)
);
}

$this->priority = $priority;
return $this;
}
}
1 change: 1 addition & 0 deletions library/CodeMonkeysRu/GCM/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private function formMessageData(Message $message)
'restricted_package_name' => 'getRestrictedPackageName',
'dry_run' => 'getDryRun',
'content_available' => 'getContentAvailable',
'priority' => 'getPriority',
);

foreach ($dataFields as $fieldName => $getter) {
Expand Down

0 comments on commit c7e5c81

Please sign in to comment.