Class: Appwrite::Teams

Inherits:
Service show all
Defined in:
lib/appwrite/services/teams.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Teams

Returns a new instance of Teams.



6
7
8
# File 'lib/appwrite/services/teams.rb', line 6

def initialize(client)
    @client = client
end

Instance Method Details

#create(team_id:, name:, roles: nil) ⇒ Team

Create a new team. The user who creates the team will automatically be assigned as the owner of the team. Only the users with the owner role can invite new members, add new owners and delete or update the team.

Parameters:

  • team_id (String)

    Team ID. Choose a custom ID or generate a random ID with ID.unique(). Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

  • name (String)

    Team name. Max length: 128 chars.

  • roles (Array) (defaults to: nil)

    Array of strings. Use this param to set the roles in the team for the user who created it. The default role is owner. A role can be any string. Learn more about roles and permissions. Maximum of 100 roles are allowed, each 32 characters long.

Returns:

  • (Team)


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
# File 'lib/appwrite/services/teams.rb', line 51

def create(team_id:, name:, roles: nil)
    api_path = '/teams'

    if team_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if name.nil?
      raise Appwrite::Exception.new('Missing required parameter: "name"')
    end

    api_params = {
        teamId: team_id,
        name: name,
        roles: roles,
    }
    
    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Team
    )

end

#create_membership(team_id:, roles:, email: nil, user_id: nil, phone: nil, url: nil, name: nil) ⇒ Membership

Invite a new member to join your team. Provide an ID for existing users, or invite unregistered users using an email or phone number. If initiated from a Client SDK, Appwrite will send an email or sms with a link to join the team to the invited user, and an account will be created for them if one doesn't exist. If initiated from a Server SDK, the new member will be added automatically to the team.

You only need to provide one of a user ID, email, or phone number. Appwrite will prioritize accepting the user ID > email > phone number if you provide more than one of these parameters.

Use the url parameter to redirect the user from the invitation email to your app. After the user is redirected, use the Update Team Membership Status endpoint to allow the user to accept the invitation to the team.

Please note that to avoid a Redirect Attack Appwrite will accept the only redirect URLs under the domains you have added as a platform on the Appwrite Console.

Parameters:

  • team_id (String)

    Team ID.

  • roles (Array)

    Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about roles and permissions. Maximum of 100 roles are allowed, each 81 characters long.

  • email (String) (defaults to: nil)

    Email of the new team member.

  • user_id (String) (defaults to: nil)

    ID of the user to be added to a team.

  • phone (String) (defaults to: nil)

    Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.

  • url (String) (defaults to: nil)

    URL to redirect the user back to your app from the invitation email. This parameter is not required when an API key is supplied. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an open redirect attack against your project API.

  • name (String) (defaults to: nil)

    Name of the new team member. Max length: 128 chars.

Returns:

  • (Membership)


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
# File 'lib/appwrite/services/teams.rb', line 254

def create_membership(team_id:, roles:, email: nil, user_id: nil, phone: nil, url: nil, name: nil)
    api_path = '/teams/{teamId}/memberships'
        .gsub('{teamId}', team_id)

    if team_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if roles.nil?
      raise Appwrite::Exception.new('Missing required parameter: "roles"')
    end

    api_params = {
        email: email,
        userId: user_id,
        phone: phone,
        roles: roles,
        url: url,
        name: name,
    }
    
    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Membership
    )

end

#delete(team_id:) ⇒ Object

Delete a team using its ID. Only team members with the owner role can delete the team.

Parameters:

  • team_id (String)

    Team ID.

Returns:

  • []



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/appwrite/services/teams.rb', line 159

def delete(team_id:)
    api_path = '/teams/{teamId}'
        .gsub('{teamId}', team_id)

    if team_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    api_params = {
    }
    
    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: api_path,
        headers: api_headers,
        params: api_params,
    )

end

#delete_membership(team_id:, membership_id:) ⇒ Object

This endpoint allows a user to leave a team or for a team owner to delete the membership of any other team member. You can also use this endpoint to delete a user membership even if it is not accepted.

Parameters:

  • team_id (String)

    Team ID.

  • membership_id (String)

    Membership ID.

Returns:

  • []



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
# File 'lib/appwrite/services/teams.rb', line 385

def delete_membership(team_id:, membership_id:)
    api_path = '/teams/{teamId}/memberships/{membershipId}'
        .gsub('{teamId}', team_id)
        .gsub('{membershipId}', membership_id)

    if team_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if membership_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "membershipId"')
    end

    api_params = {
    }
    
    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: api_path,
        headers: api_headers,
        params: api_params,
    )

end

#get(team_id:) ⇒ Team

Get a team by its ID. All team members have read access for this resource.

Parameters:

  • team_id (String)

    Team ID.

Returns:

  • (Team)


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
# File 'lib/appwrite/services/teams.rb', line 89

def get(team_id:)
    api_path = '/teams/{teamId}'
        .gsub('{teamId}', team_id)

    if team_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    api_params = {
    }
    
    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Team
    )

end

#get_membership(team_id:, membership_id:) ⇒ Membership

Get a team member by the membership unique id. All team members have read access for this resource. Hide sensitive attributes from the response by toggling membership privacy in the Console.

Parameters:

  • team_id (String)

    Team ID.

  • membership_id (String)

    Membership ID.

Returns:

  • (Membership)


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
# File 'lib/appwrite/services/teams.rb', line 299

def get_membership(team_id:, membership_id:)
    api_path = '/teams/{teamId}/memberships/{membershipId}'
        .gsub('{teamId}', team_id)
        .gsub('{membershipId}', membership_id)

    if team_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if membership_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "membershipId"')
    end

    api_params = {
    }
    
    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Membership
    )

