Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
icetee committed Feb 1, 2020
2 parents 00c55b0 + d51d3ef commit 7938ce6
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 222 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
composer.lock
composer.phar
vendor/
.phpunit.result.cache
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":3544:{a:2:{s:7:"defects";a:10:{s:68:"WebmonkeyTest\Google\Gcm\ClientTest::testGetHttpClientReturnsDefault";i:4;s:72:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedRegistrationIdBehavior";i:6;s:69:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedCollapseKeyBehavior";i:6;s:62:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedDataBehavior";i:6;s:70:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedNotificationBehavior";i:6;s:72:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedDelayWhileIdleBehavior";i:6;s:68:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedTimeToLiveBehavior";i:6;s:75:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedRestrictedPackageBehavior";i:6;s:64:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedDryRunBehavior";i:6;s:82:"WebmonkeyTest\Google\Gcm\ResponseTest::testInvalidConstructorThrowsExceptionOnPhp7";i:1;}s:5:"times";a:32:{s:76:"WebmonkeyTest\Google\Gcm\ClientTest::testSetApiKeyThrowsExceptionOnNonString";d:0.005;s:50:"WebmonkeyTest\Google\Gcm\ClientTest::testSetApiKey";d:0;s:68:"WebmonkeyTest\Google\Gcm\ClientTest::testGetHttpClientReturnsDefault";d:0;s:54:"WebmonkeyTest\Google\Gcm\ClientTest::testSetHttpClient";d:0;s:82:"WebmonkeyTest\Google\Gcm\ClientTest::testSendThrowsExceptionWhenServiceUnavailable";d:0.005;s:81:"WebmonkeyTest\Google\Gcm\ClientTest::testSendThrowsExceptionWhenServerUnavailable";d:0.001;s:80:"WebmonkeyTest\Google\Gcm\ClientTest::testSendThrowsExceptionWhenInvalidAuthToken";d:0.001;s:78:"WebmonkeyTest\Google\Gcm\ClientTest::testSendThrowsExceptionWhenInvalidPayload";d:0.001;s:72:"WebmonkeyTest\Google\Gcm\ClientTest::testSendResultInvalidRegistrationId";d:0.001;s:67:"WebmonkeyTest\Google\Gcm\ClientTest::testSendResultMismatchSenderId";d:0.001;s:64:"WebmonkeyTest\Google\Gcm\ClientTest::testSendResultNotRegistered";d:0.001;s:64:"WebmonkeyTest\Google\Gcm\ClientTest::testSendResultMessageTooBig";d:0.001;s:61:"WebmonkeyTest\Google\Gcm\ClientTest::testSendResultSuccessful";d:0.001;s:79:"WebmonkeyTest\Google\Gcm\ClientTest::testSendResultSuccessfulWithRegistrationId";d:0.001;s:72:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedRegistrationIdBehavior";d:0;s:78:"WebmonkeyTest\Google\Gcm\MessageTest::testInvalidRegistrationIdThrowsException";d:0;s:69:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedCollapseKeyBehavior";d:0;s:75:"WebmonkeyTest\Google\Gcm\MessageTest::testInvalidCollapseKeyThrowsException";d:0;s:62:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedDataBehavior";d:0;s:70:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedNotificationBehavior";d:0;s:68:"WebmonkeyTest\Google\Gcm\MessageTest::testInvalidDataThrowsException";d:0;s:73:"WebmonkeyTest\Google\Gcm\MessageTest::testDuplicateDataKeyThrowsException";d:0;s:72:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedDelayWhileIdleBehavior";d:0;s:68:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedTimeToLiveBehavior";d:0;s:75:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedRestrictedPackageBehavior";d:0;s:81:"WebmonkeyTest\Google\Gcm\MessageTest::testInvalidRestrictedPackageThrowsException";d:0;s:64:"WebmonkeyTest\Google\Gcm\MessageTest::testExpectedDryRunBehavior";d:0;s:70:"WebmonkeyTest\Google\Gcm\ResponseTest::testConstructorExpectedBehavior";d:0;s:76:"WebmonkeyTest\Google\Gcm\ResponseTest::testInvalidConstructorThrowsException";d:0;s:82:"WebmonkeyTest\Google\Gcm\ResponseTest::testInvalidConstructorThrowsExceptionOnPhp7";d:0;s:66:"WebmonkeyTest\Google\Gcm\ResponseTest::testMessageExpectedBehavior";d:0;s:51:"WebmonkeyTest\Google\Gcm\ResponseTest::testResponse";d:0;}}}
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ language: php

