Skip to content

Commit

Permalink
Merge branch 'release/0.56.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Jan 11, 2023
2 parents f24f190 + c12ecaa commit d1c895e
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 40 deletions.
12 changes: 10 additions & 2 deletions Source/ZoomNet.IntegrationTests/Tests/Reports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ public async Task RunAsync(User myUser, string[] myPermissions, IZoomClient clie

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

//GET ALL MEETINGS
var now = DateTime.UtcNow;
var pastMeetings = await client.Reports.GetMeetingsAsync(myUser.Id, now.Subtract(TimeSpan.FromDays(30)), now, ReportMeetingType.Past, 30, null, cancellationToken);
var from = now.Subtract(TimeSpan.FromDays(30));
var to = now;

//GET ALL HOSTS
var activeHosts = await client.Reports.GetHostsAsync(from, to, ReportHostType.Active, 30, null, cancellationToken);
var inactiveHosts = await client.Reports.GetHostsAsync(from, to, ReportHostType.Inactive, 30, null, cancellationToken);
await log.WriteLineAsync($"Active Hosts: {activeHosts.Records.Length}. Inactive Hosts: {inactiveHosts.Records.Length}").ConfigureAwait(false);

//GET ALL MEETINGS
var pastMeetings = await client.Reports.GetMeetingsAsync(myUser.Id, from, to, ReportMeetingType.Past, 30, null, cancellationToken);

int totalParticipants = 0;

Expand Down
2 changes: 2 additions & 0 deletions Source/ZoomNet/Json/ZoomNetJsonSerializerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ namespace ZoomNet.Json
[JsonSerializable(typeof(ZoomNet.Models.RegistrationQuestionsForMeeting))]
[JsonSerializable(typeof(ZoomNet.Models.RegistrationQuestionsForWebinar))]
[JsonSerializable(typeof(ZoomNet.Models.RegistrationType))]
[JsonSerializable(typeof(ZoomNet.Models.ReportHost))]
[JsonSerializable(typeof(ZoomNet.Models.ReportMeetingParticipant))]
[JsonSerializable(typeof(ZoomNet.Models.ReportMeetingType))]
[JsonSerializable(typeof(ZoomNet.Models.ReportParticipant))]
Expand Down Expand Up @@ -361,6 +362,7 @@ namespace ZoomNet.Json
[JsonSerializable(typeof(ZoomNet.Models.RegistrationQuestionsForMeeting[]))]
[JsonSerializable(typeof(ZoomNet.Models.RegistrationQuestionsForWebinar[]))]
[JsonSerializable(typeof(ZoomNet.Models.RegistrationType[]))]
[JsonSerializable(typeof(ZoomNet.Models.ReportHost[]))]
[JsonSerializable(typeof(ZoomNet.Models.ReportMeetingParticipant[]))]
[JsonSerializable(typeof(ZoomNet.Models.ReportMeetingType[]))]
[JsonSerializable(typeof(ZoomNet.Models.ReportParticipant[]))]
Expand Down
45 changes: 45 additions & 0 deletions Source/ZoomNet/Models/ReportHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Text.Json.Serialization;

namespace ZoomNet.Models;

/// <summary>
/// Host report item.
/// </summary>
public class ReportHost
{
/// <summary>Gets or sets the user id.</summary>
[JsonPropertyName("id")]
public string Id { get; set; }

/// <summary>Gets or sets the department.</summary>
[JsonPropertyName("dept")]
public string Department { get; set; }

/// <summary>Gets or sets a valid email address.</summary>
[JsonPropertyName("email")]
public string Email { get; set; }

/// <summary>Gets or sets the type.</summary>
[JsonPropertyName("type")]
public UserType Type { get; set; }

/// <summary>Gets or sets display name.</summary>
[JsonPropertyName("user_name")]
public string DisplayName { get; set; }

/// <summary>Gets or sets the custom attributes.</summary>
[JsonPropertyName("custom_attributes")]
public CustomAttribute[] CustomAttributes { get; set; }

/// <summary>Gets or sets the number of participants in meetings for user.</summary>
[JsonPropertyName("participants")]
public int TotalParticipants { get; set; }

/// <summary>Gets or sets the number of meetings for user.</summary>
[JsonPropertyName("meetings")]
public int TotalMeetings { get; set; }

/// <summary>Gets or sets the number of meeting minutes for user.</summary>
[JsonPropertyName("meeting_minutes")]
public int TotalMeetingMinutes { get; set; }
}
21 changes: 21 additions & 0 deletions Source/ZoomNet/Models/ReportHostType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Runtime.Serialization;

namespace ZoomNet.Models;

/// <summary>
/// Enumeration to indicate the type of a host.
/// </summary>
public enum ReportHostType
{
/// <summary>
/// Active.
/// </summary>
[EnumMember(Value = "active")]
Active,

/// <summary>
/// Inactive.
/// </summary>
[EnumMember(Value = "inactive")]
Inactive,
}
3 changes: 3 additions & 0 deletions Source/ZoomNet/Models/UserType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public enum UserType
/// <summary>On-premise.</summary>
OnPremise = 3,

/// <summary>No Meetings License.</summary>
NoMeetingsLicense = 4,

/// <summary>None.</summary>
/// <remarks>This can only be set with <see cref="UserCreateType.SSo"/>.</remarks>
None = 99,
Expand Down
26 changes: 25 additions & 1 deletion Source/ZoomNet/Resources/IReports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,32 @@ public interface IReports
/// </param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// An array of <see cref="PastMeeting">meetings.</see>.
/// An array of <see cref="PastMeeting">meetings</see>.
/// </returns>
Task<PaginatedResponseWithToken<PastMeeting>> GetMeetingsAsync(string userId, DateTime from, DateTime to, ReportMeetingType type = ReportMeetingType.Past, int pageSize = 30, string pageToken = null, CancellationToken cancellationToken = default);

/// <summary>
/// Gets active/inactive host reports.
/// </summary>
/// <remarks>
/// A user is considered to be an active host during the month specified in the "from" and "to" range, if the user has hosted at least one meeting during this period. If the user didn't host any meetings during this period, the user is considered to be inactive.
/// The Active Hosts report displays a list of meetings, participants, and meeting minutes for a specific time range, up to one month. The month should fall within the last six months.
/// The Inactive Hosts report pulls a list of users who were not active during a specific period of time.
/// Use this method to retrieve an active or inactive host report for a specified period of time. The time range for the report is limited to a month and the month should fall under the past six months.
/// </remarks>
/// <param name="from">Start date.</param>
/// <param name="to">End date.</param>
/// <param name="type">Type of report.</param>
/// <param name="pageSize">The number of records returned within a single API call.</param>
/// <param name="pageToken">
/// The next page token is used to paginate through large result sets.
/// A next page token will be returned whenever the set of available results exceeds the current page size.
/// The expiration period for this token is 15 minutes.
/// </param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// An array of <see cref="ReportHost">report items</see>.
/// </returns>
Task<PaginatedResponseWithToken<ReportHost>> GetHostsAsync(DateTime from, DateTime to, ReportHostType type = ReportHostType.Active, int pageSize = 30, string pageToken = null, CancellationToken cancellationToken = default);
}
}
77 changes: 42 additions & 35 deletions Source/ZoomNet/Resources/Reports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ internal Reports(IClient client)
/// </returns>
public Task<PaginatedResponseWithToken<ReportMeetingParticipant>> GetMeetingParticipantsAsync(string meetingId, int pageSize = 30, string pageToken = null, CancellationToken cancellationToken = default)
{
if (pageSize < 1 || pageSize > 300)
{
throw new ArgumentOutOfRangeException(nameof(pageSize), "Page size must be between 1 and 300");
}
VerifyPageSize(pageSize);

return _client
.GetAsync($"report/meetings/{meetingId}/participants")
Expand All @@ -55,39 +52,11 @@ public Task<PaginatedResponseWithToken<ReportMeetingParticipant>> GetMeetingPart
.AsPaginatedResponseWithToken<ReportMeetingParticipant>("participants");
}

