-
Notifications
You must be signed in to change notification settings - Fork 91
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
Conversation
->setCustom(["a" => "b"]) | ||
->setStatus("status") | ||
->setType("type"), | ||
(new PNChannelMember('uuid1')) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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] ?? '';
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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
),
There was a problem hiding this comment.
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*
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@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)