Skip to content

Refactor/replace transport with guzzle#116

Merged
seba-aln merged 19 commits intomasterfrom
refactor/replace-transport-with-guzzle
Mar 19, 2025
Merged

Refactor/replace transport with guzzle#116
seba-aln merged 19 commits intomasterfrom
refactor/replace-transport-with-guzzle

Conversation

@seba-aln
Copy link

@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'))
Copy link
Contributor

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);
Copy link
Contributor

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
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.

Copy link
Contributor

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()
Copy link
Contributor

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
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

Copy link
Contributor

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])
Copy link
Contributor

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
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 :)

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

public function __construct(array $response)
{
$this->fileUrl = $result->headers->getAll()['location'][0];
$this->fileUrl = $response['Location'][0];
Copy link
Contributor

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
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;
Copy link
Contributor

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
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

$this->mapping = array_merge($this->mapping, [
'channel' => 'channel',
'channelId' => 'channel.id',
'channel' => 'channel.id',
Copy link
Contributor

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
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*

Copy link
Contributor

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
Copy link
Contributor

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
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"

Copy link
Contributor

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
Copy link
Contributor

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
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

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

$this->mapping = array_merge($this->mapping, [
'channel' => 'channel',
'channelId' => 'channel.id',
'channel' => 'channel.id',
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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);
Copy link
Contributor

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()
Copy link
Contributor

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])
Copy link
Contributor

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
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