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

Refactor/replace transport with guzzle #116

Merged
merged 19 commits into from
Mar 19, 2025

Conversation

seba-aln
Copy link
Contributor

@seba-aln seba-aln commented Feb 25, 2025

refactor: Replace dependency from Requests to Guzzle.

Replace dependency from Requests to GuzzleHTTP to allow communication over HTTP/2. This is potentially breaking change because removes the old way to set up custom transport with setting the client dependency. Read more in the documentation (migration guide available)

@seba-aln seba-aln marked this pull request as ready for review March 11, 2025 10:31
->setCustom(["a" => "b"])
->setStatus("status")
->setType("type"),
(new PNChannelMember('uuid1'))

Choose a reason for hiding this comment

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

Is this ok to add PNChannelMember with the same uuid1 as above?

$additionalMetadata = ["Months" => "Jan-May"];

// Merge additional metadata
$updatedCustomMetadata = array_merge($custom, $additionalMetadata);

Choose a reason for hiding this comment

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

Wouldn't
$updatedCustomMetadata = $custom + $additionalMetadata;
be better not ot overwrite existing keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that only depends on the goal you want to achieve. over here I show how to update the metadata so array_merge seems better. I guess if you'd change some fields, do a union and after update you get the "old" values then you'd think something is not right.

Choose a reason for hiding this comment

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

ok

$updatedCustomMetadata = array_merge($custom, $additionalMetadata);

// Update the channel metadata
$updatedMetadata = $pubnub->setChannelMetadata()

Choose a reason for hiding this comment

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

What would happened when exception is thrown. Shouldn't we add try/catch block here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's just a simple example. I didn't give it a second thought TBH

Choose a reason for hiding this comment

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

ok

// Set initial channel metadata
$pubnub->setChannelMetadata()
->channel($channel)
->meta(["custom" => $initialCustom])

Choose a reason for hiding this comment

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

is property called meta or custom ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the old implementation had just the meta property where one had to create a valid structure on it's own. Right now there are 'convenience methods' to set custom name and other fields without relying on deep arcane knowledge of the schema :)

Choose a reason for hiding this comment

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

ok

{
$this->fileUrl = $result->headers->getAll()['location'][0];
$this->fileUrl = $response['Location'][0];

Choose a reason for hiding this comment

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

What about:
$this->fileUrl = isset($response['Location'][0]) ? $response['Location'][0] : '';
or
$this->fileUrl = $response['Location'][0] ?? '';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You Sir are absolutely right. This part could use some hardening i guess

@@ -6,9 +6,14 @@ class PNGetFileDownloadURLResult
{
protected string $fileUrl;

Choose a reason for hiding this comment

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

what about:
protected ?string $fileUrl = null;

If Location[0] is not set, the property will be assigned an empty string (''), but it should ideally be null to indicate an error ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You Sir are absolutely right. This part could use some hardening i guess

public bool $channelCustom = false;
public bool $channelType = false;
public bool $channelStatus = false;

public function __construct()
{
$this->mapping = array_merge($this->mapping, [
'channel' => 'channel',
'channelId' => 'channel.id',
'channel' => 'channel.id',

Choose a reason for hiding this comment

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

FYI in kotlin SDK there is:
MembershipInclude(
includeCustom = true,
includeStatus = true,
includeType = true,
includeChannel = true,
includeChannelCustom = true,
includeChannelType = true,
includeChannelStatus = true,
includeTotalCount = true
),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean that it misses custom, status, type and total count ? They are present in the PNIncludes class.
Or it's about not having Include prefix? I thought it would be redundant as the entire object is called PNMembership*Includes*

Choose a reason for hiding this comment

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

Here:
https://www.pubnub.com/docs/sdks/rest-api/get-membership-metadata
in section Query Parameters#include there are:
Possible values: [custom, type, status, channel, channel.custom, channel.status, channel.type]

Does you code allows specifying all those properties?

* @param ClientInterface $httpClient
* @return void
*/
public function setClient(ClientInterface $httpClient): void

Choose a reason for hiding this comment

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

If the client or request factory is changed mid-execution, it could introduce inconsistent behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you mean "mid execution"? this SDK is not yet asynchronous (and not planned to be async or non-blocking) so there should not be a thing that would overwrite client "mid-execution"

Choose a reason for hiding this comment

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

ok

* @param RequestFactoryInterface $requestFactory
* @return void
*/
public function setRequestFactory(RequestFactoryInterface $requestFactory): void

Choose a reason for hiding this comment

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

If the client or request factory is changed mid-execution, it could introduce inconsistent behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same ... to change anything you have to wait until nothing else is running

Choose a reason for hiding this comment

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

ok

public bool $channelCustom = false;
public bool $channelType = false;
public bool $channelStatus = false;

public function __construct()
{
$this->mapping = array_merge($this->mapping, [
'channel' => 'channel',
'channelId' => 'channel.id',
'channel' => 'channel.id',

Choose a reason for hiding this comment

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

Here:
https://www.pubnub.com/docs/sdks/rest-api/get-membership-metadata
in section Query Parameters#include there are:
Possible values: [custom, type, status, channel, channel.custom, channel.status, channel.type]

Does you code allows specifying all those properties?

* @param ClientInterface $httpClient
* @return void
*/
public function setClient(ClientInterface $httpClient): void

Choose a reason for hiding this comment

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

ok

* @param RequestFactoryInterface $requestFactory
* @return void
*/
public function setRequestFactory(RequestFactoryInterface $requestFactory): void

Choose a reason for hiding this comment

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

ok

$additionalMetadata = ["Months" => "Jan-May"];

// Merge additional metadata
$updatedCustomMetadata = array_merge($custom, $additionalMetadata);

Choose a reason for hiding this comment

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

ok

$updatedCustomMetadata = array_merge($custom, $additionalMetadata);

// Update the channel metadata
$updatedMetadata = $pubnub->setChannelMetadata()

Choose a reason for hiding this comment

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

ok

// Set initial channel metadata
$pubnub->setChannelMetadata()
->channel($channel)
->meta(["custom" => $initialCustom])

Choose a reason for hiding this comment

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

ok

@seba-aln
Copy link
Contributor Author

@pubnub-release-bot release as 8.0.0

@seba-aln seba-aln merged commit eeee989 into master Mar 19, 2025
8 checks passed
@seba-aln seba-aln deleted the refactor/replace-transport-with-guzzle branch March 19, 2025 13:41
@pubnub-release-bot
Copy link
Contributor

🚀 Release successfully completed 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants