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

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mwillbanks committed Jan 17, 2017
2 parents 90efb90 + 343e7c4 commit f5a0c72
Show file tree
Hide file tree
Showing 21 changed files with 652 additions and 626 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm

before_install:
- cp tests/TestConfiguration.php.travis tests/TestConfiguration.php
- composer install --dev
- composer install

script:
- phpunit -c tests/phpunit.xml.dist
- ./vendor/bin/phpunit

notifications:
irc: "irc.freenode.org#zftalk.2"
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

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

## 2.0.0 - TBD

### Added

- [#27](https://github.com/zendframework/ZendService_Google_Gcm/pull/27) PSR-4 schema
- [#27](https://github.com/zendframework/ZendService_Google_Gcm/pull/27) PHP >= 5.5 & 7
- [#20](https://github.com/zendframework/ZendService_Google_Gcm/pull/25) Notification and priority parameters for FCM

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- [#27](https://github.com/zendframework/ZendService_Google_Gcm/pull/27) Fix travis CI integration
- [#27](https://github.com/zendframework/ZendService_Google_Gcm/pull/27) Fix coding style (use ::class and short arrays)
- [#27](https://github.com/zendframework/ZendService_Google_Gcm/pull/27) Fix docblocks for IDE integration
- [#20](https://github.com/zendframework/ZendService_Google_Gcm/pull/25) Change endpoint to FCM

## 1.0.4 - TBD

### Added
Expand Down
Empty file modified LICENSE.txt
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion README.md
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ZendService\Google\Gcm [![Build Status](https://travis-ci.org/zendframework/ZendService_Google_Gcm.png?branch=master.png?branch=master)](https://travis-ci.org/zendframework/ZendService_Google_Gcm)
ZendService\Google\Gcm [![Build Status](https://api.travis-ci.org/zendframework/ZendService_Google_Gcm.svg?branch=develop)](https://travis-ci.org/zendframework/ZendService_Google_Gcm)
================================

Provides support for Google push notifications.
Expand Down
24 changes: 11 additions & 13 deletions composer.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,24 @@
"notification",
"google"
],
"homepage": "http://packages.zendframework.com/",
"homepage": "https://github.com/zendframework/zendservice-google-gcm",
"license": "BSD-3-Clause",
"autoload": {
"psr-0": {
"ZendService\\Google\\Gcm\\": "library/",
"ZendService\\Google\\Exception\\": "library/"
"psr-4": {
"ZendService\\Google\\": "library/"
}
},
"repositories": [
{
"type": "composer",
"url": "http://packages.zendframework.com/"
"autoload-dev": {
"psr-4": {
"ZendServiceTest\\Google\\": "tests/"
}
],
},
"require": {
"php": ">=5.3.3",
"zendframework/zend-http": ">=2.0.0",
"zendframework/zend-json": ">=2.0.0"
"php": "^5.5 || ^7.0",
"zendframework/zend-http": "^2.0",
"zendframework/zend-json": "^2.0"
},
"require-dev": {
"phpunit/PHPUnit": "3.7.*"
"phpunit/PHPUnit": "^4.8"
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
* Zend Framework (http://framework.zend.com/).
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
*
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*
* @category ZendService
* @package ZendService_Google
*/

namespace ZendService\Google\Exception;

/**
* Invalid Argument Exception
* Invalid Argument Exception.
*
* @category ZendService
* @package ZendService_Google
*/
class InvalidArgumentException extends \InvalidArgumentException
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
* Zend Framework (http://framework.zend.com/).
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
*
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*
* @category ZendService
* @package ZendService_Google
*/

namespace ZendService\Google\Exception;

/**
* Runtime Exception
* Runtime Exception.
*
* @category ZendService
* @package ZendService_Google
*/
class RuntimeException extends \RuntimeException
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
* Zend Framework (http://framework.zend.com/).
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
*
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*
* @category ZendService
* @package ZendService_Google\Gcm
*/

namespace ZendService\Google\Gcm;

use ZendService\Google\Exception;
Expand All @@ -21,18 +21,16 @@
* through the Google Cloud Messaging API.
*
* @category ZendService
* @package ZendService_Google
* @subpackage Gcm
*/
class Client
{
/**
* @const string Server URI
*/
const SERVER_URI = 'https://gcm-http.googleapis.com/gcm/send';
const SERVER_URI = 'https://fcm.googleapis.com/fcm/send';

/**
* @var Zend\Http\Client
* @var \Zend\Http\Client
*/
protected $httpClient;

Expand All @@ -42,7 +40,7 @@ class Client
protected $apiKey;

/**
* Get API Key
* Get API Key.
*
* @return string
*/
Expand All @@ -52,60 +50,76 @@ public function getApiKey()
}

/**
* Set API Key
* Set API Key.
*
* @param string $apiKey
*
* @return Client
* @throws InvalidArgumentException
*
* @throws Exception\InvalidArgumentException
*/
public function setApiKey($apiKey)
{
if (!is_string($apiKey) || empty($apiKey)) {
throw new Exception\InvalidArgumentException('The api key must be a string and not empty');
}
$this->apiKey = $apiKey;

return $this;
}

/**
* Get HTTP Client
* Get HTTP Client.
*
* @return Zend\Http\Client
* @throws \Zend\Http\Client\Exception\InvalidArgumentException
*
* @return \Zend\Http\Client
*/
public function getHttpClient()
{
if (!$this->httpClient) {
$this->httpClient = new HttpClient();
$this->httpClient->setOptions(array('strictredirects' => true));
$this->httpClient->setOptions(['strictredirects' => true]);
}

return $this->httpClient;
}

/**
* Set HTTP Client
* Set HTTP Client.
*
* @param \Zend\Http\Client
*
* @param Zend\Http\Client
* @return Client
*/
public function setHttpClient(HttpClient $http)
{
$this->httpClient = $http;

return $this;
}

/**
* Send Message
* Send Message.
*
* @param Message $message
*
* @throws \Zend\Json\Exception\RuntimeException
* @throws \ZendService\Google\Exception\RuntimeException
* @throws \Zend\Http\Exception\RuntimeException
* @throws \Zend\Http\Client\Exception\RuntimeException
* @throws \Zend\Http\Exception\InvalidArgumentException
* @throws \Zend\Http\Client\Exception\InvalidArgumentException
* @throws \ZendService\Google\Exception\InvalidArgumentException
*
* @param Mesage $message
* @return Response
* @throws Exception\RuntimeException
*/
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());

$response = $client->setHeaders($headers)
->setMethod('POST')
Expand All @@ -120,7 +134,7 @@ public function send(Message $message)
case 503:
$exceptionMessage = '503 Server Unavailable';
if ($retry = $response->getHeaders()->get('Retry-After')) {
$exceptionMessage .= '; Retry After: ' . $retry;
$exceptionMessage .= '; Retry After: '.$retry;
}
throw new Exception\RuntimeException($exceptionMessage);
break;
Expand Down
Loading

0 comments on commit f5a0c72

Please sign in to comment.