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 d493f351..8d5d4e56 100644 --- a/Source/ZoomNet.IntegrationTests/TestsRunner.cs +++ b/Source/ZoomNet.IntegrationTests/TestsRunner.cs @@ -117,7 +117,8 @@ public async Task RunAsync() 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 4f54bc6e..2478c346 100644 --- a/Source/ZoomNet/IZoomClient.cs +++ b/Source/ZoomNet/IZoomClient.cs @@ -107,5 +107,10 @@ public interface IZoomClient /// Gets the resource which allows you to view reports. /// IReports Reports { 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 bfebc42c..155eea13 100644 --- a/Source/ZoomNet/ZoomClient.cs +++ b/Source/ZoomNet/ZoomClient.cs @@ -156,6 +156,9 @@ public static string Version /// public IReports Reports { get; private set; } + /// + public IWorkspaces Workspaces { get; private set; } + #endregion #region CTOR @@ -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); } ///