Skip to content

Commit

Permalink
GCM to FCM migration (#100)
Browse files Browse the repository at this point in the history
* GCM to FCM migration

* Add checking if using GCM throws E_DEPRECATION_WARNING

* Improve readability and fix error messages

* PubNub SDK v6.2.0 release.

---------

Co-authored-by: PubNub Release Bot <[email protected]>
  • Loading branch information
seba-aln and pubnub-release-bot authored Jun 11, 2024
1 parent cd1f426 commit 20de5d8
Show file tree
Hide file tree
Showing 21 changed files with 362 additions and 594 deletions.
11 changes: 8 additions & 3 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: php
version: 6.1.3
version: 6.2.0
schema: 1
scm: github.com/pubnub/php
changelog:
- date: 2024-06-11
version: v6.2.0
changes:
- type: feature
text: "Replacing GCM with FCM. This is not a breaking change, but using GCM will result in throwing `E_USER_DEPRECATED` warning."
- date: 2023-11-27
version: v6.1.3
changes:
Expand Down Expand Up @@ -407,8 +412,8 @@ sdks:
- x86-64
- distribution-type: library
distribution-repository: GitHub release
package-name: php-6.1.3.zip
location: https://github.com/pubnub/php/releases/tag/v6.1.3
package-name: php-6.2.0.zip
location: https://github.com/pubnub/php/releases/tag/v6.2.0
requires:
- name: rmccue/requests
min-version: 1.0.0
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v6.2.0
June 11 2024

#### Added
- Replacing GCM with FCM. This is not a breaking change, but using GCM will result in throwing `E_USER_DEPRECATED` warning.

## v6.1.3
November 27 2023

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your
{
"require": {
<!-- include the latest version from the badge at the top -->
"pubnub/pubnub": "6.1.3"
"pubnub/pubnub": "6.2.0"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": ["api", "real-time", "realtime", "real time", "ajax", "push"],
"homepage": "http://www.pubnub.com/",
"license": "proprietary",
"version": "6.1.3",
"version": "6.2.0",
"authors": [
{
"name": "PubNub",
Expand Down
136 changes: 9 additions & 127 deletions src/PubNub/Endpoints/Push/AddChannelsToPush.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,110 +2,40 @@

namespace PubNub\Endpoints\Push;

use PubNub\Endpoints\Endpoint;
use PubNub\Enums\PNHttpMethod;
use PubNub\Enums\PNOperationType;
use PubNub\Enums\PNPushType;
use PubNub\Exceptions\PubNubValidationException;
use PubNub\Models\Consumer\Push\PNPushAddChannelResult;
use PubNub\PubNubUtil;


class AddChannelsToPush extends Endpoint
class AddChannelsToPush extends PushEndpoint
{
const PATH = "/v1/push/sub-key/%s/devices/%s";

const PATH_APNS2 = "/v2/push/sub-key/%s/devices-apns2/%s";
protected const OPERATION_TYPE = PNOperationType::PNAddPushNotificationsOnChannelsOperation;
protected const OPERATION_NAME = "AddChannelsToPush";
public const PATH = "/v1/push/sub-key/%s/devices/%s";
public const PATH_APNS2 = "/v2/push/sub-key/%s/devices-apns2/%s";

/** @var string[]|string */
protected $channels = [];

/** @var string */
protected $deviceId;

/** @var int */
protected $pushType;

/** @var string */
protected $environment;

/** @var string */
protected $topic;
protected string | array $channels = [];

/**
* @param string[]|string $channels
* @return $this
*/
public function channels($channels)
public function channels(string | array $channels)
{
$this->channels = PubNubUtil::extendArray($this->channels, $channels);

return $this;
}

/**
* @param string $deviceId
* @return $this
*/
public function deviceId($deviceId)
{
$this->deviceId = $deviceId;

return $this;
}

/**
* @param int $pushType
* @return $this
*/
public function pushType($pushType)
{
$this->pushType = $pushType;

return $this;
}

/**
* @param int $environment
* @return $this
*/
public function environment($environment)
{
$this->environment = $environment;

return $this;
}

/**
* @param int $pushType
* @return $this
*/
public function topic($topic)
{
$this->topic = $topic;

return $this;
}

protected function validateParams()
{
$this->validateSubscribeKey();
parent::validateParams();

if (!is_array($this->channels) || count($this->channels) === 0) {
throw new PubNubValidationException("Channel missing");
}

if (!is_string($this->deviceId) || strlen($this->deviceId) === 0) {
throw new PubNubValidationException("Device ID is missing for push operation");
}

if ($this->pushType === null || strlen($this->pushType) === 0) {
throw new PubNubValidationException("Push Type is missing");
}

if (($this->pushType == PNPushType::APNS2) && (!is_string($this->topic) || strlen($this->topic) === 0)) {
throw new PubNubValidationException("APNS2 topic is missing");
}
}

/**
Expand Down Expand Up @@ -164,52 +94,4 @@ protected function createResponse($json)
{
return new PNPushAddChannelResult();
}

/**
* @return bool
*/
protected function isAuthRequired()
{
return true;
}

/**
* @return int
*/
protected function getRequestTimeout()
{
return $this->pubnub->getConfiguration()->getNonSubscribeRequestTimeout();
}

/**
* @return int
*/
protected function getConnectTimeout()
{
return $this->pubnub->getConfiguration()->getConnectTimeout();
}

/**
* @return string PNHttpMethod
*/
protected function httpMethod()
{
return PNHttpMethod::GET;
}

/**
* @return int
*/
protected function getOperationType()
{
return PNOperationType::PNAddPushNotificationsOnChannelsOperation;
}

/**
* @return string
*/
protected function getName()
{
return "AddChannelsToPush";
}
}
}
137 changes: 6 additions & 131 deletions src/PubNub/Endpoints/Push/ListPushProvisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,18 @@

namespace PubNub\Endpoints\Push;

use PubNub\Endpoints\Endpoint;
use PubNub\Enums\PNHttpMethod;
use PubNub\Enums\PNOperationType;
use PubNub\Enums\PNPushType;
use PubNub\Exceptions\PubNubValidationException;
use PubNub\Models\Consumer\Push\PNPushListProvisionsResult;


class ListPushProvisions extends Endpoint
class ListPushProvisions extends PushEndpoint
{
const PATH = "/v1/push/sub-key/%s/devices/%s";

const PATH_APNS2 = "/v2/push/sub-key/%s/devices-apns2/%s";

/** @var string */
protected $deviceId;

/** @var int */
protected $pushType;

/** @var string */
protected $environment;

/** @var string */
protected $topic;

/**
* @param string $deviceId
* @return $this
*/
public function deviceId($deviceId)
{
$this->deviceId = $deviceId;

return $this;
}

/**
* @param int $pushType
* @return $this
*/
public function pushType($pushType)
{
$this->pushType = $pushType;

return $this;
}

/**
* @param int $environment
* @return $this
*/
public function environment($environment)
{
$this->environment = $environment;

return $this;
}

/**
* @param int $pushType
* @return $this
*/
public function topic($topic)
{
$this->topic = $topic;

return $this;
}

/**
* @throws PubNubValidationException
*/
protected function validateParams()
{
$this->validateSubscribeKey();

if (!is_string($this->deviceId) || strlen($this->deviceId) === 0) {
throw new PubNubValidationException("Device ID is missing for push operation");
}

if ($this->pushType === null || strlen($this->pushType) === 0) {
throw new PubNubValidationException("Push Type is missing");
}

if (($this->pushType == PNPushType::APNS2) && (!is_string($this->topic) || strlen($this->topic) === 0)) {
throw new PubNubValidationException("APNS2 topic is missing");
}
}
protected const OPERATION_TYPE = PNOperationType::PNPushNotificationEnabledChannelsOperation;
protected const OPERATION_NAME = "ListPushProvisions";
public const PATH = "/v1/push/sub-key/%s/devices/%s";
public const PATH_APNS2 = "/v2/push/sub-key/%s/devices-apns2/%s";

/**
* @return array
Expand Down Expand Up @@ -150,52 +73,4 @@ protected function createResponse($json)
return new PNPushListProvisionsResult([]);
}
}

/**
* @return bool
*/
protected function isAuthRequired()
{
return true;
}

/**
* @return int
*/
protected function getRequestTimeout()
{
return $this->pubnub->getConfiguration()->getNonSubscribeRequestTimeout();
}

/**
* @return int
*/
protected function getConnectTimeout()
{
return $this->pubnub->getConfiguration()->getConnectTimeout();
}

/**
* @return string PNHttpMethod
*/
protected function httpMethod()
{
return PNHttpMethod::GET;
}

/**
* @return int
*/
protected function getOperationType()
{
return PNOperationType::PNPushNotificationEnabledChannelsOperation;
}

/**
* @return string
*/
protected function getName()
{
return "ListPushProvisions";
}
}
}
Loading

0 comments on commit 20de5d8

Please sign in to comment.