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

rwjdk / TrelloDotNet / 15361499730

31 May 2025 07:28AM UTC coverage: 80.301% (-0.1%) from 80.419%
15361499730

push

github

rwjdk
AI Review of ReadMe

2535 of 3449 branches covered (73.5%)

Branch coverage included in aggregate %.

4460 of 5262 relevant lines covered (84.76%)

102.52 hits per line

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

97.26
/src/TrelloDotNet/TrelloClient.Members.cs
1
using System.Collections.Generic;
2
using System.Diagnostics.CodeAnalysis;
3
using System.Linq;
4
using System.Threading;
5
using System.Threading.Tasks;
6
using TrelloDotNet.Control;
7
using TrelloDotNet.Model;
8
using TrelloDotNet.Model.Options.GetMemberOptions;
9

10
// ReSharper disable UnusedMember.Global
11

12
namespace TrelloDotNet
13
{
14
    public partial class TrelloClient
15
    {
16
        /// <summary>
17
        /// Get the Members (users) of a board
18
        /// </summary>
19
        /// <param name="boardId">Id of the Board (in its long or short version)</param>
20
        /// <param name="cancellationToken">Cancellation Token</param>
21
        /// <returns>List of Members</returns>
22
        public async Task<List<Member>> GetMembersOfBoardAsync(string boardId, CancellationToken cancellationToken = default)
23
        {
24
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersOfBoard(boardId), cancellationToken);
26✔
25
        }
26✔
26

27
        /// <summary>
28
        /// Get the Members (users) of a board
29
        /// </summary>
30
        /// <param name="boardId">Id of the Board (in its long or short version)</param>
31
        /// <param name="options">Option for what data to include on the Member</param>
32
        /// <param name="cancellationToken">Cancellation Token</param>
33
        /// <returns>List of Members</returns>
34
        public async Task<List<Member>> GetMembersOfBoardAsync(string boardId, GetMemberOptions options, CancellationToken cancellationToken = default)
35
        {
36
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersOfBoard(boardId), cancellationToken, options.GetParameters());
1✔
37
        }
1✔
38

39
        /// <summary>
40
        /// Get the Members (users) who voted on a Card
41
        /// </summary>
42
        /// <param name="cardId">Id of the Card</param>
43
        /// <param name="cancellationToken">Cancellation Token</param>
44
        /// <returns>List of Members who voted</returns>
45
        public async Task<List<Member>> GetMembersWhoVotedOnCardAsync(string cardId, CancellationToken cancellationToken = default)
46
        {
47
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersWhoVotedOnOfCard(cardId), cancellationToken);
1✔
48
        }
1✔
49

50
        /// <summary>
51
        /// Get the Members (users) who voted on a Card
52
        /// </summary>
53
        /// <param name="cardId">Id of the Card</param>
54
        /// <param name="options">Option for what data to include on the Member</param>
55
        /// <param name="cancellationToken">Cancellation Token</param>
56
        /// <returns>List of Members who voted</returns>
57
        public async Task<List<Member>> GetMembersWhoVotedOnCardAsync(string cardId, GetMemberOptions options, CancellationToken cancellationToken = default)
58
        {
59
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersWhoVotedOnOfCard(cardId), cancellationToken, options.GetParameters());
1✔
60
        }
1✔
61

62
        /// <summary>
63
        /// Get the Members (users) of a Card
64
        /// </summary>
65
        /// <param name="cardId">Id of the Card</param>
66
        /// <param name="cancellationToken">Cancellation Token</param>
67
        /// <returns>List of Members</returns>
68
        public async Task<List<Member>> GetMembersOfCardAsync(string cardId, CancellationToken cancellationToken = default)
69
        {
70
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersOfCard(cardId), cancellationToken);
2✔
71
        }
2✔
72

73
        /// <summary>
74
        /// Get the Members (users) of a Card
75
        /// </summary>
76
        /// <param name="cardId">Id of the Card</param>
77
        /// <param name="options">Option for what data to include on the Member</param>
78
        /// <param name="cancellationToken">Cancellation Token</param>
79
        /// <returns>List of Members</returns>
80
        public async Task<List<Member>> GetMembersOfCardAsync(string cardId, GetMemberOptions options, CancellationToken cancellationToken = default)
81
        {
82
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersOfCard(cardId), cancellationToken, options.GetParameters());
1✔
83
        }
1✔
84

85
        /// <summary>
86
        /// Get a Member with a specific Id
87
        /// </summary>
88
        /// <param name="memberId">Id of the Member</param>
89
        /// <param name="cancellationToken">Cancellation Token</param>
90
        /// <returns>The Member</returns>
91
        public async Task<Member> GetMemberAsync(string memberId, CancellationToken cancellationToken = default)
92
        {
93
            return await _apiRequestController.Get<Member>(GetUrlBuilder.GetMember(memberId), cancellationToken);
1✔
94
        }
1✔
95

96
        /// <summary>
97
        /// Add one or more Members to a Card
98
        /// </summary>
99
        /// <param name="cardId">Id of the Card</param>
