Class: Appwrite::Users

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

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from Appwrite::Service

Instance Method Details

#create(user_id:, email:, password:, name: nil) ⇒ User

Create a new user.

Parameters:

  • user_id (string)

    User ID. Choose your own unique ID or pass the string "unique()" to auto generate it. 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.

  • email (string)

    User email.

  • password (string)

    User password. Must be at least 8 chars.

  • name (string) (defaults to: nil)

    User name. Max length: 128 chars.

Returns:

  • (User)


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

def create(user_id:, email:, password:, name: nil)
    if user_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "userId"')
    end

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

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

    path = '/users'

    params = {
        userId: user_id,
        email: email,
        password: password,
        name: name,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::User
    )
end

#delete(user_id:) ⇒ Object

Delete a user by its unique ID, thereby releasing it's ID. Since ID is released and can be reused, all user-related resources like documents or storage files should be deleted before user deletion. If you want to keep ID reserved, use the [updateStatus](/docs/server/users#usersUpdateStatus) endpoint instead.

Parameters:

  • user_id (string)

    User ID.

Returns:



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/appwrite/services/users.rb', line 123

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

    path = '/users/{userId}'
        .gsub('{userId}', user_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: path,
        headers: headers,
        params: params,
    )
end

#delete_session(user_id:, session_id:) ⇒ Object

Delete a user sessions by its unique ID.

Parameters:

  • user_id (string)

    User ID.

  • session_id (string)

    Session ID.

Returns:



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

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

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

    path = '/users/{userId}/sessions/{sessionId}'
        .gsub('{userId}', user_id)
        .gsub('{sessionId}', session_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: path,
        headers: headers,
        params: params,
    )
end

#delete_sessions(user_id:) ⇒ Object

Delete all user's sessions by using the user's unique ID.

Parameters:

  • user_id (string)

    User ID.

Returns:



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/appwrite/services/users.rb', line 413

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

    path = '/users/{userId}/sessions'
        .gsub('{userId}', user_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: path,
        headers: headers,
        params: params,
    )
end

#get(user_id:) ⇒ User

Get a user by its unique ID.

Parameters:

  • user_id (string)

    User ID.

Returns:

  • (User)


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/appwrite/services/users.rb', line 90

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

    path = '/users/{userId}'
        .gsub('{userId}', user_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::User
    )
end

#get_logs(user_id:, limit: nil, offset: nil) ⇒ LogList

Get the user activity logs list by its unique ID.

Parameters:

  • user_id (string)

    User ID.

  • limit (number) (defaults to: nil)

    Maximum number of logs to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.

  • offset (number) (defaults to: nil)

    Offset value. The default value is 0. Use this value to manage pagination. [learn more about pagination](appwrite.io/docs/pagination)

Returns:

  • (LogList)


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

def get_logs(user_id:, limit: nil, offset: nil)
    if user_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "userId"')
    end

    path = '/users/{userId}/logs'
        .gsub('{userId}', user_id)

    params = {
        limit: limit,
        offset: offset,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::LogList
    )
end

#get_memberships(user_id:) ⇒ MembershipList

Get the user membership list by its unique ID.

Parameters:

  • user_id (string)

    User ID.

Returns:

  • (MembershipList)


219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/appwrite/services/users.rb', line 219

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

    path = '/users/{userId}/memberships'
        .gsub('{userId}', user_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

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

#get_prefs(user_id:) ⇒ Preferences

Get the user preferences by its unique ID.

Parameters:

  • user_id (string)

    User ID.

Returns:

  • (Preferences)


318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/appwrite/services/users.rb', line 318

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

    path = '/users/{userId}/prefs'
        .gsub('{userId}', user_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

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

#get_sessions(user_id:) ⇒ SessionList

Get the user sessions list by its unique ID.

Parameters:

  • user_id (string)

    User ID.

Returns:

  • (SessionList)


384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/appwrite/services/users.rb', line 384

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

    path = '/users/{userId}/sessions'
        .gsub('{userId}', user_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::SessionList
    )
end

#list(search: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_type: nil) ⇒ UserList

Get a list of all the project's users. You can use the query params to filter your results.

Parameters:

  • search (string) (defaults to: nil)

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

  • limit (number) (defaults to: nil)

    Maximum number of users to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.

  • offset (number) (defaults to: nil)

    Offset value. The default value is 0. Use this param to manage pagination. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor (string) (defaults to: nil)

    ID of the user used as the starting point for the query, excluding the user itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor_direction (string) (defaults to: nil)

    Direction of the cursor.

  • order_type (string) (defaults to: nil)

    Order result by ASC or DESC order.

Returns:

  • (UserList)


17
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/users.rb', line 17

def list(search: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_type: nil)
    path = '/users'

    params = {
        search: search,
        limit: limit,
        offset: offset,
        cursor: cursor,
        cursorDirection: cursor_direction,
        orderType: order_type,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::UserList
    )
end

#update_email(user_id:, email:) ⇒ User

Update the user email by its unique ID.

Parameters:

  • user_id (string)

    User ID.

  • email (string)

    User email.

Returns:

  • (User)


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

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

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

    path = '/users/{userId}/email'
        .gsub('{userId}', user_id)

    params = {
        email: email,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::User
    )
end

#update_name(user_id:, name:) ⇒ User

Update the user name by its unique ID.

Parameters:

  • user_id (string)

    User ID.

  • name (string)

    User name. Max length: 128 chars.

Returns:

  • (User)


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

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

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

    path = '/users/{userId}/name'
        .gsub('{userId}', user_id)

    params = {
        name: name,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::User
    )
end

#update_password(user_id:, password:) ⇒ User

Update the user password by its unique ID.

Parameters:

  • user_id (string)

    User ID.

  • password (string)

    New user password. Must be at least 8 chars.

Returns:

  • (User)


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

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

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

    path = '/users/{userId}/password'
        .gsub('{userId}', user_id)

    params = {
        password: password,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::User
    )
end

#update_prefs(user_id:, prefs:) ⇒ Preferences

Update the user 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 error if exceeded.

Parameters:

  • user_id (string)

    User ID.

  • prefs (object)

    Prefs key-value JSON object.

Returns:

  • (Preferences)


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

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

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

    path = '/users/{userId}/prefs'
        .gsub('{userId}', user_id)

    params = {
        prefs: prefs,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Preferences
    )
end

#update_status(user_id:, status:) ⇒ User

Update the user status by its unique ID. Use this endpoint as an alternative to deleting a user if you want to keep user's ID reserved.

Parameters:

  • user_id (string)

    User ID.

  • status (boolean)

    User Status. To activate the user pass `true` and to block the user pass `false`.

Returns:

  • (User)


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

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

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

    path = '/users/{userId}/status'
        .gsub('{userId}', user_id)

    params = {
        status: status,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::User
    )
end

#update_verification(user_id:, email_verification:) ⇒ User

Update the user email verification status by its unique ID.

Parameters:

  • user_id (string)

    User ID.

  • email_verification (boolean)

    User email verification status.

Returns:

  • (User)


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

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

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

    path = '/users/{userId}/verification'
        .gsub('{userId}', user_id)

    params = {
        emailVerification: email_verification,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::User
    )
end