matrix:
include:
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.4
env:
- CS_CHECK=true
- php: 7.2
- php: 7.3
- php: 7.4

before_install:
- composer install --no-interaction
Expand Down
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

## 2.1.2 - TBD
## 3.0.1 - TBD

### Added

Expand All @@ -24,6 +24,29 @@ All notable changes to this project will be documented in this file, in reverse

- Nothing.

## 3.0.0 - 2020-02-01

### Added

- Nothing.

### Changed

- Drop Support 7.4 previous versions
- Change `array_key_exists` to `isset`

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.

## 2.1.1 - 2019-02-07

### Added
Expand Down
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Copyright (c) 2005-2018, Zend Technologies USA, Inc.
All rights reserved.
Copyright (c) 2005-2018, Zend Technologies USA, Inc. of Creator
Copyright (c) 2020, Webmonkey Solutions Kft of Maintainer

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Expand Down
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
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)
Webmonkey\Google\Gcm [![Build Status](https://api.travis-ci.org/webmonkeyhu/Google_Gcm.svg?branch=develop)](https://travis-ci.org/webmonkeyhu/Google_Gcm)
================================

> ## Repository abandoned 2019-12-05
>
> This repository is no longer maintained.
Provides support for Google push notifications.

## Requirements

* PHP >= 5.6
* PHP >= 7.4

## Getting Started

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

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

## Documentation

The documentation can be found at: http://framework.zend.com/manual/current/en/modules/zendservice.google.gcm.html
The documentation can be found at: [Docs](docs/documentation.md)
33 changes: 15 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,45 @@
{
"name": "zendframework/zendservice-google-gcm",
"description": "OOP wrapper for Google Cloud Messaging",
"name": "webmonkeyhu/google-gcm",
"description": "OOP Laminas wrapper for Google Cloud Messaging",
"license": "BSD-3-Clause",
"keywords": [
"zf",
"zendframework",
"webmonkey",
"laminas",
"gcm",
"push",
"notification",
"google"
],
"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"
"issues": "https://github.com/webmonkeyhu/Google_Gcm/issues",
"source": "https://github.com/webmonkeyhu/Google_Gcm"
},
"require": {
"php": "^5.6 || ^7.0",
"zendframework/zend-http": "^2.0",
"zendframework/zend-json": "^2.0 || ^3.0"
"php": "^7.4",
"laminas/laminas-http": "^2.11.2",
"laminas/laminas-json": "^3.1.2"
},
"require-dev": {
"phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.5",
"zendframework/zend-coding-standard": "~1.0.0"
"laminas/laminas-coding-standard": "^1.0",
"phpunit/phpunit": "^8.5"
},
"autoload": {
"psr-4": {
"ZendService\\Google\\": "src/"
"Webmonkey\\Google\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ZendServiceTest\\Google\\": "test/"
"WebmonkeyTest\\Google\\": "test/"
}
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev",
"dev-develop": "2.2.x-dev"
"dev-master": "3.0.x-dev",
"dev-develop": "3.1.x-dev"
}
}
}
62 changes: 62 additions & 0 deletions docs/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# GoogleGcm

## Introduction
`Webmonkey\Google\Gcm` provides a client for the Google Cloud Messaging (GCM) API. `Webmonkey\Google\Gcm\Client` allows you to send data from servers to your Android Applications on Android devices (Google API driven).