100
        /// <param name="memberIdsToAdd">One or more Ids of Members to add</param>
101
        public async Task<Card> AddMembersToCardAsync(string cardId, params string[] memberIdsToAdd)
102
        {
103
            return await AddMembersToCardAsync(cardId, CancellationToken.None, memberIdsToAdd);
15✔
104
        }
15✔
105

106
        /// <summary>
107
        /// Add one or more Members to a Card
108
        /// </summary>
109
        /// <param name="cardId">Id of the Card</param>
110
        /// <param name="cancellationToken">Cancellation Token</param>
111
        /// <param name="memberIdsToAdd">One or more Ids of Members to add</param>
112
        public async Task<Card> AddMembersToCardAsync(string cardId, CancellationToken cancellationToken = default, params string[] memberIdsToAdd)
113
        {
114
            var card = await GetCardAsync(cardId, cancellationToken);
15✔
115
            var missing = memberIdsToAdd.Where(x => !card.MemberIds.Contains(x)).ToList();
30✔
116

117
            if (missing.Count == 0)
15✔
118
            {
119
                return card; //Everyone already There
1✔
120
            }
121

122
            //Need update
123
            card.MemberIds.AddRange(missing);
14✔
124
            return await UpdateCardAsync(cardId, new List<CardUpdate>
14✔
125
            {
14✔
126
                CardUpdate.Members(card.MemberIds.Distinct().ToList())
14✔
127
            }, cancellationToken);
14✔
128
        }
15✔
129

130
        /// <summary>
131
        /// Remove a Member of a Card
132
        /// </summary>
133
        /// <param name="cardId">Id of the Card</param>
134
        /// <param name="memberIdsToRemove">One or more Ids of Members to remove</param>
135
        public async Task<Card> RemoveMembersFromCardAsync(string cardId, params string[] memberIdsToRemove)
136
        {
137
            return await RemoveMembersFromCardAsync(cardId, CancellationToken.None, memberIdsToRemove);
3✔
138
        }
3✔
139

140
        /// <summary>
141
        /// Remove one or more Members from a Card
142
        /// </summary>
143
        /// <param name="cardId">Id of the Card</param>
144
        /// <param name="cancellationToken">Cancellation Token</param>
145
        /// <param name="memberIdsToRemove">One or more Ids of Members to remove</param>
146
        public async Task<Card> RemoveMembersFromCardAsync(string cardId, CancellationToken cancellationToken = default, params string[] memberIdsToRemove)
147
        {
148
            var card = await GetCardAsync(cardId, cancellationToken);
3✔
149
            var toRemove = memberIdsToRemove.Where(x => card.MemberIds.Contains(x)).ToList();
6✔
150
            if (toRemove.Count == 0)
3✔
151
            {
152
                return card; //Everyone not there
1✔
153
            }
154

155
            //Need update
156
            card.MemberIds = card.MemberIds.Except(toRemove).ToList();
2✔
157
            return await UpdateCardAsync(cardId, new List<CardUpdate>
2✔
158
            {
2✔
159
                CardUpdate.Members(card.MemberIds.Distinct().ToList())
2✔
160
            }, cancellationToken);
2✔
161
        }
3✔
162

163
        /// <summary>
164
        /// Remove all Members from a Card
165
        /// </summary>
166
        /// <param name="cardId">Id of the Card</param>
167
        /// <param name="cancellationToken">Cancellation Token</param>
168
        public async Task<Card> RemoveAllMembersFromCardAsync(string cardId, CancellationToken cancellationToken = default)
169
        {
170
            return await UpdateCardAsync(cardId, new List<CardUpdate>
2✔
171
            {
2✔
172
                CardUpdate.Members(new List<string>())
2✔
173
            }, cancellationToken);
2✔
174
        }
2✔
175

176
        /// <summary>
177
        /// Add a Member to a board (aka give them access)
178
        /// </summary>
179
        /// <param name="boardId">Id of the Board to give access to</param>
180
        /// <param name="memberId">Id of the Member that need access</param>
181
        /// <param name="membershipType">What type of access the member should be given</param>
182
        /// <param name="allowBillableGuest">Optional param that allows organization admins to add multi-board guests onto a board.</param>
183
        /// <param name="cancellationToken">Cancellation Token</param>
184
        public async Task AddMemberToBoardAsync(string boardId, string memberId, MembershipType membershipType, bool allowBillableGuest = false, CancellationToken cancellationToken = default)
185
        {
186
            await _apiRequestController.Put($"{UrlPaths.Boards}/{boardId}/{UrlPaths.Members}/{memberId}", cancellationToken, 0,
1✔
187
                new QueryParameter("type", membershipType.GetJsonPropertyName()),
1✔
188
                new QueryParameter("allowBillableGuest", allowBillableGuest));
1✔
189
        }
1✔
190

191
        /// <summary>
192
        /// Invite a Member to a board via email (aka give them access)
193
        /// </summary>
194
        /// <param name="boardId">Id of the Board to give access to</param>
195
        /// <param name="email">Email to invite</param>
196
        /// <param name="membershipType">What type of access the member should be given</param>
197
        /// <param name="cancellationToken">Cancellation Token</param>
