Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strongly typed endpoint output #106

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/PubNub/Endpoints/Access/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
use PubNub\Models\Consumer\AccessManager\PNAccessManagerAuditResult;
use PubNub\PubNubUtil;


class Audit extends Endpoint
{
const PATH = "/v1/auth/audit/sub-key/%s";
protected const PATH = "/v1/auth/audit/sub-key/%s";

/** @var string[] */
protected $authKeys = [];
Expand Down Expand Up @@ -88,7 +87,7 @@ protected function httpMethod()
/**
* @return PNAccessManagerAuditResult

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment need when a type is defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll include it in future PR

*/
public function sync()
public function sync(): PNAccessManagerAuditResult
{
return parent::sync();
}
Expand All @@ -97,7 +96,7 @@ public function sync()
* @param array $result Decoded json
* @return PNAccessManagerAuditResult
*/
protected function createResponse($result)
protected function createResponse($result): PNAccessManagerAuditResult
{
return PNAccessManagerAuditResult::fromJson($result['payload']);
}
Expand Down
21 changes: 11 additions & 10 deletions src/PubNub/Endpoints/Access/Grant.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

use PubNub\Endpoints\Endpoint;
use PubNub\Exceptions\PubNubValidationException;
use PubNub\Models\Consumer\AccessManager\PNAccessManagerGrantResult;
use PubNub\PubNubUtil;
use PubNub\Enums\PNHttpMethod;
use PubNub\Enums\PNOperationType;

use PubNub\Models\Consumer\AccessManager\PNAccessManagerAbstractResult;

class Grant extends Endpoint
{
const PATH = "/v2/auth/grant/sub-key/%s";
protected const PATH = "/v2/auth/grant/sub-key/%s";

/** @var string[] */
protected $authKeys = [];
Expand Down Expand Up @@ -195,7 +194,10 @@ public function validateParams()
$this->validateSubscribeKey();
$this->validateSecretKey();

if ($this->write === null && $this->read === null && $this->manage === null && $this->get === null && $this->update === null && $this->join === null) {
if (
$this->write === null && $this->read === null && $this->manage === null && $this->get === null
&& $this->update === null && $this->join === null
) {
throw new PubNubValidationException("At least one flag should be specified");
}
}
Expand Down Expand Up @@ -277,20 +279,20 @@ public function buildPath()
}

/**
* @return PNAccessManagerGrantResult
* @return PNAccessManagerAbstractResult
*/
public function sync()
public function sync(): PNAccessManagerAbstractResult
{
return parent::sync();
}

/**
* @param array $result
* @return PNAccessManagerGrantResult
* @return PNAccessManagerAbstractResult
*/
public function createResponse($result)
public function createResponse($result): PNAccessManagerAbstractResult
{
return PNAccessManagerGrantResult::fromJson($result['payload']);
return PNAccessManagerAbstractResult::fromJson($result['payload']);
}

/**
Expand Down Expand Up @@ -365,4 +367,3 @@ public function getName()
return "Grant";
}
}

8 changes: 4 additions & 4 deletions src/PubNub/Endpoints/Access/GrantToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class GrantToken extends Endpoint
{
private const PATH = '/v3/pam/%s/grant';
protected const PATH = '/v3/pam/%s/grant';

/** @var int */
protected $ttl;
Expand Down Expand Up @@ -239,16 +239,16 @@ public function buildPath()
/**
* @return PNAccessManagerGrantResult
*/
public function sync()
public function sync(): PNAccessManagerGrantResult
{
return parent::sync();
}

/**
* @param string $token
* @return PNAccessManagerGrantResult
* @return : PNAccessManagerGrantResult
*/
public function createResponse($response)
public function createResponse($response): PNAccessManagerGrantResult
{
return $response['data']['token'];
}
Expand Down
6 changes: 3 additions & 3 deletions src/PubNub/Endpoints/Access/RevokeToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class RevokeToken extends Endpoint
{
const PATH = "/v3/pam/%s/grant/%s";
protected const PATH = "/v3/pam/%s/grant/%s";

protected $token;

Expand Down Expand Up @@ -74,7 +74,7 @@ public function buildPath()
/**
* @return PNRequestResult
*/
public function sync()
public function sync(): PNRequestResult
{
return parent::sync();
}
Expand All @@ -83,7 +83,7 @@ public function sync()
* @param string $token
* @return PNRequestResult
*/
public function createResponse($response)
public function createResponse($response): PNRequestResult
{
return new PNRequestResult(
$response['status'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
use PubNub\Models\Consumer\ChannelGroup\PNChannelGroupsAddChannelResult;
use PubNub\PubNubUtil;


class AddChannelToChannelGroup extends Endpoint
{
const PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s";
protected const PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s";

/** @var string[] */
protected $channels = [];
Expand Down Expand Up @@ -78,11 +77,16 @@ protected function buildPath()
);
}

public function sync(): PNChannelGroupsAddChannelResult
{
return parent::sync();
}

/**
* @param array $result Decoded json
* @return PNChannelGroupsAddChannelResult
*/
protected function createResponse($result)
protected function createResponse($result): PNChannelGroupsAddChannelResult
{
return new PNChannelGroupsAddChannelResult();
}
Expand All @@ -104,7 +108,7 @@ protected function customParams()
*/
protected function isAuthRequired()
{
return True;
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
use PubNub\Exceptions\PubNubValidationException;
use PubNub\Models\Consumer\ChannelGroup\PNChannelGroupsListChannelsResult;


class ListChannelsInChannelGroup extends Endpoint
{
const PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s";
protected const PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s";

/** @var string */
protected $channelGroup;
Expand Down Expand Up @@ -72,7 +71,7 @@ protected function buildPath()
/**
* @return PNChannelGroupsListChannelsResult
*/
public function sync()
public function sync(): PNChannelGroupsListChannelsResult
{
return parent::sync();
}
Expand All @@ -81,7 +80,7 @@ public function sync()
* @param array $result Decoded json
* @return PNChannelGroupsListChannelsResult
*/
protected function createResponse($result)
protected function createResponse($result): PNChannelGroupsListChannelsResult
{
return PNChannelGroupsListChannelsResult::fromPayload(static::fetchPayload($result));
}
Expand All @@ -91,7 +90,7 @@ protected function createResponse($result)
*/
protected function isAuthRequired()
{
return True;
return true;
}

/**
Expand Down Expand Up @@ -133,4 +132,4 @@ protected function getName()
{
return "ListChannelsInChannelGroup";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
use PubNub\Models\Consumer\ChannelGroup\PNChannelGroupsRemoveChannelResult;
use PubNub\PubNubUtil;


class RemoveChannelFromChannelGroup extends Endpoint
{
const PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s";
protected const PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s";

/** @var string */
protected $channelGroup;
Expand Down Expand Up @@ -93,7 +92,7 @@ protected function customParams()
/**
* @return PNChannelGroupsRemoveChannelResult
*/
public function sync()
public function sync(): PNChannelGroupsRemoveChannelResult
{
return parent::sync();
}
Expand All @@ -102,7 +101,7 @@ public function sync()
* @param array $result Decoded json
* @return PNChannelGroupsRemoveChannelResult
*/
protected function createResponse($result)
protected function createResponse($result): PNChannelGroupsRemoveChannelResult
{
return new PNChannelGroupsRemoveChannelResult();
}
Expand All @@ -112,7 +111,7 @@ protected function createResponse($result)
*/
protected function isAuthRequired()
{
return True;
return true;
}

/**
Expand Down Expand Up @@ -154,4 +153,4 @@ protected function getName()
{
return "RemoveChannelFromChannelGroup";
}
}
}
11 changes: 5 additions & 6 deletions src/PubNub/Endpoints/ChannelGroups/RemoveChannelGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
use PubNub\Exceptions\PubNubValidationException;
use PubNub\Models\Consumer\ChannelGroup\PNChannelGroupsRemoveGroupResult;


class RemoveChannelGroup extends Endpoint
{
const PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s/remove";
protected const PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s/remove";

/** @var string */
private $channelGroup;
Expand Down Expand Up @@ -72,7 +71,7 @@ protected function buildPath()
/**
* @return PNChannelGroupsRemoveGroupResult
*/
public function sync()
public function sync(): PNChannelGroupsRemoveGroupResult
{
return parent::sync();
}
Expand All @@ -81,7 +80,7 @@ public function sync()
* @param array $result Decoded json
* @return PNChannelGroupsRemoveGroupResult
*/
protected function createResponse($result)
protected function createResponse($result): PNChannelGroupsRemoveGroupResult
{
return new PNChannelGroupsRemoveGroupResult();
}
Expand All @@ -91,7 +90,7 @@ protected function createResponse($result)
*/
protected function isAuthRequired()
{
return True;
return true;
}

/**
Expand Down Expand Up @@ -133,4 +132,4 @@ protected function getName()
{
return "RemoveChannelGroup";
}
}
}
7 changes: 6 additions & 1 deletion src/PubNub/Endpoints/FileSharing/DeleteFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ class DeleteFile extends FileSharingEndpoint
{
protected const ENDPOINT_URL = "/v1/files/%s/channels/%s/files/%s/%s";

protected function createResponse($result)
public function sync(): PNDeleteFileResult
{
return parent::sync();
}

protected function createResponse($result): PNDeleteFileResult
{
return new PNDeleteFileResult($result);
}
Expand Down
7 changes: 6 additions & 1 deletion src/PubNub/Endpoints/FileSharing/DownloadFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ protected function isAuthRequired()
return false;
}

protected function createResponse($result)
public function sync(): PNDownloadFileResult
{
return parent::sync();
}

protected function createResponse($result): PNDownloadFileResult
{
if ($this->pubnub->isCryptoEnabled()) {
return new PNDownloadFileResult($this->pubnub->getCrypto()->decrypt((string)$result));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ public function httpMethod()
return PNHttpMethod::POST;
}

public function createResponse($result)
public function sync(): PNFetchFileUploadS3DataResult
{
return parent::sync();
}

public function createResponse($result): PNFetchFileUploadS3DataResult
{
return new PNFetchFileUploadS3DataResult($result);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PubNub/Endpoints/FileSharing/GetFileDownloadUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function isAuthRequired()
return false;
}

protected function createResponse($result)
protected function createResponse($result): PNGetFileDownloadURLResult
{
return new PNGetFileDownloadURLResult($result);
}
Expand Down
5 changes: 5 additions & 0 deletions src/PubNub/Endpoints/FileSharing/ListFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ protected function isAuthRequired(): bool
return true;
}

public function sync(): PNGetFilesResult
{
return parent::sync();
}

protected function createResponse($result): PNGetFilesResult
{
return new PNGetFilesResult($result);
Expand Down
Loading
Loading