• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Jericho / ZoomNet / 834

15 Nov 2024 03:18PM UTC coverage: 20.194% (-0.2%) from 20.435%
834

push

appveyor

Jericho
Merge branch 'release/0.84.0'

645 of 3194 relevant lines covered (20.19%)

11.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.78
/Source/ZoomNet/Resources/Users.cs
1
using Pathoschild.Http.Client;
2
using System;
3
using System.Collections.Generic;
4
using System.IO;
5
using System.Linq;
6
using System.Net.Http;
7
using System.Text.Json.Nodes;
8
using System.Threading;
9
using System.Threading.Tasks;
10
using ZoomNet.Models;
11

12
namespace ZoomNet.Resources
13
{
14
        /// <inheritdoc/>
15
        public class Users : IUsers
16
        {
17
                private readonly IClient _client;
18

19
                /// <summary>
20
                /// Initializes a new instance of the <see cref="Users" /> class.
21
                /// </summary>
22
                /// <param name="client">The HTTP client.</param>
23
                internal Users(IClient client)
24
                {
25
                        _client = client;
2✔
26
                }
2✔
27

28
                /// <inheritdoc/>
29
                [Obsolete("Zoom is in the process of deprecating the \"page number\" and \"page count\" fields.")]
30
                public Task<PaginatedResponse<User>> GetAllAsync(UserStatus status = UserStatus.Active, string roleId = null, int recordsPerPage = 30, int page = 1, CancellationToken cancellationToken = default)
31
                {
32
                        if (recordsPerPage < 1 || recordsPerPage > 300)
33
                        {
34
                                throw new ArgumentOutOfRangeException(nameof(recordsPerPage), "Records per page must be between 1 and 300");
35
                        }
36

37
                        return _client
38
                                .GetAsync($"users")
39
                                .WithArgument("status", status.ToEnumString())
40
                                .WithArgument("role_id", roleId)
41
                                .WithArgument("page_size", recordsPerPage)
42
                                .WithArgument("page_number", page)
43
                                .WithCancellationToken(cancellationToken)
44
                                .AsPaginatedResponse<User>("users");
45
                }
46

47
                /// <inheritdoc/>
48
                public Task<PaginatedResponseWithToken<User>> GetAllAsync(UserStatus status = UserStatus.Active, string roleId = null, int recordsPerPage = 30, string pagingToken = null, CancellationToken cancellationToken = default)
49
                {
50
                        if (recordsPerPage < 1 || recordsPerPage > 300)
×
51
                        {
52
                                throw new ArgumentOutOfRangeException(nameof(recordsPerPage), "Records per page must be between 1 and 300");
×
53
                        }
54

55
                        return _client
×
56
                                .GetAsync($"users")
×
57
                                .WithArgument("status", status.ToEnumString())
×
58
                                .WithArgument("role_id", roleId)
×
59
                                .WithArgument("page_size", recordsPerPage)
×
60
                                .WithArgument("next_page_token", pagingToken)
×
61
                                .WithCancellationToken(cancellationToken)
×
62
                                .AsPaginatedResponseWithToken<User>("users");
×
63
                }
64

65
                /// <inheritdoc/>
66
                public Task<User> CreateAsync(string email, string firstName = null, string lastName = null, string password = null, UserType type = UserType.Basic, UserCreateType createType = UserCreateType.Normal, CancellationToken cancellationToken = default)
67
                {
68
                        var data = new JsonObject
×
69
                        {
×
70
                                { "action", createType.ToEnumString() },
×
71
                                {
×
72
                                        "user_info", new JsonObject
×
73
                                        {
×
74
                                                { "email", email },
×
75
                                                { "type", type },
×
76
                                                { "first_name", firstName },
×
77
                                                { "last_name", lastName },
×
78
                                                { "password", password }
×
79
                                        }
×
80
                                }
×
81
                        };
×
82

83
                        return _client
×
84
                                .PostAsync("users")
×
85
                                .WithJsonBody(data)
×
86
                                .WithCancellationToken(cancellationToken)
×
87
                                .AsObject<User>();
×
88
                }
89

90
                /// <inheritdoc/>
91
                public Task UpdateAsync(string userId, string firstName = null, string lastName = null, string company = null, string department = null, string groupId = null, string hostKey = null, string jobTitle = null, string language = null, string location = null, string manager = null, IEnumerable<PhoneNumber> phoneNumbers = null, string pmi = null, string pronouns = null, PronounDisplayType? pronounsDisplay = null, TimeZones? timezone = null, UserType? type = null, bool? usePmi = null, string personalMeetingRoomName = null, IEnumerable<CustomAttribute> customAttributes = null, CancellationToken cancellationToken = default)
92
                {
93
                        var data = new JsonObject
×
94
                        {
×
95
                                { "company", company },
×
96
                                { "dept", department },
×
97
                                { "first_name", firstName },
×
98
                                { "group_id", groupId },
×
99
                                { "host_key", hostKey },
×
100
                                { "job_title", jobTitle },
×
101
                                { "language", language },
×
102
                                { "last_name", lastName },
×
103
                                { "location", location },
×
104
                                { "manager", manager },
×
105
                                { "phone_numbers", phoneNumbers?.ToArray() },
×
106
                                { "pmi", pmi },
×
107
                                { "pronouns", pronouns },
×
108
                                { "pronouns_option", pronounsDisplay?.ToEnumString() },
×
109
                                { "timezone", timezone?.ToEnumString() },
×
110
                                { "type", type },
×
111
                                { "use_pmi", usePmi },
×
112
                                { "vanity_name", personalMeetingRoomName },
×
113
                                { "custom_attributes", customAttributes?.ToArray() }
×
114
                        };
×
115

116
                        return _client
×
117
                                .PatchAsync($"users/{userId}")
×
118
                                .WithJsonBody(data)
×
119
                                .WithCancellationToken(cancellationToken)
×
120
                                .AsMessage();
×
121
                }
122

123
                /// <inheritdoc/>
124
                public Task<User> GetAsync(string userId, CancellationToken cancellationToken = default)
125
                {
126
                        return _client
×
127
                                .GetAsync($"users/{userId}")
×
128
                                .WithCancellationToken(cancellationToken)
×
129
                                .AsObject<User>();
×
130
                }
131

132
                /// <inheritdoc/>
133
                public Task DeleteAsync(string userId, string transferEmail, bool transferMeetings, bool transferWebinars, bool transferRecordings, CancellationToken cancellationToken = default)
134
                {
135
                        return _client
×
136
                                .DeleteAsync($"users/{userId}")
×
137
                                .WithArgument("action", "delete")
×
138
                                .WithArgument("transfer_email", transferEmail)
×
139
                                .WithArgument("transfer_meetings", transferMeetings.ToString().ToLowerInvariant())
×
140
                                .WithArgument("transfer_webinars", transferWebinars.ToString().ToLowerInvariant())
×
141
                                .WithArgument("transfer_recordings", transferRecordings.ToString().ToLowerInvariant())
×
142
                                .WithCancellationToken(cancellationToken)
×
143
                                .AsMessage();
×
144
                }
145

146
                /// <inheritdoc/>
147
                public Task DisassociateAsync(string userId, string transferEmail, bool transferMeetings, bool transferWebinars, bool transferRecordings, CancellationToken cancellationToken = default)
148
                {
149
                        return _client
×
150
                                .DeleteAsync($"users/{userId}")
×
151
                                .WithArgument("action", "disassociate")
×
152
                                .WithArgument("transfer_email", transferEmail)
×
153
                                .WithArgument("transfer_meetings", transferMeetings.ToString().ToLowerInvariant())
×
154
                                .WithArgument("transfer_webinars", transferWebinars.ToString().ToLowerInvariant())
×
155
                                .WithArgument("transfer_recordings", transferRecordings.ToString().ToLowerInvariant())
×
156
                                .WithCancellationToken(cancellationToken)
×
157
                                .AsMessage();
×
158
                }
159

160
                /// <inheritdoc/>
161
                public Task<Assistant[]> GetAssistantsAsync(string userId, CancellationToken cancellationToken = default)
162
                {
163
                        return _client
×
164
                                .GetAsync($"users/{userId}/assistants")
×
165
                                .WithCancellationToken(cancellationToken)
×
166
                                .AsObject<Assistant[]>("assistants");
×
167
                }
168

169
                /// <inheritdoc/>
170
                public Task AddAssistantsByIdAsync(string userId, IEnumerable<string> assistantIds, CancellationToken cancellationToken = default)
171
                {
172
                        if (assistantIds == null || !assistantIds.Any()) throw new ArgumentNullException(nameof(assistantIds), "You must provide at least one assistant Id.");
×
173

174
                        var data = new JsonObject
×
175
                        {
×
176
                                { "assistants", assistantIds.Select(id => new JsonObject { { "id", id } }).ToArray() }
×
177
                        };
×
178

179
                        return _client
×
180
                                .PostAsync($"users/{userId}/assistants")
×
181
                                .WithJsonBody(data)
×
182
                                .WithCancellationToken(cancellationToken)
×
183
                                .AsMessage();
×
184
                }
185

186
                /// <inheritdoc/>
187
                public Task AddAssistantsByEmailAsync(string userId, IEnumerable<string> assistantEmails, CancellationToken cancellationToken = default)
188
                {
189
                        if (assistantEmails == null || !assistantEmails.Any()) throw new ArgumentNullException(nameof(assistantEmails), "You must provide at least one assistant email address.");
×
190

191
                        var data = new JsonObject
×
192
                        {
×
193
                                { "assistants", assistantEmails.Select(id => new JsonObject { { "email", id } }).ToArray() }
×
194
                        };
×
195

196
                        return _client
×
197
                                .PostAsync($"users/{userId}/assistants")
×
198
                                .WithJsonBody(data)
×
199
                                .WithCancellationToken(cancellationToken)
×
200
                                .AsMessage();
×
201
                }
202

203
                /// <inheritdoc/>
204
                public Task DeleteAssistantAsync(string userId, string assistantId, CancellationToken cancellationToken = default)
205
                {
206
                        return _client
×
207
                                .DeleteAsync($"users/{userId}/assistants/{assistantId}")
×
208
                                .WithCancellationToken(cancellationToken)
×
209
                                .AsMessage();
×
210
                }
211

212
                /// <inheritdoc/>
213
                public Task DeleteAllAssistantsAsync(string userId, CancellationToken cancellationToken = default)
214
                {
215
                        return _client
×
216
                                .DeleteAsync($"users/{userId}/assistants")
×
217
                                .WithCancellationToken(cancellationToken)
×
218
                                .AsMessage();
×
219
                }
220

221
                /// <inheritdoc/>
222
                public Task<Assistant[]> GetSchedulersAsync(string userId, CancellationToken cancellationToken = default)
223
                {
224
                        return _client
×
225
                                .GetAsync($"users/{userId}/schedulers")
×
226
                                .WithCancellationToken(cancellationToken)
×
227
                                .AsObject<Assistant[]>("schedulers");
×
228
                }
229

230
                /// <inheritdoc/>
231
                public Task DeleteSchedulerAsync(string userId, string assistantId, CancellationToken cancellationToken = default)
232
                {
233
                        return _client
×
234
                                .DeleteAsync($"users/{userId}/schedulers/{assistantId}")
×
235
                                .WithCancellationToken(cancellationToken)
×
236
                                .AsMessage();
×
237
                }
238

239
                /// <inheritdoc/>
240
                public Task DeleteAllSchedulersAsync(string userId, CancellationToken cancellationToken = default)
241
                {
242
                        return _client
×
243
                                .DeleteAsync($"users/{userId}/schedulers")
×
244
                                .WithCancellationToken(cancellationToken)
×
245
                                .AsMessage();
×
246
                }
247

248
                /// <inheritdoc/>
249
                public Task UploadProfilePictureAsync(string userId, string fileName, Stream pictureData, CancellationToken cancellationToken = default)
250
                {
251
                        return _client
×
252
                                .PostAsync($"users/{userId}/picture")
×
253
                                .WithBody(bodyBuilder =>
×
254
                                {
×
255
                                        var content = new MultipartFormDataContent();
×
256

×
257
                                        // Zoom requires the 'name' to be 'pic_file'. Also, you
×
258
                                        // must specify the 'fileName' otherwise Zoom will return
×
259
                                        // a very confusing HTTP 400 error with the following body:
×
260
                                        // {"code":120,"message":""}
×
261
                                        content.Add(new StreamContent(pictureData), "pic_file", fileName);
×
262

×
263
                                        return content;
×
264
                                })
×
265
                                .WithCancellationToken(cancellationToken)
×
266
                                .AsMessage();
×
267
                }
268

269
                /// <inheritdoc/>
270
                public Task DeleteProfilePictureAsync(string userId, CancellationToken cancellationToken = default)
271
                {
272
                        return _client
×
273
                                .DeleteAsync($"users/{userId}/picture")
×
274
                                .WithCancellationToken(cancellationToken)
×
275
                                .AsMessage();
×
276
                }
277

278
                /// <inheritdoc/>
279
                public Task<UserSettings> GetSettingsAsync(string userId, CancellationToken cancellationToken = default)
280
                {
281
                        return _client
×
282
                                .GetAsync($"users/{userId}/settings")
×
283
                                .WithCancellationToken(cancellationToken)
×
284
                                .AsObject<UserSettings>();
×
285
                }
286

287
                /// <inheritdoc/>
288
                public async Task<AuthenticationSettings> GetMeetingAuthenticationSettingsAsync(string userId, CancellationToken cancellationToken = default)
289
                {
290
                        var response = await _client
291
                                .GetAsync($"users/{userId}/settings")
292
                                .WithArgument("option", "meeting_authentication")
293
                                .WithCancellationToken(cancellationToken)
294
                                .AsJson()
295
                                .ConfigureAwait(false);
296

297
                        var settings = new AuthenticationSettings()
298
                        {
299
                                RequireAuthentication = response.GetPropertyValue("meeting_authentication", false),
300
                                AuthenticationOptions = response.GetProperty("authentication_options", false)?.ToObject<AuthenticationOptions[]>() ?? Array.Empty<AuthenticationOptions>()
301
                        };
302

303
                        return settings;
304
                }
305

306
                /// <inheritdoc/>
307
                public async Task<AuthenticationSettings> GetRecordingAuthenticationSettingsAsync(string userId, CancellationToken cancellationToken = default)
308
                {
309
                        var response = await _client
310
                                .GetAsync($"users/{userId}/settings")
311
                                .WithArgument("option", "recording_authentication")
312
                                .WithCancellationToken(cancellationToken)
313
                                .AsJson()
314
                                .ConfigureAwait(false);
315

316
                        var settings = new AuthenticationSettings()
317
                        {
318
                                RequireAuthentication = response.GetPropertyValue("recording_authentication", false),
319
                                AuthenticationOptions = response.GetProperty("authentication_options", false)?.ToObject<AuthenticationOptions[]>() ?? Array.Empty<AuthenticationOptions>()
320
                        };
321

322
                        return settings;
323
                }
324

325
                /// <inheritdoc/>
326
                public Task<SecuritySettings> GetSecuritySettingsAsync(string userId, CancellationToken cancellationToken = default)
327
                {
328
                        return _client
×
329
                                .GetAsync($"users/{userId}/settings")
×
330
                                .WithArgument("option", "meeting_security")
×
331
                                .WithCancellationToken(cancellationToken)
×
332
                                .AsObject<SecuritySettings>("meeting_security");
×
333
                }
334

335
                /// <inheritdoc/>
336
                public Task DeactivateAsync(string userId, CancellationToken cancellationToken = default)
337
                {
338
                        var data = new JsonObject
×
339
                        {
×
340
                                { "action", "deactivate" }
×
341
                        };
×
342

343
                        return _client
×
344
                                .PutAsync($"users/{userId}/status")
×
345
                                .WithJsonBody(data)
×
346
                                .WithCancellationToken(cancellationToken)
×
347
                                .AsMessage();
×
348
                }
349

350
                /// <inheritdoc/>
351
                public Task ReactivateAsync(string userId, CancellationToken cancellationToken = default)
352
                {
353
                        var data = new JsonObject
×
354
                        {
×
355
                                { "action", "activate" }
×
356
                        };
×
357

358
                        return _client
×
359
                                .PutAsync($"users/{userId}/status")
×
360
                                .WithJsonBody(data)
×
361
                                .WithCancellationToken(cancellationToken)
×
362
                                .AsMessage();
×
363
                }
364

365
                /// <inheritdoc/>
366
                public Task ChangePasswordAsync(string userId, string password, CancellationToken cancellationToken = default)
367
                {
368
                        var data = new JsonObject
×
369
                        {
×
370
                                { "password", password }
×
371
                        };
×
372

373
                        return _client
×
374
                                .PutAsync($"users/{userId}/password")
×
375
                                .WithJsonBody(data)
×
376
                                .WithCancellationToken(cancellationToken)
×
377
                                .AsMessage();
×
378
                }
379

380
                /// <inheritdoc/>
381
                public Task<string[]> GetPermissionsAsync(string userId, CancellationToken cancellationToken = default)
382
                {
383
                        return _client
×
384
                                .GetAsync($"users/{userId}/permissions")
×
385
                                .WithCancellationToken(cancellationToken)
×
386
                                .AsObject<string[]>("permissions");
×
387
                }
388

389
                /// <inheritdoc/>
390
                public Task RevokeSsoTokenAsync(string userId, CancellationToken cancellationToken = default)
391
                {
392
                        return _client
×
393
                                .DeleteAsync($"users/{userId}/token")
×
394
                                .WithCancellationToken(cancellationToken)
×
395
                                .AsMessage();
×
396
                }
397

398
                /// <inheritdoc/>
399
                public Task<bool> CheckEmailInUseAsync(string email, CancellationToken cancellationToken = default)
400
                {
401
                        return _client
×
402
                                .GetAsync($"users/email")
×
403
                                .WithArgument("email", email)
×
404
                                .WithCancellationToken(cancellationToken)
×
405
                                .AsObject<bool>("existed_email");
×
406
                }
407

408
                /// <inheritdoc/>
409
                public Task ChangeEmailAsync(string userId, string email, CancellationToken cancellationToken = default)
410
                {
411
                        var data = new JsonObject
×
412
                        {
×
413
                                { "email", email }
×
414
                        };
×
415

416
                        return _client
×
417
                                .PutAsync($"users/{userId}/email")
×
418
                                .WithJsonBody(data)
×
419
                                .WithCancellationToken(cancellationToken)
×
420
                                .AsMessage();
×
421
                }
422

423
                /// <inheritdoc/>
424
                public Task<bool> CheckPersonalMeetingRoomNameInUseAsync(string name, CancellationToken cancellationToken = default)
425
                {
426
                        return _client
×
427
                                .GetAsync($"users/vanity_name")
×
428
                                .WithArgument("vanity_name", name)
×
429
                                .WithCancellationToken(cancellationToken)
×
430
                                .AsObject<bool>("existed");
×
431
                }
432

433
                /// <inheritdoc/>
434
                public Task SwitchAccountAsync(string userId, string currentAccountId, string newAccountId, CancellationToken cancellationToken = default)
435
                {
436
                        var data = new JsonObject
×
437
                        {
×
438
                                { "account_id", newAccountId }
×
439
                        };
×
440

441
                        return _client
×
442
                                .PutAsync($"accounts/{currentAccountId}/users/{userId}/account")
×
443
                                .WithJsonBody(data)
×
444
                                .WithCancellationToken(cancellationToken)
×
445
                                .AsMessage();
×
446
                }
447

448
                /// <inheritdoc/>
449
                public Task<string> GetAccessTokenAsync(string userId, int? ttl = null, CancellationToken cancellationToken = default)
450
                {
451
                        return _client
×
452
                                .GetAsync($"users/{userId}/token")
×
453
                                .WithArgument("type", "zak")
×
454
                                .WithArgument("ttl", ttl)
×
455
                                .WithCancellationToken(cancellationToken)
×
456
                                .AsObject<string>("token");
×
457
                }
458

459
                /// <inheritdoc/>
460
                public Task<VirtualBackgroundFile> UploadVirtualBackgroundAsync(string userId, string fileName, Stream pictureData, CancellationToken cancellationToken = default)
461
                {
462
                        return _client
×
463
                                .PostAsync($"users/{userId}/settings/virtual_backgrounds")
×
464
                                .WithBody(bodyBuilder =>
×
465
                                {
×
466
                                        var content = new MultipartFormDataContent();
×
467

×
468
                                        // Zoom requires the 'name' to be 'file'. Also, you
×
469
                                        // must specify the 'fileName' otherwise Zoom will return
×
470
                                        // a very confusing HTTP 400 error with the following body:
×
471
                                        // {"code":-1,"message":"Required request part 'file' is not present"}
×
472
                                        content.Add(new StreamContent(pictureData), "file", fileName);
×
473

×
474
                                        return content;
×
475
                                })
×
476
                                .WithCancellationToken(cancellationToken)
×
477
                                .AsObject<VirtualBackgroundFile>();
×
478
                }
479

480
                /// <inheritdoc/>
481
                public Task DeleteVirtualBackgroundAsync(string userId, string fileId, CancellationToken cancellationToken = default)
482
                {
483
                        return _client
×
484
                                .DeleteAsync($"users/{userId}/settings/virtual_backgrounds")
×
485
                                .WithArgument("file_ids", fileId)
×
486
                                .WithCancellationToken(cancellationToken)
×
487
                                .AsMessage();
×
488
                }
489

490
                /// <inheritdoc/>
491
                public Task UpdatePresenceStatusAsync(string userId, PresenceStatus status, int? duration = null, CancellationToken cancellationToken = default)
492
                {
493
                        if (status == PresenceStatus.Unknown) throw new ArgumentOutOfRangeException(nameof(status), "You can not change a user's status to Unknown.");
×
494

495
                        var data = new JsonObject
×
496
                        {
×
497
                                { "status", status.ToEnumString() }
×
498
                        };
×
499
                        if (status == PresenceStatus.DoNotDisturb) data.Add("duration", duration);
×
500

501
                        return _client
×
502
                                .PutAsync($"users/{userId}/presence_status")
×
503
                                .WithJsonBody(data)
×
504
                                .WithCancellationToken(cancellationToken)
×
505
                                .AsMessage();
×
506
                }
507

508
                /// <inheritdoc/>
509
                public Task<PresenceStatusResponse> GetPresenceStatusAsync(string userId, CancellationToken cancellationToken = default)
510
                {
511
                        return _client
×
512
                                .GetAsync($"users/{userId}/presence_status")
×
513
                                .WithCancellationToken(cancellationToken)
×
514
                                .AsObject<PresenceStatusResponse>();
×
515
                }
516
        }
517
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc