Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Commit

Permalink
Merging develop to master in preparation for 2.1.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed May 8, 2018
2 parents af9af15 + 9ee330c commit 44f4e2a
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 81 deletions.
23 changes: 14 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
sudo: false

language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm
matrix:
include:
- php: 5.6
- php: 7.0
- php: 7.1
env:
- CS_CHECK=true
- php: 7.2

before_install:
- composer install
- composer install --no-interaction

script:
- ./vendor/bin/phpunit
- ./vendor/bin/phpunit
- if [[ $CS_CHECK == 'true' ]]; then ./vendor/bin/phpcs ; fi

notifications:
irc: "irc.freenode.org#zftalk.2"
email: false
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.0.1 - TBD
## 2.1.0 - 2018-05-08

### Added

- [#35](https://github.com/zendframework/ZendService_Google_Gcm/pull/35) adds support for PHP 7.1 and 7.2.

- [#13](https://github.com/zendframework/ZendService_Google_Gcm/pull/13) adds constants mapping to common GCM error codes as `ZendService\Gcm\Response::ERROR_*`.

### Changed

- Nothing.

### Deprecated
Expand All @@ -14,11 +20,14 @@ All notable changes to this project will be documented in this file, in reverse

### Removed

- Nothing.
- [#35](https://github.com/zendframework/ZendService_Google_Gcm/pull/35) removes support for PHP 5.5.

- [#35](https://github.com/zendframework/ZendService_Google_Gcm/pull/35) removes support for HHVM.

### Fixed

- Nothing.
- [#18](https://github.com/zendframework/ZendService_Google_Gcm/pull/18) adds a `Content-Length` header with the message length prior to sending
messages to GCM; this fixes 411 errors previously observed.

## 2.0.0 - 2017-01-17

Expand Down
18 changes: 9 additions & 9 deletions LICENSE.txt → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Copyright (c) 2005-2014, Zend Technologies USA, Inc.
Copyright (c) 2005-2018, Zend Technologies USA, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

* Neither the name of Zend Technologies USA, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
- Neither the name of Zend Technologies USA, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ ZendService\Google\Gcm [![Build Status](https://api.travis-ci.org/zendframework/

Provides support for Google push notifications.

## Requirements ##
## Requirements

* PHP >= 5.3.3
* PHP >= 5.6

## Getting Started ##
## Getting Started

Install this library using [Composer](http://getcomposer.org/):

```bash
$ composer require zendframework/zendservice-google-gcm
```

## Documentation ##
## Documentation

The documentation can be found at: http://framework.zend.com/manual/current/en/modules/zendservice.google.gcm.html
40 changes: 28 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,48 @@
{
"name": "zendframework/zendservice-google-gcm",
"description": "OOP wrapper for Google Cloud Messaging",
"type": "library",
"license": "BSD-3-Clause",
"keywords": [
"zf2",
"zf",
"zendframework",
"gcm",
"push",
"notification",
"google"
],
"homepage": "https://github.com/zendframework/zendservice-google-gcm",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/zendframework/ZendService_Google_Gcm/issues",
"source": "https://github.com/zendframework/ZendService_Google_Gcm",
"rss": "https://github.com/zendframework/ZendService_Google_Gcm/releases.atom",
"chat": "https://zendframework-slack.herokuapp.com",
"forum": "https://discourse.zendframework.com/c/questions/components"
},
"require": {
"php": "^5.6 || ^7.0",
"zendframework/zend-http": "^2.0",
"zendframework/zend-json": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.5",
"zendframework/zend-coding-standard": "~1.0.0"
},
"autoload": {
"psr-4": {
"ZendService\\Google\\": "library/"
"ZendService\\Google\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ZendServiceTest\\Google\\": "tests/"
"ZendServiceTest\\Google\\": "test/"
}
},
"require": {
"php": "^5.5 || ^7.0",
"zendframework/zend-http": "^2.0",
"zendframework/zend-json": "^2.0"
"config": {
"sort-packages": true
},
"require-dev": {
"phpunit/PHPUnit": "^4.8"
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev",
"dev-develop": "2.2.x-dev"
}
}
}
7 changes: 7 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<ruleset name="Zend Framework Coding Standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>

<file>src</file>
<file>test</file>
</ruleset>
18 changes: 11 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<phpunit bootstrap="vendor/autoload.php" colors="true">
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="ZendService Google Gcm Test Suite">
<directory>./tests</directory>
<directory>./test</directory>
</testsuite>
</testsuites>

<groups>
<exclude>
<group>disable</group>
</exclude>
</groups>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
File renamed without changes.
9 changes: 5 additions & 4 deletions library/Gcm/Client.php → src/Gcm/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getApiKey()
*/
public function setApiKey($apiKey)
{
if (!is_string($apiKey) || empty($apiKey)) {
if (! is_string($apiKey) || empty($apiKey)) {
throw new Exception\InvalidArgumentException('The api key must be a string and not empty');
}
$this->apiKey = $apiKey;
Expand All @@ -77,7 +77,7 @@ public function setApiKey($apiKey)
*/
public function getHttpClient()
{
if (!$this->httpClient) {
if (! $this->httpClient) {
$this->httpClient = new HttpClient();
$this->httpClient->setOptions(['strictredirects' => true]);
}
Expand Down Expand Up @@ -119,7 +119,8 @@ public function send(Message $message)
$client = $this->getHttpClient();
$client->setUri(self::SERVER_URI);
$headers = $client->getRequest()->getHeaders();
$headers->addHeaderLine('Authorization', 'key='.$this->getApiKey());
$headers->addHeaderLine('Authorization', 'key=' . $this->getApiKey());
$headers->addHeaderLine('Content-length', mb_strlen($message->toJson()));

$response = $client->setHeaders($headers)
->setMethod('POST')
Expand All @@ -146,7 +147,7 @@ public function send(Message $message)
break;
}

if (!$response = Json::decode($response->getBody(), Json::TYPE_ARRAY)) {
if (! $response = Json::decode($response->getBody(), Json::TYPE_ARRAY)) {
throw new Exception\RuntimeException('Response body did not contain a valid JSON response');
}

Expand Down
14 changes: 7 additions & 7 deletions library/Gcm/Message.php → src/Gcm/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ public function getRegistrationIds()
*/
public function addRegistrationId($id)
{
if (!is_string($id) || empty($id)) {
if (! is_string($id) || empty($id)) {
throw new Exception\InvalidArgumentException('$id must be a non-empty string');
}
if (!in_array($id, $this->registrationIds)) {
if (! in_array($id, $this->registrationIds)) {
$this->registrationIds[] = $id;
}

Expand Down Expand Up @@ -151,7 +151,7 @@ public function getCollapseKey()
*/
public function setCollapseKey($key)
{
if (null !== $key && !(is_string($key) && strlen($key) > 0)) {
if (null !== $key && ! (is_string($key) && strlen($key) > 0)) {
throw new Exception\InvalidArgumentException('$key must be null or a non-empty string');
}
$this->collapseKey = $key;
Expand All @@ -178,7 +178,7 @@ public function getPriority()
*/
public function setPriority($priority)
{
if (!is_null($priority) && !(is_string($priority) && strlen($priority) > 0)) {
if (! is_null($priority) && ! (is_string($priority) && strlen($priority) > 0)) {
throw new Exception\InvalidArgumentException('$priority must be null or a non-empty string');
}
$this->priority = $priority;
Expand Down Expand Up @@ -227,7 +227,7 @@ public function getData()
*/
public function addData($key, $value)
{
if (!is_string($key) || empty($key)) {
if (! is_string($key) || empty($key)) {
throw new Exception\InvalidArgumentException('$key must be a non-empty string');
}
if (array_key_exists($key, $this->data)) {
Expand Down Expand Up @@ -286,7 +286,7 @@ public function getNotification()
*/
public function addNotification($key, $value)
{
if (!is_string($key) || empty($key)) {
if (! is_string($key) || empty($key)) {
throw new Exception\InvalidArgumentException('$key must be a non-empty string');
}
if (array_key_exists($key, $this->notification)) {
Expand Down Expand Up @@ -367,7 +367,7 @@ public function getTimeToLive()
*/
public function setRestrictedPackageName($name)
{
if (null !== $name && !(is_string($name) && strlen($name) > 0)) {
if (null !== $name && ! (is_string($name) && strlen($name) > 0)) {
throw new Exception\InvalidArgumentException('$name must be null OR a non-empty string');
}
$this->restrictedPackageName = $name;
Expand Down
26 changes: 25 additions & 1 deletion library/Gcm/Response.php → src/Gcm/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ class Response
*/
const RESULT_CANONICAL = 'registration_id';

/**
* Error field responses
* @link https://developers.google.com/cloud-messaging/http-server-ref#error-codes
* @var string
*/
const ERROR_MISSING_REGISTRATION = 'MissingRegistration';
const ERROR_INVALID_REGISTRATION = 'InvalidRegistration';
const ERROR_NOT_REGISTERED = 'NotRegistered';
const ERROR_INVALID_PACKAGE_NAME = 'InvalidPackageName';
const ERROR_MISMATCH_SENDER_ID = 'MismatchSenderId';
const ERROR_MESSAGE_TOO_BIG = 'MessageTooBig';
const ERROR_INVALID_DATA_KEY = 'InvalidDataKey';
const ERROR_INVALID_TTL = 'InvalidTtl';
const ERROR_UNAVAILABLE = 'Unavailable';
const ERROR_INTERNAL_SERVER_ERROR = 'InternalServerError';
const ERROR_DEVICE_MESSAGE_RATE_EXCEEDED = 'DeviceMessageRateExceeded';
const ERROR_TOPICS_MESSAGE_RATE_EXCEEDED = 'TopicsMessageRateExceeded';

/**
* @var int
*/
Expand Down Expand Up @@ -138,7 +156,13 @@ public function getResponse()
*/
public function setResponse(array $response)
{
if (!isset($response['results'], $response['success'], $response['failure'], $response['canonical_ids'], $response['multicast_id'])) {
if (! isset(
$response['results'],
$response['success'],
$response['failure'],
$response['canonical_ids'],
$response['multicast_id']
)) {
throw new Exception\InvalidArgumentException('Response did not contain the proper fields');
}

Expand Down
Loading

0 comments on commit 44f4e2a

Please sign in to comment.