198
        public async Task InviteMemberToBoardViaEmailAsync(string boardId, string email, MembershipType membershipType, CancellationToken cancellationToken = default)
199
        {
200
            if (membershipType == MembershipType.Admin)
1!
201
            {
202
                throw new TrelloApiException($"It is not possible in the API to invite a member as 'Admin'. Instead invite as Normal and once they have accepted and email is confirmed, use '{nameof(UpdateMembershipTypeOfMemberOnBoardAsync)}' to promote them to Admin");
×
203
            }
204

205
            await _apiRequestController.Put($"{UrlPaths.Boards}/{boardId}/{UrlPaths.Members}", cancellationToken, 0,
1✔
206
                new QueryParameter("type", membershipType.GetJsonPropertyName()),
1✔
207
                new QueryParameter("email", email));
1✔
208
        }
1✔
209

210
        /// <summary>
211
        /// Remove a Member from a board (aka revoke access)
212
        /// </summary>
213
        /// <param name="boardId">Id of the Board the member should be removed from</param>
214
        /// <param name="memberId">Id of the Member that should be removed</param>
215
        /// <param name="cancellationToken">Cancellation Token</param>
216
        public async Task RemoveMemberFromBoardAsync(string boardId, string memberId, CancellationToken cancellationToken = default)
217
        {
218
            await _apiRequestController.Delete($"{UrlPaths.Boards}/{boardId}/{UrlPaths.Members}/{memberId}", cancellationToken, 0);
1✔
219
        }
1✔
220

221
        /// <summary>
222
        /// Get information about the Member that owns the token used by this TrelloClient
223
        /// </summary>
224
        /// <returns>The Member</returns>
225
        public async Task<Member> GetTokenMemberAsync(CancellationToken cancellationToken = default)
226
        {
227
            return await _apiRequestController.Get<Member>(GetUrlBuilder.GetTokenMember(_apiRequestController.Token), cancellationToken);
23✔
228
        }
23✔
229

230
        /// <summary>
231
        /// Get information about the Member that owns the token used by this TrelloClient
232
        /// <param name="options">Option for what data to include on the Member</param>
233
        /// <param name="cancellationToken">Cancellation Token</param>
234
        /// </summary>
235
        /// <returns>The Member</returns>
236
        public async Task<Member> GetTokenMemberAsync(GetMemberOptions options, CancellationToken cancellationToken = default)
237
        {
238
            return await _apiRequestController.Get<Member>(GetUrlBuilder.GetTokenMember(_apiRequestController.Token), cancellationToken, options.GetParameters());
1✔
239
        }
1✔
240

241
        /// <summary>
242
        /// Get the Members (users) of an Organization (aka Workspace)
243
        /// </summary>
244
        /// <param name="organizationId">Id of the Organization</param>
245
        /// <param name="cancellationToken">Cancellation Token</param>
246
        /// <returns>List of Members</returns>
247
        public async Task<List<Member>> GetMembersOfOrganizationAsync(string organizationId, CancellationToken cancellationToken = default)
248
        {
249
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersOfOrganization(organizationId), cancellationToken);
1✔
250
        }
1✔
251

252
        /// <summary>
253
        /// Get the Members (users) of an Organization (aka Workspace)
254
        /// </summary>
255
        /// <param name="organizationId">Id of the Organization</param>
256
        /// <param name="options">Option for what data to include on the Member</param>
257
        /// <param name="cancellationToken">Cancellation Token</param>
258
        /// <returns>List of Members</returns>
259
        public async Task<List<Member>> GetMembersOfOrganizationAsync(string organizationId, GetMemberOptions options, CancellationToken cancellationToken = default)
260
        {
261
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersOfOrganization(organizationId), cancellationToken, options.GetParameters());
1✔
262
        }
1✔
263

264
        /// <summary>
265
        /// Add a member vote to a card
266
        /// </summary>
267
        /// <param name="cardId">The cardId to add the vote to</param>
268
        /// <param name="memberId">The id of the member that cast the vote</param>
269
        /// <param name="cancellationToken">Cancellation Token</param>
270
        public async Task AddVoteToCardAsync(string cardId, string memberId, CancellationToken cancellationToken = default)
271
        {
272
            await _apiRequestController.Post($"{UrlPaths.Cards}/{cardId}/membersVoted", cancellationToken, 0, new QueryParameter("value", memberId));
1✔
273
        }
1✔
274

275
        /// <summary>
276
        /// Remove a member vote from a card
277
        /// </summary>
278
        /// <param name="cardId">The cardId to add the vote to</param>
279
        /// <param name="memberId">The id of the member that cast the vote</param>
280
        /// <param name="cancellationToken">Cancellation Token</param>
281
        public async Task RemoveVoteFromCardAsync(string cardId, string memberId, CancellationToken cancellationToken = default)
282
        {
283
            await _apiRequestController.Delete($"{UrlPaths.Cards}/{cardId}/membersVoted/{memberId}", cancellationToken, 0);
1✔
284
        }
1✔
285
    }
286
}
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

© 2025 Coveralls, Inc