Skip to content

Commit

Permalink
(GH-197) Add the Workspaces resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Jan 11, 2023
1 parent 0775e98 commit 50d6ba0
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 1 deletion.
33 changes: 33 additions & 0 deletions Source/ZoomNet.IntegrationTests/Tests/Workspaces.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using ZoomNet.Models;

namespace ZoomNet.IntegrationTests.Tests
{
public class Workspaces : IIntegrationTest
{
public async Task RunAsync(User myUser, string[] myPermissions, IZoomClient client, TextWriter log, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested) return;

await log.WriteLineAsync("\n***** WORKSPACES *****\n").ConfigureAwait(false);

// GET ALL THE WORKSPACES
var paginatedWorkspaces = await client.Workspaces.GetAllAsync(locationId, 30, null, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"There are {paginatedWorkspaces.TotalRecords} workspaces for location {locationId}").ConfigureAwait(false);

//// CLEANUP PREVIOUS INTEGRATION TESTS THAT MIGHT HAVE BEEN INTERRUPTED BEFORE THEY HAD TIME TO CLEANUP AFTER THEMSELVES
//var cleanUpTasks = paginatedWebinars.Records
// .Union(paginatedWebinars.Records)
// .Where(m => m.Topic.StartsWith("ZoomNet Integration Testing:"))
// .Select(async oldWebinar =>
// {
// await client.Webinars.DeleteAsync(oldWebinar.Id, null, false, cancellationToken).ConfigureAwait(false);
// await log.WriteLineAsync($"Webinar {oldWebinar.Id} deleted").ConfigureAwait(false);
// await Task.Delay(250, cancellationToken).ConfigureAwait(false); // Brief pause to ensure Zoom has time to catch up
// });
//await Task.WhenAll(cleanUpTasks).ConfigureAwait(false);
}
}
}
3 changes: 2 additions & 1 deletion Source/ZoomNet.IntegrationTests/TestsRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public async Task<int> RunAsync()
typeof(Roles),
typeof(Users),
typeof(Webinars),
typeof(Reports)
typeof(Reports),
typeof(Workspaces),
};

// Get my user and permisisons
Expand Down
5 changes: 5 additions & 0 deletions Source/ZoomNet/IZoomClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,10 @@ public interface IZoomClient
/// Gets the resource which allows you to view reports.
/// </summary>
IReports Reports { get; }

/// <summary>
/// Gets the resource which allows you to manage workspaces.
/// </summary>
IWorkspaces Workspaces { get; }
}
}
22 changes: 22 additions & 0 deletions Source/ZoomNet/Models/Workspace.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Text.Json.Serialization;

namespace ZoomNet.Models
{
/// <summary>
/// A workspace.
/// </summary>
public class Workspace
{
/// <summary>Gets or sets the workspace id.</summary>
[JsonPropertyName("id")]
public long Id { get; set; }

/// <summary>Gets or sets the name of the workspace.</summary>
[JsonPropertyName("workspace_name")]
public string Name { get; set; }

/// <summary>Gets or sets the type of the workspace.</summary>
[JsonPropertyName("workspace_type")]
public string Type { get; set; }
}
}
27 changes: 27 additions & 0 deletions Source/ZoomNet/Resources/IWorkspaces.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Threading;
using System.Threading.Tasks;
using ZoomNet.Models;

namespace ZoomNet.Resources
{
/// <summary>
/// Allows you to manage workspaces.
/// </summary>
/// <remarks>
/// See <a href="https://marketplace.zoom.us/docs/api-reference/zoom-api/methods/#tag/Workspaces">Zoom documentation</a> for more information.
/// </remarks>
public interface IWorkspaces
{
/// <summary>
/// Retrieve all workspaces for a location.
/// </summary>
/// <param name="locationId">The location Id.</param>
/// <param name="recordsPerPage">The number of records returned within a single API call.</param>
/// <param name="pagingToken">The paging token.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// An array of <see cref="Workspace">workspaces</see>.
/// </returns>
Task<PaginatedResponseWithToken<Workspace>> GetAllAsync(string locationId, int recordsPerPage = 30, string pagingToken = null, CancellationToken cancellationToken = default);
}
}
45 changes: 45 additions & 0 deletions Source/ZoomNet/Resources/Workspaces.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Pathoschild.Http.Client;
using System;
using System.Threading;
using System.Threading.Tasks;
using ZoomNet.Models;

namespace ZoomNet.Resources
{
/// <summary>
/// Allows you to manage workspaces.
/// </summary>
/// <seealso cref="ZoomNet.Resources.IWorkspaces" />
/// <remarks>
/// See <a href="https://marketplace.zoom.us/docs/api-reference/zoom-api/methods/#tag/Workspaces">Zoom documentation</a> for more information.
/// </remarks>
public class Workspaces : IWorkspaces
{
private readonly Pathoschild.Http.Client.IClient _client;

/// <summary>
/// Initializes a new instance of the <see cref="Workspaces" /> class.
/// </summary>
/// <param name="client">The HTTP client.</param>
internal Workspaces(Pathoschild.Http.Client.IClient client)
{
_client = client;
}

/// <inheritdoc/>
public Task<PaginatedResponseWithToken<Workspace>> GetAllAsync(string locationId, int recordsPerPage = 30, string pagingToken = null, CancellationToken cancellationToken = default)
{
if (recordsPerPage < 1 || recordsPerPage > 300)
{
throw new ArgumentOutOfRangeException(nameof(recordsPerPage), "Records per page must be between 1 and 300");
}

return _client
.GetAsync($"workspaces")
.WithArgument("page_size", recordsPerPage)
.WithArgument("next_page_token", pagingToken)
.WithCancellationToken(cancellationToken)
.AsPaginatedResponseWithToken<Workspace>("workspaces");
}
}
}
4 changes: 4 additions & 0 deletions Source/ZoomNet/ZoomClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ public static string Version
/// </summary>
public IReports Reports { get; private set; }

/// <inheritdoc/>
public IWorkspaces Workspaces { get; private set; }

#endregion

#region CTOR
Expand Down Expand Up @@ -257,6 +260,7 @@ private ZoomClient(IConnectionInfo connectionInfo, HttpClient httpClient, bool d
Webinars = new Webinars(_fluentClient);
Dashboards = new Dashboards(_fluentClient);
Reports = new Reports(_fluentClient);
Workspaces = new Workspaces(_fluentClient);
}

/// <summary>
Expand Down

0 comments on commit 50d6ba0

Please sign in to comment.