-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for message reactions (#111)
* Add support for message reactions * Fixes for phpstan and phpcs * Add setup and teardown for tests * Correct keys validation expression * PubNub SDK 7.2.0 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
- Loading branch information
1 parent
9c0e653
commit d39a925
Showing
16 changed files
with
711 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
src/PubNub/Endpoints/MessageActions/AddMessageAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<?php | ||
|
||
namespace PubNub\Endpoints\MessageActions; | ||
|
||
use PubNub\PubNub; | ||
use PubNub\Endpoints\Endpoint; | ||
use PubNub\Enums\PNHttpMethod; | ||
use PubNub\Enums\PNOperationType; | ||
use PubNub\Exceptions\PubNubValidationException; | ||
use PubNub\Exceptions\PubNubBuildRequestException; | ||
use PubNub\Models\Consumer\MessageActions\PNMessageAction; | ||
use PubNub\Models\Consumer\MessageActions\PNAddMessageActionResult; | ||
use PubNub\PubNubUtil; | ||
|
||
class AddMessageAction extends Endpoint | ||
{ | ||
protected bool $endpointAuthRequired = true; | ||
protected int $endpointConnectTimeout; | ||
protected int $endpointRequestTimeout; | ||
protected string $endpointHttpMethod = PNHttpMethod::POST; | ||
protected int $endpointOperationType = PNOperationType::PNAddMessageActionOperation; | ||
protected string $endpointName = "Set Message Actions"; | ||
|
||
protected const POST_PATH = "/v1/message-actions/%s/channel/%s/message/%s"; | ||
protected string $channel; | ||
protected PNMessageAction $messageAction; | ||
|
||
public function __construct(PubNub $pubnub) | ||
{ | ||
parent::__construct($pubnub); | ||
$this->endpointConnectTimeout = $this->pubnub->getConfiguration()->getConnectTimeout(); | ||
$this->endpointRequestTimeout = $this->pubnub->getConfiguration()->getNonSubscribeRequestTimeout(); | ||
} | ||
|
||
/** | ||
* Set a channel for the message action | ||
* | ||
* @param string $channel | ||
* @return AddMessageAction | ||
*/ | ||
public function channel(string $channel): self | ||
{ | ||
$this->channel = $channel; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Set the message action with instance of PNMessageAction | ||
* | ||
* @param PNMessageAction $messageAction | ||
* @return AddMessageAction | ||
*/ | ||
public function messageAction(PNMessageAction $messageAction): self | ||
{ | ||
$this->messageAction = $messageAction; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @throws PubNubValidationException | ||
*/ | ||
protected function validateParams(): void | ||
{ | ||
if (!$this->channel) { | ||
throw new PubNubValidationException("Channel Missing"); | ||
} | ||
$this->validateMessageAction(); | ||
$this->validateSubscribeKey(); | ||
$this->validatePublishKey(); | ||
} | ||
|
||
/** | ||
* @throws PubNubValidationException | ||
*/ | ||
protected function validateMessageAction(): void | ||
{ | ||
if (!isset($this->messageAction)) { | ||
throw new PubNubValidationException("Message Action Missing"); | ||
} | ||
if (!isset($this->messageAction->type)) { | ||
throw new PubNubValidationException("Message Action Type Missing"); | ||
} | ||
if (!isset($this->messageAction->value)) { | ||
throw new PubNubValidationException("Message Action Value Missing"); | ||
} | ||
if (!$this->messageAction->messageTimetoken) { | ||
throw new PubNubValidationException("Message Action Message Timetoken Missing"); | ||
} | ||
} | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
protected function customParams() | ||
{ | ||
return [ | ||
'uuid' => $this->pubnub->getConfiguration()->getUuid() | ||
]; | ||
} | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
protected function customHeaders() | ||
{ | ||
return [ | ||
'Content-Type' => 'application/json', | ||
'Accept' => 'application/json' | ||
]; | ||
} | ||
|
||
/** | ||
* @return string | null | ||
*/ | ||
protected function buildData() | ||
{ | ||
return PubNubUtil::writeValueAsString([ | ||
'type' => $this->messageAction->type, | ||
'value' => $this->messageAction->value, | ||
]); | ||
} | ||
|
||
/** | ||
* @return string | ||
* @throws PubNubBuildRequestException | ||
*/ | ||
protected function buildPath() | ||
{ | ||
return sprintf( | ||
self::POST_PATH, | ||
$this->pubnub->getConfiguration()->getSubscribeKey(), | ||
$this->channel, | ||
(int)$this->messageAction->messageTimetoken | ||
); | ||
} | ||
|
||
/** | ||
* @return PNAddMessageActionResult | ||
*/ | ||
public function sync(): PNAddMessageActionResult | ||
{ | ||
return parent::sync(); | ||
} | ||
|
||
/** | ||
* @param array<string, string> $json Decoded json | ||
* @return PNAddMessageActionResult | ||
*/ | ||
protected function createResponse($json): PNAddMessageActionResult | ||
{ | ||
return PNAddMessageActionResult::fromJson($json); | ||
} | ||
} |
Oops, something went wrong.