-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ObservableOrganizationMembersClient.cs
579 lines (526 loc) · 26.1 KB
/
ObservableOrganizationMembersClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
public class ObservableOrganizationMembersClient : IObservableOrganizationMembersClient
{
readonly IOrganizationMembersClient _client;
readonly IConnection _connection;
/// <summary>
/// Initializes a new Organization Members API client.
/// </summary>
/// <param name="client">An <see cref="IGitHubClient" /> used to make the requests</param>
public ObservableOrganizationMembersClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));
_client = client.Organization.Member;
_connection = client.Connection;
}
/// <summary>
/// <para>
/// List all users who are members of an organization. A member is a user that
/// belongs to at least 1 team in the organization.
/// </para>
/// <para>
/// If the authenticated user is also an owner of this organization then both
/// concealed and public member will be returned.
/// </para>
/// <para>
/// If the requester is not an owner of the organization the query will be redirected
/// to the public members list.
/// </para>
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/members/#members-list">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <returns></returns>
public IObservable<User> GetAll(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
return GetAll(org, ApiOptions.None);
}
/// <summary>
/// <para>
/// List all users who are members of an organization. A member is a user that
/// belongs to at least 1 team in the organization.
/// </para>
/// <para>
/// If the authenticated user is also an owner of this organization then both
/// concealed and public member will be returned.
/// </para>
/// <para>
/// If the requester is not an owner of the organization the query will be redirected
/// to the public members list.
/// </para>
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/members/#members-list">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
public IObservable<User> GetAll(string org, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages<User>(ApiUrls.Members(org), options);
}
/// <summary>
/// <para>
/// List all users who are members of an organization. A member is a user that
/// belongs to at least 1 team in the organization.
/// </para>
/// <para>
/// If the authenticated user is also an owner of this organization then both
/// concealed and public member will be returned.
/// </para>
/// <para>
/// If the requester is not an owner of the organization the query will be redirected
/// to the public members list.
/// </para>
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/members/#members-list">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="filter">The members filter, <see cref="OrganizationMembersFilter"/> </param>
/// <returns></returns>
public IObservable<User> GetAll(string org, OrganizationMembersFilter filter)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
return GetAll(org, filter, ApiOptions.None);
}
/// <summary>
/// <para>
/// List all users who are members of an organization. A member is a user that
/// belongs to at least 1 team in the organization.
/// </para>
/// <para>
/// If the authenticated user is also an owner of this organization then both
/// concealed and public member will be returned.
/// </para>
/// <para>
/// If the requester is not an owner of the organization the query will be redirected
/// to the public members list.
/// </para>
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/members/#members-list">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="filter">The members filter, <see cref="OrganizationMembersFilter"/> </param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
public IObservable<User> GetAll(string org, OrganizationMembersFilter filter, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages<User>(ApiUrls.Members(org, filter), options);
}
/// <summary>
/// <para>
/// List all users who are members of an organization. A member is a user that
/// belongs to at least 1 team in the organization.
/// </para>
/// <para>
/// If the authenticated user is also an owner of this organization then both
/// concealed and public member will be returned.
/// </para>
/// <para>
/// If the requester is not an owner of the organization the query will be redirected
/// to the public members list.
/// </para>
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/members/#members-list">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="role">The role filter to use when getting the users, <see cref="OrganizationMembersRole"/></param>
/// <returns></returns>
public IObservable<User> GetAll(string org, OrganizationMembersRole role)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
return GetAll(org, role, ApiOptions.None);
}
/// <summary>
/// <para>
/// List all users who are members of an organization. A member is a user that
/// belongs to at least 1 team in the organization.
/// </para>
/// <para>
/// If the authenticated user is also an owner of this organization then both
/// concealed and public member will be returned.
/// </para>
/// <para>
/// If the requester is not an owner of the organization the query will be redirected
/// to the public members list.
/// </para>
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/members/#members-list">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="role">The role filter to use when getting the users, <see cref="OrganizationMembersRole"/></param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
public IObservable<User> GetAll(string org, OrganizationMembersRole role, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages<User>(ApiUrls.Members(org, role), options);
}
/// <summary>
/// <para>
/// List all users who are members of an organization. A member is a user that
/// belongs to at least 1 team in the organization.
/// </para>
/// <para>
/// If the authenticated user is also an owner of this organization then both
/// concealed and public member will be returned.
/// </para>
/// <para>
/// If the requester is not an owner of the organization the query will be redirected
/// to the public members list.
/// </para>
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/members/#members-list">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="filter">The members filter, <see cref="OrganizationMembersFilter"/> </param>
/// <param name="role">The role filter to use when getting the users, <see cref="OrganizationMembersRole"/></param>
/// <returns></returns>
public IObservable<User> GetAll(string org, OrganizationMembersFilter filter, OrganizationMembersRole role)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
return GetAll(org, filter, role, ApiOptions.None);
}
/// <summary>
/// <para>
/// List all users who are members of an organization. A member is a user that
/// belongs to at least 1 team in the organization.
/// </para>
/// <para>
/// If the authenticated user is also an owner of this organization then both
/// concealed and public member will be returned.
/// </para>
/// <para>
/// If the requester is not an owner of the organization the query will be redirected
/// to the public members list.
/// </para>
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/members/#members-list">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="filter">The members filter, <see cref="OrganizationMembersFilter"/> </param>
/// <param name="role">The role filter to use when getting the users, <see cref="OrganizationMembersRole"/></param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
public IObservable<User> GetAll(string org, OrganizationMembersFilter filter, OrganizationMembersRole role, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages<User>(ApiUrls.Members(org, filter, role), options);
}
/// <summary>
/// List all users who have publicized their membership of the organization.
/// </summary>
/// <remarks>http://developer.github.com/v3/orgs/members/#public-members-list</remarks>
/// <param name="org">The login for the organization</param>
/// <returns></returns>
public IObservable<User> GetAllPublic(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
return GetAllPublic(org, ApiOptions.None);
}
/// <summary>
/// List all users who have publicized their membership of the organization.
/// </summary>
/// <remarks>http://developer.github.com/v3/orgs/members/#public-members-list</remarks>
/// <param name="org">The login for the organization</param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
public IObservable<User> GetAllPublic(string org, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages<User>(ApiUrls.PublicMembers(org), options);
}
/// <summary>
/// Check if a user is, publicly or privately, a member of the organization.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/members/#check-membership">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="user">The login for the user</param>
/// <returns></returns>
public IObservable<bool> CheckMember(string org, string user)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
return _client.CheckMember(org, user).ToObservable();
}
/// <summary>
/// Check is a user is publicly a member of the organization.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/members/#check-public-membership">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="user">The login for the user</param>
/// <returns></returns>
public IObservable<bool> CheckMemberPublic(string org, string user)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
return _client.CheckMemberPublic(org, user).ToObservable();
}
/// <summary>
/// Removes a user from the organization, this will also remove them from all teams
/// within the organization and they will no longer have any access to the organization's
/// repositories.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/members/#remove-a-member">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="user">The login for the user</param>
/// <returns></returns>
public IObservable<Unit> Delete(string org, string user)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
return _client.Delete(org, user).ToObservable();
}
/// <summary>
/// Make the authenticated user's organization membership public.
/// </summary>
/// <remarks>
/// This method requires authentication.
/// See the <a href="http://developer.github.com/v3/orgs/members/#publicize-a-users-membership">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="user">The login for the user</param>
/// <returns></returns>
public IObservable<bool> Publicize(string org, string user)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
return _client.Publicize(org, user).ToObservable();
}
/// <summary>
/// Make the authenticated user's organization membership private.
/// </summary>
/// <remarks>
/// This method requires authentication.
/// See the <a href="http://developer.github.com/v3/orgs/members/#conceal-a-users-membership">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="user">The login for the user</param>
/// <returns></returns>
public IObservable<Unit> Conceal(string org, string user)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
return _client.Conceal(org, user).ToObservable();
}
/// <summary>
/// Get a user's membership with an organization.
/// </summary>
/// <remarks>
/// This method requires authentication.
/// The authenticated user must be an organization member.
/// See the <a href="https://developer.github.com/v3/orgs/members/#get-organization-membership">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="user">The login for the user</param>
/// <returns></returns>
public IObservable<OrganizationMembership> GetOrganizationMembership(string org, string user)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
return _client.GetOrganizationMembership(org, user).ToObservable();
}
/// <summary>
/// Add a user to the organization or update the user's role withing the organization.
/// </summary>
/// <remarks>
/// This method requires authentication.
/// The authenticated user must be an organization owner.
/// See the <a href="https://developer.github.com/v3/orgs/members/#add-or-update-organization-membership">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="user">The login for the user</param>
/// <param name="addOrUpdateRequest">An <see cref="OrganizationMembershipUpdate"/> instance describing the
/// changes to make to the user's organization membership</param>
/// <returns></returns>
public IObservable<OrganizationMembership> AddOrUpdateOrganizationMembership(string org, string user, OrganizationMembershipUpdate addOrUpdateRequest)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
Ensure.ArgumentNotNull(addOrUpdateRequest, nameof(addOrUpdateRequest));
return _client.AddOrUpdateOrganizationMembership(org, user, addOrUpdateRequest).ToObservable();
}
/// <summary>
/// Create an organization invitation for a user
/// </summary>
/// <remarks>
/// This method requires authentication.
/// The authenticated user must be an organization owner.
/// See the <a href="https://developer.github.com/v3/orgs/members/#create-an-organization-invitation">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="invitationRequest">An <see cref="OrganizationInvitationRequest"/> instance containing the
/// details of the organization invitation</param>
/// <returns></returns>
public IObservable<OrganizationMembershipInvitation> CreateOrganizationInvitation(string org, OrganizationInvitationRequest invitationRequest)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(invitationRequest, nameof(invitationRequest));
return _client.CreateOrganizationInvitation(org, invitationRequest).ToObservable();
}
/// <summary>
/// Remove a user's membership with an organization.
/// </summary>
/// <remarks>
/// This method requires authentication.
/// The authenticated user must be an organization owner.
/// See the <a href="https://developer.github.com/v3/orgs/members/#remove-organization-membership">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="user">The login for the user</param>
/// <returns></returns>
public IObservable<Unit> RemoveOrganizationMembership(string org, string user)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
return _client.RemoveOrganizationMembership(org, user).ToObservable();
}
/// <summary>
/// List all pending invitations for the organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/members/#list-pending-organization-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <returns></returns>
public IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
return GetAllPendingInvitations(org, ApiOptions.None);
}
/// <summary>
/// List all pending invitations for the organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/members/#list-pending-organization-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="options">Options to change API behaviour</param>
/// <returns></returns>
public IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(string org, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages<OrganizationMembershipInvitation>(ApiUrls.OrganizationPendingInvitations(org), null, options);
}
/// <summary>
/// List failed organization invitations.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/members#list-failed-organization-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <returns></returns>
public IObservable<OrganizationMembershipInvitation> GetAllFailedInvitations(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
return GetAllFailedInvitations(org, ApiOptions.None);
}
/// <summary>
/// List failed organization invitations.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/members#list-failed-organization-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="options">Options to change API behaviour</param>
/// <returns></returns>
public IObservable<OrganizationMembershipInvitation> GetAllFailedInvitations(string org, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages<OrganizationMembershipInvitation>(ApiUrls.OrganizationFailedInvitations(org), null, options);
}
/// <summary>
/// Cancel an organization invitation. In order to cancel an organization invitation, the authenticated user must be an organization owner.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/orgs/members#cancel-an-organization-invitation">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="invitationId">The unique identifier of the invitation</param>
/// <returns></returns>
[ManualRoute("DELETE", "/orgs/{org}/invitations/{invitation_id}")]
public IObservable<Unit> CancelOrganizationInvitation(string org, int invitationId)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrDefault(invitationId, nameof(invitationId));
return _client.CancelOrganizationInvitation(org, invitationId).ToObservable();
}
/// <summary>
/// Returns all <see cref="OrganizationMembership" />s for the current user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/orgs/members#list-organization-memberships-for-the-authenticated-user">API Documentation</a>
/// for more information.
/// </remarks>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
public IObservable<OrganizationMembership> GetAllOrganizationMembershipsForCurrent()
{
return _connection.GetAndFlattenAllPages<OrganizationMembership>(ApiUrls.UserOrganizationMemberships());
}
/// <summary>
/// Returns all <see cref="OrganizationMembership" />s for the current user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/orgs/members#list-organization-memberships-for-the-authenticated-user">API Documentation</a>
/// for more information.
/// </remarks>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <param name="options">Options to change API behaviour</param>
/// <returns></returns>
public IObservable<OrganizationMembership> GetAllOrganizationMembershipsForCurrent(ApiOptions options)
{
return _connection.GetAndFlattenAllPages<OrganizationMembership>(ApiUrls.UserOrganizationMemberships(), options);
}
}
}