Closed abishekrsrikaanth closed 1 year ago
I actually figured it out myself. Here is the code for it if anybody else is looking for it
use Ably\AblyRest;
$client = new AblyRest('KEY_GOES_HERE');
$channelStatus = $client->request('GET','/channels/CHANNEL_ID');
the output for it looks something like this:
Ably\Models\HttpPaginatedResponse {#3037
+statusCode: 200,
+success: true,
+errorCode: null,
+errorMessage: null,
+headers: [
"content-type" => "application/json",
"content-length" => "280",
"access-control-allow-credentials" => "true",
"access-control-allow-origin" => "*",
"access-control-expose-headers" => "Link,Transfer-Encoding,Content-Length,X-Ably-ErrorCode,X-Ably-ErrorMessage,X-Ably-ServerId,Server",
"date" => "Thu, 24 Oct 2019 16:53:40 GMT",
"vary" => "Origin",
"x-ably-serverid" => "some-server-id",
"x-cache" => "Miss from cloudfront",
"via" => "some-random-code-ejre",
"x-amz-cf-pop" => "some-random-amz-pop",
"x-amz-cf-id" => "some-random-amz-value-here",
],
+items: [
Ably\Models\Untyped {#3036
+"name": "CHANNEL_NAME",
+"channelId": "CHANNEL_NAME",
+"status": {#3046
+"isActive": true,
+"occupancy": {#3014
+"metrics": {#3035
+"connections": 1,
+"publishers": 0,
+"subscribers": 1,
+"presenceConnections": 0,
+"presenceMembers": 0,
+"presenceSubscribers": 1,
},
},
},
},
],
}
Hope this helps for anyone else looking for it.
I really wish this was simpler like
$client->channel('MY_CHANNEL_NAME')->getStatus();
Hey @abishekrsrikaanth, at present, that API has not made it to the SDKs. The issue is that, moving it to SDKs, means we have roll that out for every SDK for every API that is available. Our approach is focus on core functionality in the SDKs, and let developers use request
for other APIs so that we can add APIs quickly, and developers can get them quickly.
With your example though, couldn't it be simplified to:
use Ably\AblyRest;
$client = new AblyRest('KEY_GOES_HERE');
$channelStatus = $client->request('GET','/channels/CHANNEL_ID').items[0]["status"];
P.S. I am not a PHP dev, so that may not run exactly, but the approach is a) you know what type is being returned, b) you can simplify access to the elements you want from the status.
@abishekrsrikaanth did you have any thoughts on my last comment?
@mattheworiordan, i was just hoping that the channel
object would have a getStatus
method to retrieve the status instead of having to use the request method. I do understand that the SDK depends on the request methods internally.
But for my convenience, I extended the Channel class and added methods within my app so I can get the status of the channels and metrics by the channel
.
But for my convenience, I extended the Channel class and added methods within my app so I can get the status of the channels and metrics by the channel.
Great, glad to hear. I'll add a note to our feature tracker to consider adding channel metadata methods to the SDK now.
Trying to figure out how to get the Channel Meta data information using the SDK. Here is the docs on ably https://www.ably.io/documentation/realtime/channel-metadata#occupancy.
┆Issue is synchronized with this Jira Story by Unito