/// <summary>
/// Get a list past meetings and webinars for a specified time period. The time range for the report is limited to a month and the month must fall within the past six months.
/// </summary>
/// <param name="userId">The user ID or email address of the user.</param>
/// <param name="from">Start date.</param>
/// <param name="to">End date.</param>
/// <param name="type">The meeting type to query for.</param>
/// <param name="pageSize">The number of records returned within a single API call.</param>
/// <param name="pageToken">
/// The next page token is used to paginate through large result sets.
/// A next page token will be returned whenever the set of available results exceeds the current page size.
/// The expiration period for this token is 15 minutes.
/// </param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// An array of <see cref="PastMeeting">meetings.</see>.
/// </returns>
/// <inheritdoc/>
public Task<PaginatedResponseWithToken<PastMeeting>> GetMeetingsAsync(string userId, DateTime from, DateTime to, ReportMeetingType type, int pageSize = 30, string pageToken = null, CancellationToken cancellationToken = default)
{
if (to < from)
{
throw new ArgumentOutOfRangeException(nameof(to), $"Should be greater then or equal to {nameof(from)}.");
}

if (to - from > TimeSpan.FromDays(30))
{
throw new ArgumentOutOfRangeException(nameof(to), "The date range should not exceed one month.");
}

if (pageSize < 1 || pageSize > 300)
{
throw new ArgumentOutOfRangeException(nameof(pageSize), "Page size must be between 1 and 300");
}
VerifyReportDatesRange(from, to);
VerifyPageSize(pageSize);

return _client
.GetAsync($"report/users/{userId}/meetings")
Expand All @@ -99,5 +68,43 @@ public Task<PaginatedResponseWithToken<PastMeeting>> GetMeetingsAsync(string use
.WithCancellationToken(cancellationToken)
.AsPaginatedResponseWithToken<PastMeeting>("meetings");
}

/// <inheritdoc/>
public Task<PaginatedResponseWithToken<ReportHost>> GetHostsAsync(DateTime from, DateTime to, ReportHostType type = ReportHostType.Active, int pageSize = 30, string pageToken = null, CancellationToken cancellationToken = default)
{
VerifyReportDatesRange(from, to);
VerifyPageSize(pageSize);

return _client
.GetAsync("report/users")
.WithArgument("from", from.ToZoomFormat(dateOnly: true))
.WithArgument("to", to.ToZoomFormat(dateOnly: true))
.WithArgument("type", type.ToEnumString())
.WithArgument("page_size", pageSize)
.WithArgument("next_page_token", pageToken)
.WithCancellationToken(cancellationToken)
.AsPaginatedResponseWithToken<ReportHost>("users");
}

private static void VerifyPageSize(int pageSize)
{
if (pageSize < 1 || pageSize > 300)
{
throw new ArgumentOutOfRangeException(nameof(pageSize), "Page size must be between 1 and 300");
}
}

private static void VerifyReportDatesRange(DateTime from, DateTime to)
{
if (to < from)
{
throw new ArgumentOutOfRangeException(nameof(to), $"Should be greater then or equal to {nameof(from)}.");
}

if (to - from > TimeSpan.FromDays(30))
{
throw new ArgumentOutOfRangeException(nameof(to), "The date range should not exceed one month.");
}
}
}
}
2 changes: 1 addition & 1 deletion Source/ZoomNet/Resources/Roles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public Task AssignUsersAsync(string roleId, IEnumerable<string> userIds, Cancell
{
// Zoom requires either the "id" field or the "email" field.
// If both are provided, "id" takes precedence.
{ "members", userIds.Select(id => new JsonObject { { (id ?? string.Empty).Contains("@") ? "email" : "id", id } }).ToArray() }
{ "members", userIds.Select(id => new JsonObject { { (id ?? string.Empty).Contains('@') ? "email" : "id", id } }).ToArray() }
};

return _client
Expand Down
2 changes: 1 addition & 1 deletion Source/ZoomNet/Resources/Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public Task UpdateAsync(string userId, string firstName = null, string lastName
{ "pronouns", pronouns },
{ "pronouns_option", pronounsDisplay?.ToEnumString() },
{ "timezone", timezone?.ToEnumString() },
{ "type", type?.ToEnumString() },
{ "type", type },
{ "use_pmi", usePmi },
{ "vanity_name", personalMeetingRoomName },
{ "custom_attributes", customAttributes?.ToArray() }
Expand Down

0 comments on commit d1c895e

Please sign in to comment.