Refactor/replace transport with guzzle#116
Conversation
| ->setCustom(["a" => "b"]) | ||
| ->setStatus("status") | ||
| ->setType("type"), | ||
| (new PNChannelMember('uuid1')) |
There was a problem hiding this comment.
Is this ok to add PNChannelMember with the same uuid1 as above?
| $additionalMetadata = ["Months" => "Jan-May"]; | ||
|
|
||
| // Merge additional metadata | ||
| $updatedCustomMetadata = array_merge($custom, $additionalMetadata); |
There was a problem hiding this comment.
Wouldn't
$updatedCustomMetadata = $custom + $additionalMetadata;
be better not ot overwrite existing keys?
There was a problem hiding this comment.
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.
| $updatedCustomMetadata = array_merge($custom, $additionalMetadata); | ||
|
|
||
| // Update the channel metadata | ||
| $updatedMetadata = $pubnub->setChannelMetadata() |
There was a problem hiding this comment.
What would happened when exception is thrown. Shouldn't we add try/catch block here?
There was a problem hiding this comment.
it's just a simple example. I didn't give it a second thought TBH
| // Set initial channel metadata | ||
| $pubnub->setChannelMetadata() | ||
| ->channel($channel) | ||
| ->meta(["custom" => $initialCustom]) |
There was a problem hiding this comment.
is property called meta or custom ?
There was a problem hiding this comment.
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 :)
| public function __construct(array $response) | ||
| { | ||
| $this->fileUrl = $result->headers->getAll()['location'][0]; | ||
| $this->fileUrl = $response['Location'][0]; |
There was a problem hiding this comment.
What about:
$this->fileUrl = isset($response['Location'][0]) ? $response['Location'][0] : '';
or
$this->fileUrl = $response['Location'][0] ?? '';
There was a problem hiding this comment.
You Sir are absolutely right. This part could use some hardening i guess
| @@ -6,9 +6,14 @@ class PNGetFileDownloadURLResult | |||
| { | |||
| protected string $fileUrl; | |||
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
FYI in kotlin SDK there is:
MembershipInclude(
includeCustom = true,
includeStatus = true,
includeType = true,
includeChannel = true,
includeChannelCustom = true,
includeChannelType = true,
includeChannelStatus = true,
includeTotalCount = true
),
There was a problem hiding this comment.
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*
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
If the client or request factory is changed mid-execution, it could introduce inconsistent behavior.
There was a problem hiding this comment.
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"
| * @param RequestFactoryInterface $requestFactory | ||
| * @return void | ||
| */ | ||
| public function setRequestFactory(RequestFactoryInterface $requestFactory): void |
There was a problem hiding this comment.
If the client or request factory is changed mid-execution, it could introduce inconsistent behavior.
There was a problem hiding this comment.
same ... to change anything you have to wait until nothing else is running
| $this->mapping = array_merge($this->mapping, [ | ||
| 'channel' => 'channel', | ||
| 'channelId' => 'channel.id', | ||
| 'channel' => 'channel.id', |
There was a problem hiding this comment.
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 |
| * @param RequestFactoryInterface $requestFactory | ||
| * @return void | ||
| */ | ||
| public function setRequestFactory(RequestFactoryInterface $requestFactory): void |
| $additionalMetadata = ["Months" => "Jan-May"]; | ||
|
|
||
| // Merge additional metadata | ||
| $updatedCustomMetadata = array_merge($custom, $additionalMetadata); |
| $updatedCustomMetadata = array_merge($custom, $additionalMetadata); | ||
|
|
||
| // Update the channel metadata | ||
| $updatedMetadata = $pubnub->setChannelMetadata() |
| // Set initial channel metadata | ||
| $pubnub->setChannelMetadata() | ||
| ->channel($channel) | ||
| ->meta(["custom" => $initialCustom]) |
|
@pubnub-release-bot release as 8.0.0 |
|
🚀 Release successfully completed 🚀 |
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)