From 1d14199d0c8d363d2ad259bb815dad18370ea238 Mon Sep 17 00:00:00 2001 From: Jericho Date: Tue, 26 Apr 2022 09:42:39 -0400 Subject: [PATCH] =?UTF-8?q?=EF=BB=BF(GH-197)=20Add=20the=20Workspaces=20re?= =?UTF-8?q?source?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tests/Workspaces.cs | 33 ++++++++++++++ .../ZoomNet.IntegrationTests/TestsRunner.cs | 3 +- Source/ZoomNet/IZoomClient.cs | 5 +++ Source/ZoomNet/Models/Workspace.cs | 22 +++++++++ Source/ZoomNet/Resources/IWorkspaces.cs | 27 +++++++++++ Source/ZoomNet/Resources/Workspaces.cs | 45 +++++++++++++++++++ Source/ZoomNet/ZoomClient.cs | 4 ++ 7 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 Source/ZoomNet.IntegrationTests/Tests/Workspaces.cs create mode 100644 Source/ZoomNet/Models/Workspace.cs create mode 100644 Source/ZoomNet/Resources/IWorkspaces.cs create mode 100644 Source/ZoomNet/Resources/Workspaces.cs diff --git a/Source/ZoomNet.IntegrationTests/Tests/Workspaces.cs b/Source/ZoomNet.IntegrationTests/Tests/Workspaces.cs new file mode 100644 index 00000000..c0b99f11 --- /dev/null +++ b/Source/ZoomNet.IntegrationTests/Tests/Workspaces.cs @@ -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); + } + } +} diff --git a/Source/ZoomNet.IntegrationTests/TestsRunner.cs b/Source/ZoomNet.IntegrationTests/TestsRunner.cs index 6b8563c7..3d1fc96d 100644 --- a/Source/ZoomNet.IntegrationTests/TestsRunner.cs +++ b/Source/ZoomNet.IntegrationTests/TestsRunner.cs @@ -149,7 +149,8 @@ private async Task RunApiTestsAsync(IConnectionInfo connectionInfo, IWebPro typeof(Roles), typeof(Users), typeof(Webinars), - typeof(Reports) + typeof(Reports), + typeof(Workspaces), }; // Get my user and permisisons diff --git a/Source/ZoomNet/IZoomClient.cs b/Source/ZoomNet/IZoomClient.cs index 773b5d73..6dc86974 100644 --- a/Source/ZoomNet/IZoomClient.cs +++ b/Source/ZoomNet/IZoomClient.cs @@ -112,5 +112,10 @@ public interface IZoomClient /// Gets the resource which allows you to manage call logs. /// ICallLogs CallLogs { get; } + + /// + /// Gets the resource which allows you to manage workspaces. + /// + IWorkspaces Workspaces { get; } } } diff --git a/Source/ZoomNet/Models/Workspace.cs b/Source/ZoomNet/Models/Workspace.cs new file mode 100644 index 00000000..5cb7836a --- /dev/null +++ b/Source/ZoomNet/Models/Workspace.cs @@ -0,0 +1,22 @@ +using System.Text.Json.Serialization; + +namespace ZoomNet.Models +{ + /// + /// A workspace. + /// + public class Workspace + { + /// Gets or sets the workspace id. + [JsonPropertyName("id")] + public long Id { get; set; } + + /// Gets or sets the name of the workspace. + [JsonPropertyName("workspace_name")] + public string Name { get; set; } + + /// Gets or sets the type of the workspace. + [JsonPropertyName("workspace_type")] + public string Type { get; set; } + } +} diff --git a/Source/ZoomNet/Resources/IWorkspaces.cs b/Source/ZoomNet/Resources/IWorkspaces.cs new file mode 100644 index 00000000..2bfc4621 --- /dev/null +++ b/Source/ZoomNet/Resources/IWorkspaces.cs @@ -0,0 +1,27 @@ +using System.Threading; +using System.Threading.Tasks; +using ZoomNet.Models; + +namespace ZoomNet.Resources +{ + /// + /// Allows you to manage workspaces. + /// + /// + /// See Zoom documentation for more information. + /// + public interface IWorkspaces + { + /// + /// Retrieve all workspaces for a location. + /// + /// The location Id. + /// The number of records returned within a single API call. + /// The paging token. + /// The cancellation token. + /// + /// An array of workspaces. + /// + Task> GetAllAsync(string locationId, int recordsPerPage = 30, string pagingToken = null, CancellationToken cancellationToken = default); + } +} diff --git a/Source/ZoomNet/Resources/Workspaces.cs b/Source/ZoomNet/Resources/Workspaces.cs new file mode 100644 index 00000000..749b320f --- /dev/null +++ b/Source/ZoomNet/Resources/Workspaces.cs @@ -0,0 +1,45 @@ +using Pathoschild.Http.Client; +using System; +using System.Threading; +using System.Threading.Tasks; +using ZoomNet.Models; + +namespace ZoomNet.Resources +{ + /// + /// Allows you to manage workspaces. + /// + /// + /// + /// See Zoom documentation for more information. + /// + public class Workspaces : IWorkspaces + { + private readonly Pathoschild.Http.Client.IClient _client; + + /// + /// Initializes a new instance of the class. + /// + /// The HTTP client. + internal Workspaces(Pathoschild.Http.Client.IClient client) + { + _client = client; + } + + /// + public Task> 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("workspaces"); + } + } +} diff --git a/Source/ZoomNet/ZoomClient.cs b/Source/ZoomNet/ZoomClient.cs index b982c1b8..88180cb4 100644 --- a/Source/ZoomNet/ZoomClient.cs +++ b/Source/ZoomNet/ZoomClient.cs @@ -161,6 +161,9 @@ public static string Version /// public ICallLogs CallLogs { get; private set; } + /// + public IWorkspaces Workspaces { get; private set; } + #endregion #region CTOR @@ -265,6 +268,7 @@ private ZoomClient(IConnectionInfo connectionInfo, HttpClient httpClient, bool d Dashboards = new Dashboards(_fluentClient); Reports = new Reports(_fluentClient); CallLogs = new CallLogs(_fluentClient); + Workspaces = new Workspaces(_fluentClient); } ///