Skip to content

Commit

Permalink
Merge pull request #81 from michael-aj-kennedy/UpdateWebinar
Browse files Browse the repository at this point in the history
Webinars: Add functionality to allow existing webinars to be updated.

Resolves #80
  • Loading branch information
Jericho authored Jan 20, 2021
2 parents 8b5b27a + ac7f60f commit b0e59f0
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 2 deletions.
35 changes: 35 additions & 0 deletions Source/ZoomNet/Resources/IWebinars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ public interface IWebinars
/// <exception cref="System.Exception">Thrown when an exception occured while creating the webinar.</exception>
Task<RecurringWebinar> CreateRecurringWebinarAsync(string userId, string topic, string agenda, DateTime? start, int duration, RecurrenceInfo recurrence, string password = null, WebinarSettings settings = null, IDictionary<string, string> trackingFields = null, CancellationToken cancellationToken = default);

/// <summary>
/// Updates an existing scheduled webinar.
/// </summary>
/// <param name="webinarId">The webinar ID.</param>
/// <param name="topic">Webinar topic.</param>
/// <param name="agenda">Webinar description.</param>
/// <param name="start">Webinar start time.</param>
/// <param name="duration">Webinar duration (minutes).</param>
/// <param name="password">Password to join the webinar. By default the password may only contain the following characters: [a-z A-Z 0-9 @ - _ *]. Max of 10 characters. This can be updated within Zoom account settings.</param>
/// <param name="settings">Webinar settings.</param>
/// <param name="trackingFields">Tracking fields.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The async task.
/// </returns>
Task UpdateScheduledWebinarAsync(long webinarId, string topic = null, string agenda = null, DateTime? start = null, int? duration = null, string password = null, WebinarSettings settings = null, IDictionary<string, string> trackingFields = null, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve the details of a webinar.
/// </summary>
Expand All @@ -87,6 +104,24 @@ public interface IWebinars
/// </returns>
Task<Webinar> GetAsync(long webinarId, string occurrenceId = null, CancellationToken cancellationToken = default);

/// <summary>
/// Updates an existing recurring webinar for a user.
/// </summary>
/// <param name="webinarId">The webinar ID.</param>
/// <param name="topic">Webinar topic.</param>
/// <param name="agenda">Webinar description.</param>
/// <param name="start">Webinar start time.</param>
/// <param name="duration">Webinar duration (minutes).</param>
/// <param name="recurrence">Recurrence information.</param>
/// <param name="password">Password to join the webinar. By default the password may only contain the following characters: [a-z A-Z 0-9 @ - _ *]. Max of 10 characters. This can be updated within Zoom account settings.</param>
/// <param name="settings">Webinar settings.</param>
/// <param name="trackingFields">Tracking fields.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The async task.
/// </returns>
Task UpdateRecurringWebinarAsync(long webinarId, string topic = null, string agenda = null, DateTime? start = null, int? duration = null, RecurrenceInfo recurrence = null, string password = null, WebinarSettings settings = null, IDictionary<string, string> trackingFields = null, CancellationToken cancellationToken = default);

/// <summary>
/// Delete a webinar.
/// </summary>
Expand Down
88 changes: 86 additions & 2 deletions Source/ZoomNet/Resources/Webinars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Task<PaginatedResponseWithToken<Webinar>> GetAllAsync(string userId, int
/// <param name="agenda">Webinar description.</param>
/// <param name="start">Webinar start time.</param>
/// <param name="duration">Webinar duration (minutes).</param>
/// <param name="password">Password to join the webinar. Password may only contain the following characters: [a-z A-Z 0-9 @ - _ *]. Max of 10 characters.</param>
/// <param name="password">Password to join the webinar. By default the password may only contain the following characters: [a-z A-Z 0-9 @ - _ *]. Max of 10 characters. This can be updated within Zoom account settings.</param>
/// <param name="settings">Webinar settings.</param>
/// <param name="trackingFields">Tracking fields.</param>
/// <param name="cancellationToken">The cancellation token.</param>
Expand Down Expand Up @@ -120,6 +120,47 @@ public Task<ScheduledWebinar> CreateScheduledWebinarAsync(string userId, string
.AsObject<ScheduledWebinar>();
}

/// <summary>
/// Updates an existing scheduled webinar.
/// </summary>
/// <param name="webinarId">The webinar ID.</param>
/// <param name="topic">Webinar topic.</param>
/// <param name="agenda">Webinar description.</param>
/// <param name="start">Webinar start time.</param>
/// <param name="duration">Webinar duration (minutes).</param>
/// <param name="password">Password to join the webinar. By default the password may only contain the following characters: [a-z A-Z 0-9 @ - _ *]. Max of 10 characters. This can be updated within Zoom account settings.</param>
/// <param name="settings">Webinar settings.</param>
/// <param name="trackingFields">Tracking fields.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The async task.
/// </returns>
public async Task UpdateScheduledWebinarAsync(long webinarId, string topic = null, string agenda = null, DateTime? start = null, int? duration = null, string password = null, WebinarSettings settings = null, IDictionary<string, string> trackingFields = null, CancellationToken cancellationToken = default)
{
var data = new JObject();
data.AddPropertyIfValue("topic", topic);
data.AddPropertyIfValue("agenda", agenda);
data.AddPropertyIfValue("password", password);
data.AddPropertyIfValue("start_time", start?.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss'Z'"));
data.AddPropertyIfValue("duration", duration);
if (start.HasValue) data.Add("timezone", "UTC");
data.AddPropertyIfValue("settings", settings);
data.AddPropertyIfValue("tracking_fields", trackingFields?.Select(tf => new JObject() { { "field", tf.Key }, { "value", tf.Value } }));

var result = await _client
.PatchAsync($"webinars/{webinarId}")
.WithJsonBody(data)
.WithCancellationToken(cancellationToken)
.AsMessage()
.ConfigureAwait(false);

if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
// Zoom returns an HTTP 200 message when there is no webinar subscription and instead returns a 204 after a successful update
throw new NotSupportedException("Webinar subscription plan is missing. Enable webinar for this user once the subscription is added");
}
}

/// <summary>
/// Creates a recurring webinar for a user.
/// </summary>
Expand All @@ -129,7 +170,7 @@ public Task<ScheduledWebinar> CreateScheduledWebinarAsync(string userId, string
/// <param name="start">Webinar start time.</param>
/// <param name="duration">Webinar duration (minutes).</param>
/// <param name="recurrence">Recurrence information.</param>
/// <param name="password">Password to join the webinar. Password may only contain the following characters: [a-z A-Z 0-9 @ - _ *]. Max of 10 characters.</param>
/// <param name="password">Password to join the webinar. By default the password may only contain the following characters: [a-z A-Z 0-9 @ - _ *]. Max of 10 characters. This can be updated within Zoom account settings.</param>
/// <param name="settings">Webinar settings.</param>
/// <param name="trackingFields">Tracking fields.</param>
/// <param name="cancellationToken">The cancellation token.</param>
Expand Down Expand Up @@ -162,6 +203,49 @@ public Task<RecurringWebinar> CreateRecurringWebinarAsync(string userId, string
.AsObject<RecurringWebinar>();
}

/// <summary>
/// Updates an existing recurring webinar for a user.
/// </summary>
/// <param name="webinarId">The webinar ID.</param>
/// <param name="topic">Webinar topic.</param>
/// <param name="agenda">Webinar description.</param>
/// <param name="start">Webinar start time.</param>
/// <param name="duration">Webinar duration (minutes).</param>
/// <param name="recurrence">Recurrence information.</param>
/// <param name="password">Password to join the webinar. By default the password may only contain the following characters: [a-z A-Z 0-9 @ - _ *]. Max of 10 characters. This can be updated within Zoom account settings.</param>
/// <param name="settings">Webinar settings.</param>
/// <param name="trackingFields">Tracking fields.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The async task.
/// </returns>
public async Task UpdateRecurringWebinarAsync(long webinarId, string topic = null, string agenda = null, DateTime? start = null, int? duration = null, RecurrenceInfo recurrence = null, string password = null, WebinarSettings settings = null, IDictionary<string, string> trackingFields = null, CancellationToken cancellationToken = default)
{
var data = new JObject();
data.AddPropertyIfValue("topic", topic);
data.AddPropertyIfValue("agenda", agenda);
data.AddPropertyIfValue("password", password);
data.AddPropertyIfValue("start_time", start?.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss'Z'"));
data.AddPropertyIfValue("duration", duration);
data.AddPropertyIfValue("recurrence", recurrence);
if (start.HasValue) data.Add("timezone", "UTC");
data.AddPropertyIfValue("settings", settings);
data.AddPropertyIfValue("tracking_fields", trackingFields?.Select(tf => new JObject() { { "field", tf.Key }, { "value", tf.Value } }));

var result = await _client
.PatchAsync($"webinars/{webinarId}")
.WithJsonBody(data)
.WithCancellationToken(cancellationToken)
.AsMessage()
.ConfigureAwait(false);

if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
// Zoom returns an HTTP 200 message when there is no webinar subscription and instead returns a 204 after a successful update
throw new NotSupportedException("Webinar subscription plan is missing. Enable webinar for this user once the subscription is added");
}
}

/// <summary>
/// Retrieve the details of a webinar.
/// </summary>
Expand Down

0 comments on commit b0e59f0

Please sign in to comment.