In order to leverage GCM you must create your project in the Google API Console and enable the GCM service on your device. To get started with GCM prior to building out the 3rd-party server please see [GCM: Getting Started](http://developer.android.com/guide/google/gcm/gs.html)

The service is composed of 3 distinct parts:

- The Client: `Webmonkey\Google\Gcm\Client`
- The Message: `Webmonkey\Google\Gcm\Message`
- The Response: `Webmonkey\Google\Gcm\Response`

The Client is the broker that sends the message to the GCM server and returns the response. The Message is where you define all of the message specific data that you would like to send. The response is the feedback given back from the GCM server on success, failures and any new canonical id’s that must be updated.

## Quick Start
In order to send messages; you must have your API key ready and available. Here we will setup the client and prepare ourselves to send out messages.

```
use Webmonkey\Google\Gcm\Client;
use Webmonkey\Google\Gcm\Message;
use Webmonkey\Google\Exception\RuntimeException;
$client = new Client();
$client->setApiKey('the-api-key-for-gcm');
```

So now that we have the client setup and available, it is time to define out the message that we intend to send to our registration id’s that have registered for push notifications on our server. Note that many of the methods specified are not required but are here to give an inclusive look into the message.

```
$message = new Message();
// up to 100 registration ids can be sent to at once
$message->setRegistrationIds(array(
'1-an-id-from-gcm',
'2-an-id-from-gcm',
));
// optional fields
$message->setData(array(
'pull-request' => '1',
));
$message->setCollapseKey('pull-request');
$message->setRestrictedPackageName('com.zf.manual');
$message->setDelayWhileIdle(false);
$message->setTimeToLive(600);
$message->setDryRun(false);
```

Now that we have the message taken care of, all we need to do next is send out the message. Each message comes back with a set of data that allows us to understand what happened with our push notification as well as throwing exceptions in the cases of server failures.

```
try {
$response = $client->send($message);
} catch (RuntimeException $e) {
echo $e->getMessage() . PHP_EOL;
exit(1);
}
echo 'Successful: ' . $response->getSuccessCount() . PHP_EOL;
echo 'Failures: ' . $response->getFailureCount() . PHP_EOL;
echo 'Canonicals: ' . $response->getCanonicalCount() . PHP_EOL;
```
4 changes: 2 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<ruleset name="Zend Framework Coding Standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>
<ruleset name="Laminas Coding Standard">
<rule ref="./vendor/laminas/laminas-coding-standard/ruleset.xml"/>

<file>src</file>
<file>test</file>
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="ZendService Google Gcm Test Suite">
<testsuite name="Webmonkey Google Gcm Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
Expand Down
17 changes: 5 additions & 12 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
<?php
/**
* 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
*/
namespace ZendService\Google\Exception;

declare(strict_types=1);

namespace Webmonkey\Google\Exception;

/**
* Invalid Argument Exception.
*
* @category ZendService
* @category Webmonkey
*/
class InvalidArgumentException extends \InvalidArgumentException
{
Expand Down
17 changes: 5 additions & 12 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
<?php
/**
* 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
*/
namespace ZendService\Google\Exception;

declare(strict_types=1);

namespace Webmonkey\Google\Exception;

/**
* Runtime Exception.
*
* @category ZendService
* @category Webmonkey
*/
class RuntimeException extends \RuntimeException
{
Expand Down
45 changes: 18 additions & 27 deletions src/Gcm/Client.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
<?php
/**
* 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
*/
namespace ZendService\Google\Gcm;

use ZendService\Google\Exception;
use Zend\Http\Client as HttpClient;
use Zend\Json\Json;
declare(strict_types=1);

namespace Webmonkey\Google\Gcm;

use Webmonkey\Google\Exception;
use Laminas\Http\Client as HttpClient;
use Laminas\Json\Json;

/**
* Google Cloud Messaging Client
* This class allows the ability to send out messages
* through the Google Cloud Messaging API.
*
* @category ZendService
*/
class Client
{
Expand All @@ -30,7 +21,7 @@ class Client
const SERVER_URI = 'https://fcm.googleapis.com/fcm/send';

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

Expand Down Expand Up @@ -71,9 +62,9 @@ public function setApiKey($apiKey)
/**
* Get HTTP Client.
*
* @throws \Zend\Http\Client\Exception\InvalidArgumentException
* @throws \Laminas\Http\Client\Exception\InvalidArgumentException
*
* @return \Zend\Http\Client
* @return \Laminas\Http\Client
*/
public function getHttpClient()
{
Expand All @@ -88,7 +79,7 @@ public function getHttpClient()
/**
* Set HTTP Client.
*
* @param \Zend\Http\Client
* @param \Laminas\Http\Client
*
* @return Client
*/
Expand All @@ -104,13 +95,13 @@ public function setHttpClient(HttpClient $http)
*
* @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
* @throws \Laminas\Json\Exception\RuntimeException
* @throws \Webmonkey\Google\Exception\RuntimeException
* @throws \Laminas\Http\Exception\RuntimeException
* @throws \Laminas\Http\Client\Exception\RuntimeException
* @throws \Laminas\Http\Exception\InvalidArgumentException
* @throws \Laminas\Http\Client\Exception\InvalidArgumentException
* @throws \Webmonkey\Google\Exception\InvalidArgumentException
*
* @return Response
*/
Expand Down
Loading

0 comments on commit 7938ce6

Please sign in to comment.