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 all commits
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
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: 7.0.0
version: 7.0.1
schema: 1
scm: github.com/pubnub/php
changelog:
- date: 2024-07-10
version: 7.0.1
changes:
- type: improvement
text: "Added strict typing for some customer facing elements."
- date: 2024-06-27
version: 7.0.0
changes:
Expand Down Expand Up @@ -429,8 +434,8 @@ sdks:
- x86-64
- distribution-type: library
distribution-repository: GitHub release
package-name: php-7.0.0.zip
location: https://github.com/pubnub/php/releases/tag/7.0.0
package-name: php-7.0.1.zip
location: https://github.com/pubnub/php/releases/tag/7.0.1
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 @@
## 7.0.1
July 10 2024

#### Modified
- Added strict typing for some customer facing elements.

## 7.0.0
June 27 2024

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": "7.0.0"
"pubnub/pubnub": "7.0.1"
}
}
```
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": "7.0.0",
"version": "7.0.1",
"authors": [
{
"name": "PubNub",
Expand Down
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
Loading
Loading