From ea00ed5af4a5fa2e34e259338ed4764b39927df2 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Tue, 11 Jun 2024 15:41:03 +0200 Subject: [PATCH] FCM sends GCM as a type parameter --- src/PubNub/Endpoints/Push/AddChannelsToPush.php | 3 +-- src/PubNub/Endpoints/Push/ListPushProvisions.php | 4 +--- src/PubNub/Endpoints/Push/PushEndpoint.php | 5 +++++ src/PubNub/Endpoints/Push/RemoveChannelsFromPush.php | 3 +-- src/PubNub/Endpoints/Push/RemoveDeviceFromPush.php | 4 +--- tests/integrational/push/AddChannelsToPushEndpointTest.php | 2 +- tests/integrational/push/ListPushProvisionsEndpointTest.php | 2 +- .../push/RemoveChannelsFromPushEndpointTest.php | 2 +- .../integrational/push/RemoveDeviceFromPushEndpointTest.php | 2 +- 9 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/PubNub/Endpoints/Push/AddChannelsToPush.php b/src/PubNub/Endpoints/Push/AddChannelsToPush.php index de62a564..aac20698 100644 --- a/src/PubNub/Endpoints/Push/AddChannelsToPush.php +++ b/src/PubNub/Endpoints/Push/AddChannelsToPush.php @@ -48,8 +48,7 @@ protected function customParams() ]; if ($this->pushType != PNPushType::APNS2) { - // v1 push -> add type - $params['type'] = $this->pushType; + $params['type'] = $this->getPushType(); } else { // apns2 push -> add topic and environment $params['topic'] = $this->topic; diff --git a/src/PubNub/Endpoints/Push/ListPushProvisions.php b/src/PubNub/Endpoints/Push/ListPushProvisions.php index 33a7209e..0c2cad8f 100644 --- a/src/PubNub/Endpoints/Push/ListPushProvisions.php +++ b/src/PubNub/Endpoints/Push/ListPushProvisions.php @@ -5,7 +5,6 @@ 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 PushEndpoint @@ -23,8 +22,7 @@ protected function customParams() $params = []; if ($this->pushType != PNPushType::APNS2) { - // v1 push -> add type - $params['type'] = $this->pushType; + $params['type'] = $this->getPushType(); } else { // apns2 push -> add topic and environment $params['topic'] = $this->topic; diff --git a/src/PubNub/Endpoints/Push/PushEndpoint.php b/src/PubNub/Endpoints/Push/PushEndpoint.php index 44aa85cf..767e4e31 100644 --- a/src/PubNub/Endpoints/Push/PushEndpoint.php +++ b/src/PubNub/Endpoints/Push/PushEndpoint.php @@ -146,4 +146,9 @@ protected function getName() { return static::OPERATION_NAME; } + + protected function getPushType(): string + { + return $this->pushType == PNPushType::FCM ? 'gcm' : $this->pushType; + } } diff --git a/src/PubNub/Endpoints/Push/RemoveChannelsFromPush.php b/src/PubNub/Endpoints/Push/RemoveChannelsFromPush.php index 0a793592..90646c44 100644 --- a/src/PubNub/Endpoints/Push/RemoveChannelsFromPush.php +++ b/src/PubNub/Endpoints/Push/RemoveChannelsFromPush.php @@ -57,8 +57,7 @@ protected function customParams() ]; if ($this->pushType != PNPushType::APNS2) { - // v1 push -> add type - $params['type'] = $this->pushType; + $params['type'] = $this->getPushType(); } else { // apns2 push -> add topic and environment $params['topic'] = $this->topic; diff --git a/src/PubNub/Endpoints/Push/RemoveDeviceFromPush.php b/src/PubNub/Endpoints/Push/RemoveDeviceFromPush.php index 1d841f52..90ff0978 100644 --- a/src/PubNub/Endpoints/Push/RemoveDeviceFromPush.php +++ b/src/PubNub/Endpoints/Push/RemoveDeviceFromPush.php @@ -6,7 +6,6 @@ use PubNub\Enums\PNHttpMethod; use PubNub\Enums\PNOperationType; use PubNub\Enums\PNPushType; -use PubNub\Exceptions\PubNubValidationException; use PubNub\Models\Consumer\Push\PNPushRemoveAllChannelsResult; class RemoveDeviceFromPush extends PushEndpoint @@ -24,8 +23,7 @@ protected function customParams() $params = []; if ($this->pushType != PNPushType::APNS2) { - // v1 push -> add type - $params['type'] = $this->pushType; + $params['type'] = $this->getPushType(); } else { // apns2 push -> add topic and environment $params['topic'] = $this->topic; diff --git a/tests/integrational/push/AddChannelsToPushEndpointTest.php b/tests/integrational/push/AddChannelsToPushEndpointTest.php index 78fd16b1..4c0a24bb 100644 --- a/tests/integrational/push/AddChannelsToPushEndpointTest.php +++ b/tests/integrational/push/AddChannelsToPushEndpointTest.php @@ -92,7 +92,7 @@ public function testPushAddFCM() ->withQuery([ "pnsdk" => $this->encodedSdkName, "add" => "ch1,ch2,ch3", - "type" => "fcm", + "type" => "gcm", "uuid" => "sampleUUID", ]) ->setResponseBody('[1, "Modified Channels"]'); diff --git a/tests/integrational/push/ListPushProvisionsEndpointTest.php b/tests/integrational/push/ListPushProvisionsEndpointTest.php index 8b1977cc..8a750da9 100644 --- a/tests/integrational/push/ListPushProvisionsEndpointTest.php +++ b/tests/integrational/push/ListPushProvisionsEndpointTest.php @@ -64,7 +64,7 @@ public function testListChannelGroupFCM() $list->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ "pnsdk" => $this->encodedSdkName, - "type" => "fcm", + "type" => "gcm", "uuid" => "sampleUUID", ]) ->setResponseBody('[1, "Modified Channels"]'); diff --git a/tests/integrational/push/RemoveChannelsFromPushEndpointTest.php b/tests/integrational/push/RemoveChannelsFromPushEndpointTest.php index 698defcd..2bd090e8 100644 --- a/tests/integrational/push/RemoveChannelsFromPushEndpointTest.php +++ b/tests/integrational/push/RemoveChannelsFromPushEndpointTest.php @@ -88,7 +88,7 @@ public function testPushRemoveFCM() $remove->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ "pnsdk" => $this->encodedSdkName, - "type" => "fcm", + "type" => "gcm", "uuid" => "sampleUUID", "remove" => "ch1,ch2,ch3" ]) diff --git a/tests/integrational/push/RemoveDeviceFromPushEndpointTest.php b/tests/integrational/push/RemoveDeviceFromPushEndpointTest.php index 0e94f98f..5d26aa34 100644 --- a/tests/integrational/push/RemoveDeviceFromPushEndpointTest.php +++ b/tests/integrational/push/RemoveDeviceFromPushEndpointTest.php @@ -84,7 +84,7 @@ public function testRemovePushFCM() $remove->stubFor("/v1/push/sub-key/demo/devices/coolDevice/remove") ->withQuery([ "pnsdk" => $this->encodedSdkName, - "type" => "fcm", + "type" => "gcm", "uuid" => "sampleUUID", ]) ->setResponseBody('[1, "Modified Channels"]');