end

#get_prefs(team_id:) ⇒ Preferences

Get the team's shared preferences by its unique ID. If a preference doesn't need to be shared by all team members, prefer storing them in user preferences.

Parameters:

  • team_id (String)

    Team ID.

Returns:

  • (Preferences)


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
# File 'lib/appwrite/services/teams.rb', line 478

def get_prefs(team_id:)
    api_path = '/teams/{teamId}/prefs'
        .gsub('{teamId}', team_id)

    if team_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    api_params = {
    }
    
    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Preferences
    )

end

#list(queries: nil, search: nil, total: nil) ⇒ TeamList

Get a list of all the teams in which the current user is a member. You can use the parameters to filter your results.

Parameters:

  • queries (Array) (defaults to: nil)

    Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, total, billingPlan

  • search (String) (defaults to: nil)

    Search term to filter your list results. Max length: 256 chars.

  • []

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (TeamList)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/appwrite/services/teams.rb', line 18

def list(queries: nil, search: nil, total: nil)
    api_path = '/teams'

    api_params = {
        queries: queries,
        search: search,
        total: total,
    }
    
    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::TeamList
    )

end

#list_memberships(team_id:, queries: nil, search: nil, total: nil) ⇒ MembershipList

Use this endpoint to list a team's members using the team's ID. All team members have read access to this endpoint. Hide sensitive attributes from the response by toggling membership privacy in the Console.

Parameters:

  • team_id (String)

    Team ID.

  • queries (Array) (defaults to: nil)

    Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, teamId, invited, joined, confirm, roles

  • search (String) (defaults to: nil)

    Search term to filter your list results. Max length: 256 chars.

  • []

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (MembershipList)


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
# File 'lib/appwrite/services/teams.rb', line 194

def list_memberships(team_id:, queries: nil, search: nil, total: nil)
    api_path = '/teams/{teamId}/memberships'
        .gsub('{teamId}', team_id)

    if team_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    api_params = {
        queries: queries,
        search: search,
        total: total,
    }
    
    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::MembershipList
    )

end

#update_membership(team_id:, membership_id:, roles:) ⇒ Membership

Modify the roles of a team member. Only team members with the owner role have access to this endpoint. Learn more about roles and permissions.

Parameters:

  • team_id (String)

    Team ID.

  • membership_id (String)

    Membership ID.

  • roles (Array)

    An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about roles and permissions. Maximum of 100 roles are allowed, each 81 characters long.

Returns:

  • (Membership)


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
# File 'lib/appwrite/services/teams.rb', line 340

def update_membership(team_id:, membership_id:, roles:)
    api_path = '/teams/{teamId}/memberships/{membershipId}'
        .gsub('{teamId}', team_id)
        .gsub('{membershipId}', membership_id)

    if team_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if membership_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "membershipId"')
    end

    if roles.nil?
      raise Appwrite::Exception.new('Missing required parameter: "roles"')
    end

    api_params = {
        roles: roles,
    }
    
    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Membership
    )

end

#update_membership_status(team_id:, membership_id:, user_id:, secret:) ⇒ Membership

Use this endpoint to allow a user to accept an invitation to join a team after being redirected back to your app from the invitation email received by the user.

If the request is successful, a session for the user is automatically created.

Parameters:

  • team_id (String)

    Team ID.

  • membership_id (String)

    Membership ID.

  • user_id (String)

    User ID.

  • secret (String)

    Secret key.

Returns:

  • (Membership)


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
# File 'lib/appwrite/services/teams.rb', line 429

def update_membership_status(team_id:, membership_id:, user_id:, secret:)
    api_path = '/teams/{teamId}/memberships/{membershipId}/status'
        .gsub('{teamId}', team_id)
        .gsub('{membershipId}', membership_id)

    if team_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if membership_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "membershipId"')
    end

    if user_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "userId"')
    end

    if secret.nil?
      raise Appwrite::Exception.new('Missing required parameter: "secret"')
    end

    api_params = {
        userId: user_id,
        secret: secret,
    }
    
    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Membership
    )

end

#update_name(team_id:, name:) ⇒ Team

Update the team's name by its unique ID.

Parameters:

  • team_id (String)

    Team ID.

  • name (String)

    New team name. Max length: 128 chars.

Returns:

  • (Team)


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
# File 'lib/appwrite/services/teams.rb', line 121

def update_name(team_id:, name:)
    api_path = '/teams/{teamId}'
        .gsub('{teamId}', team_id)

    if team_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if name.nil?
      raise Appwrite::Exception.new('Missing required parameter: "name"')
    end

    api_params = {
        name: name,
    }
    
    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'PUT',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Team
    )

end

#update_prefs(team_id:, prefs:) ⇒ Preferences

Update the team's preferences by its unique ID. The object you pass is stored as is and replaces any previous value. The maximum allowed prefs size is 64kB and throws an error if exceeded.

Parameters:

  • team_id (String)

    Team ID.

  • prefs (Hash)

    Prefs key-value JSON object.

Returns:

  • (Preferences)


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
# File 'lib/appwrite/services/teams.rb', line 512

def update_prefs(team_id:, prefs:)
    api_path = '/teams/{teamId}/prefs'
        .gsub('{teamId}', team_id)

    if team_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if prefs.nil?
      raise Appwrite::Exception.new('Missing required parameter: "prefs"')
    end

    api_params = {
        prefs: prefs,
    }
    
    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'PUT',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Preferences
    )

end