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

Add async version of channel status #1266

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,6 @@ foreach (var presence in presenceHistory.Items)
var presenceNextPage = await presenceHistory.NextAsync();
```

### Getting the channel status

Getting the current status of a channel, including details of the current number of `Publishers`, `Subscribers` and `PresenceMembers` etc is simple

```csharp
ChannelDetails details = channel.Status();
ChannelMetrics metrics = details.Status.Occupancy.Metrics;
// Do something with 'metrics.Publishers' etc
```

### Symmetric end-to-end encrypted payloads on a channel

When a 128-bit or 256-bit key is provided to the library, all payloads are encrypted and decrypted automatically using that key on the channel. The secret key is never transmitted to Ably and thus it is the developer's responsibility to distribute a secret key to both publishers and subscribers.
Expand Down Expand Up @@ -445,6 +435,16 @@ var nextStatsPage = await stats.NextAsync();
DateTimeOffset time = await client.TimeAsync();
```

### Getting the channel status

Getting the current status of a channel, including details of the current number of `Publishers`, `Subscribers` and `PresenceMembers` etc is simple

```csharp
ChannelDetails details = await channel.StatusAsync();
ChannelMetrics metrics = details.Status.Occupancy.Metrics;
// Do something with 'metrics.Publishers' etc
```

### Making explicit HTTP requests to Ably Rest Endpoints / Batch publish
- The `AblyRest->Request` method should be used to make explicit HTTP requests.
- It automatically adds necessary auth headers based on the initial auth config and supports pagination.
Expand Down
9 changes: 8 additions & 1 deletion src/IO.Ably.Shared/Rest/IRestChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public interface IRestChannel
/// <returns><see cref="PaginatedResult{T}"/> of past Messages.</returns>
Task<PaginatedResult<Message>> HistoryAsync(PaginatedRequestParams query);

/// <summary>
/// Returns the active status for the channel including the number of publishers, subscribers and presenceMembers etc.
/// </summary>
/// <returns><see cref="ChannelDetails"/>Channel Details.</returns>
Task<ChannelDetails> StatusAsync();

/// <summary>
/// Name of the channel.
/// </summary>
Expand Down Expand Up @@ -103,7 +109,8 @@ public interface IRestChannel
PaginatedResult<Message> History(PaginatedRequestParams query);

/// <summary>
/// Returns the active status for the channel including the number of publishers, subscribers and presenceMembers etc.
/// Sync version of <see cref="StatusAsync()"/>.
/// Prefer async version where possible.
/// </summary>
/// <returns><see cref="ChannelDetails"/>Channel Details.</returns>
ChannelDetails Status();
Expand Down
3 changes: 2 additions & 1 deletion src/IO.Ably.Shared/Rest/RestChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ public PaginatedResult<Message> History(PaginatedRequestParams query)
return AsyncHelper.RunSync(() => HistoryAsync(query));
}

private async Task<ChannelDetails> StatusAsync()
/// <inheritdoc/>
public async Task<ChannelDetails> StatusAsync()
{
AblyRequest request = _ablyRest.CreateGetRequest("/channels/" + Name);
return await _ablyRest.ExecuteRequest<ChannelDetails>(request);
Expand Down
2 changes: 1 addition & 1 deletion src/IO.Ably.Tests.Shared/Rest/ChannelSandboxSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ public async Task ChannelDetails_AreAvailable(Protocol protocol)
AblyRest client = await GetRestClient(protocol);
IRestChannel c = client.Channels.Get(Name);

ChannelDetails cd = c.Status();
ChannelDetails cd = await c.StatusAsync();
cd.ChannelId.Should().Be(Name);
cd.Status.IsActive.Should().BeTrue();

Expand Down
Loading