appwrite 11.0.1 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of appwrite might be problematic. Click here for more details.

Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/appwrite/client.rb +54 -76
  3. data/lib/appwrite/enums/credit_card.rb +1 -1
  4. data/lib/appwrite/enums/flag.rb +1 -0
  5. data/lib/appwrite/enums/image_format.rb +1 -0
  6. data/lib/appwrite/enums/name.rb +1 -2
  7. data/lib/appwrite/enums/runtime.rb +5 -0
  8. data/lib/appwrite/models/attribute_boolean.rb +10 -0
  9. data/lib/appwrite/models/attribute_datetime.rb +10 -0
  10. data/lib/appwrite/models/attribute_email.rb +10 -0
  11. data/lib/appwrite/models/attribute_enum.rb +10 -0
  12. data/lib/appwrite/models/attribute_float.rb +10 -0
  13. data/lib/appwrite/models/attribute_integer.rb +10 -0
  14. data/lib/appwrite/models/attribute_ip.rb +10 -0
  15. data/lib/appwrite/models/attribute_relationship.rb +10 -0
  16. data/lib/appwrite/models/attribute_string.rb +10 -0
  17. data/lib/appwrite/models/attribute_url.rb +10 -0
  18. data/lib/appwrite/models/build.rb +67 -0
  19. data/lib/appwrite/models/deployment.rb +5 -0
  20. data/lib/appwrite/models/document.rb +4 -9
  21. data/lib/appwrite/models/document_list.rb +1 -2
  22. data/lib/appwrite/models/execution.rb +8 -3
  23. data/lib/appwrite/models/function.rb +13 -3
  24. data/lib/appwrite/models/index.rb +13 -3
  25. data/lib/appwrite/models/mfa_factors.rb +8 -3
  26. data/lib/appwrite/models/preferences.rb +4 -9
  27. data/lib/appwrite/models/runtime.rb +5 -0
  28. data/lib/appwrite/models/session.rb +5 -0
  29. data/lib/appwrite/models/specification.rb +42 -0
  30. data/lib/appwrite/models/specification_list.rb +32 -0
  31. data/lib/appwrite/multipart.rb +127 -0
  32. data/lib/appwrite/payload.rb +94 -0
  33. data/lib/appwrite/services/account.rb +54 -61
  34. data/lib/appwrite/services/avatars.rb +24 -22
  35. data/lib/appwrite/services/databases.rb +136 -114
  36. data/lib/appwrite/services/functions.rb +174 -72
  37. data/lib/appwrite/services/graphql.rb +2 -2
  38. data/lib/appwrite/services/health.rb +15 -15
  39. data/lib/appwrite/services/messaging.rb +230 -228
  40. data/lib/appwrite/services/storage.rb +40 -40
  41. data/lib/appwrite/services/teams.rb +19 -19
  42. data/lib/appwrite/services/users.rb +108 -72
  43. data/lib/appwrite.rb +5 -1
  44. metadata +7 -3
  45. data/lib/appwrite/input_file.rb +0 -33
@@ -0,0 +1,127 @@
1
+ require 'mime/types'
2
+
3
+ module Appwrite
4
+ class MultipartBuilder
5
+ attr_reader :boundary
6
+
7
+ def initialize(boundary: nil)
8
+ @boundary = boundary ||= "----RubyMultipartPost#{rand(1000000)}"
9
+ @parts = []
10
+ end
11
+
12
+ def add(name, contents, filename: nil, content_type: nil)
13
+ if contents.is_a?(Array)
14
+ contents.each_with_index do |element, index|
15
+ add("#{name}[#{index}]", element)
16
+ end
17
+ return
18
+ end
19
+
20
+ part = "--#{@boundary}\r\n"
21
+ part << "Content-Disposition: form-data; name=\"#{name}\""
22
+ part << "; filename=\"#{filename}\"" if filename
23
+ part << "\r\n"
24
+ if content_type
25
+ part << "Content-Type: #{content_type}\r\n"
26
+ elsif filename
27
+ content_type = MIME::Types.type_for(filename).first&.content_type || 'application/octet-stream'
28
+ part << "Content-Type: #{content_type}\r\n"
29
+ end
30
+ part << "\r\n"
31
+ part << contents.to_s
32
+ part << "\r\n"
33
+
34
+ @parts << part
35
+ end
36
+
37
+ def body
38
+ @parts.join + "--#{@boundary}--\r\n"
39
+ end
40
+
41
+ def content_type
42
+ "multipart/form-data; boundary=#{@boundary}"
43
+ end
44
+ end
45
+
46
+ class MultipartParser
47
+ attr_reader :parts
48
+
49
+ def initialize(multipart_string, content_type)
50
+ @multipart_string = multipart_string
51
+ @boundary = _extract_boundary(content_type)
52
+ @parts = {}
53
+ parse
54
+ end
55
+
56
+ def _extract_boundary(content_type)
57
+ match = content_type.match(/boundary="?(.+?)"?(?:\s*;|$)/)
58
+ if match
59
+ return match[1]
60
+ end
61
+
62
+ puts content_type
63
+
64
+ raise "Boundary not found in Content-Type header"
65
+ end
66
+
67
+ def parse
68
+ # Split the multipart string into individual parts
69
+ parts = @multipart_string.split("--#{@boundary}")
70
+
71
+ # Remove the first (empty) and last (boundary end) elements
72
+ parts = parts[1...-1]
73
+
74
+ parts.each do |part|
75
+ # Split headers and content
76
+ headers, content = part.strip.split("\r\n\r\n", 2)
77
+
78
+ # Parse headers
79
+ headers_hash = headers.split("\r\n").each_with_object({}) do |header, hash|
80
+ key, value = header.split(": ", 2)
81
+ hash[key.downcase] = value
82
+ end
83
+
84
+ # Extract name from Content-Disposition header
85
+ content_disposition = headers_hash["content-disposition"] || ""
86
+ name = content_disposition[/name="([^"]*)"/, 1]
87
+
88
+ # If no name is found, use a default naming scheme
89
+ name ||= "unnamed_part_#{@parts.length}"
90
+
91
+ # Store the parsed data
92
+ @parts[name] = {
93
+ contents: content.strip,
94
+ headers: headers_hash
95
+ }
96
+ end
97
+ end
98
+
99
+ def to_hash
100
+ h = {}
101
+
102
+ @parts.each do |name, part|
103
+ case name
104
+ when "responseBody"
105
+ h[name] = Payload.from_binary(part[:contents])
106
+ when "responseHeaders"
107
+ h[name] = part[:contents].split("\r\n").each_with_object({}) do |header, hash|
108
+ key, value = header.split(": ", 2)
109
+ hash[key] = value
110
+ end
111
+ when "responseStatusCode"
112
+ h[name] = part[:contents].to_i
113
+ when "duration"
114
+ h[name] = part[:contents].to_f
115
+ else
116
+ begin
117
+ h[name] = part[:contents].force_encoding("utf-8")
118
+ rescue
119
+ h[name] = part[:contents]
120
+ end
121
+ end
122
+ end
123
+
124
+ h
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,94 @@
1
+ require 'fileutils'
2
+
3
+ module Appwrite
4
+ class Payload
5
+ attr_reader :filename
6
+ attr_reader :size
7
+
8
+ def initialize(data, path, filename)
9
+ if data.nil? && path.nil? then
10
+ raise ArgumentError.new('Payload must have one of data or path')
11
+ end
12
+
13
+ @path = path
14
+ @data = data
15
+
16
+ @filename = filename
17
+ @size = if @data then
18
+ @data.bytesize
19
+ else
20
+ File.size(@path)
21
+ end
22
+ end
23
+
24
+ # @param [Integer] offset
25
+ # @param [Integer] length
26
+ # @return [String]
27
+ def to_binary(offset = 0, length = nil)
28
+ length ||= @size - offset
29
+ if @data then
30
+ @data.byteslice(offset, length)
31
+ else
32
+ IO.read(@path, length, offset)
33
+ end
34
+ end
35
+
36
+ # @return [String]
37
+ def to_s()
38
+ to_binary().force_encoding('UTF-8')
39
+ end
40
+
41
+ alias to_string to_s
42
+
43
+ # @return [Hash]
44
+ def to_json()
45
+ JSON.parse(to_s())
46
+ end
47
+
48
+ # @param [String] path
49
+ # @return [void]
50
+ def to_file(path)
51
+ FileUtils.mkdir_p(File.dirname(path))
52
+ File.open(path, 'wb') { |f| f.write(to_binary()) }
53
+ end
54
+
55
+ # @param [String] bytes
56
+ # @param [String, nil] filename
57
+ # @return [Payload]
58
+ def self.from_binary(bytes, filename: nil)
59
+ new(bytes, nil, filename)
60
+ end
61
+
62
+ # @param [String] string
63
+ # @param [String, nil] filename
64
+ # @return [Payload]
65
+ def self.from_string(string, filename: nil)
66
+ bytes = string.encode('UTF-8')
67
+ new(bytes, nil, filename)
68
+ end
69
+
70
+ # @param [Hash, Array] object
71
+ # @param [String, nil] filename
72
+ # @return [Payload]
73
+ def self.from_json(object, filename: nil)
74
+ if !object.is_a?(Hash) && !object.is_a?(Array) then
75
+ raise ArgumentError.new('Object must be a Hash or Array')
76
+ end
77
+ json = JSON.generate(object)
78
+ self.from_string(json, filename: filename)
79
+ end
80
+
81
+ # @param [String] path
82
+ # @param [String, nil] filename
83
+ # @return [Payload]
84
+ def self.from_file(path, filename: nil)
85
+ raise ArgumentError.new('File not found') if !File.exists?(path)
86
+ filename = if filename.nil? then
87
+ File.basename(path)
88
+ else
89
+ filename
90
+ end
91
+ new(nil, path, filename)
92
+ end
93
+ end
94
+ end
@@ -61,10 +61,10 @@ module Appwrite
61
61
  end
62
62
 
63
63
  api_params = {
64
- userId: user_id,
65
- email: email,
66
- password: password,
67
- name: name,
64
+ userId: user_id,
65
+ email: email,
66
+ password: password,
67
+ name: name,
68
68
  }
69
69
 
70
70
  api_headers = {
@@ -106,8 +106,8 @@ module Appwrite
106
106
  end
107
107
 
108
108
  api_params = {
109
- email: email,
110
- password: password,
109
+ email: email,
110
+ password: password,
111
111
  }
112
112
 
113
113
  api_headers = {
@@ -133,7 +133,7 @@ module Appwrite
133
133
  api_path = '/account/identities'
134
134
 
135
135
  api_params = {
136
- queries: queries,
136
+ queries: queries,
137
137
  }
138
138
 
139
139
  api_headers = {
@@ -188,7 +188,7 @@ module Appwrite
188
188
  #
189
189
  # @return [Jwt]
190
190
  def create_jwt()
191
- api_path = '/account/jwt'
191
+ api_path = '/account/jwts'
192
192
 
193
193
  api_params = {
194
194
  }
@@ -217,7 +217,7 @@ module Appwrite
217
217
  api_path = '/account/logs'
218
218
 
219
219
  api_params = {
220
- queries: queries,
220
+ queries: queries,
221
221
  }
222
222
 
223
223
  api_headers = {
@@ -247,7 +247,7 @@ module Appwrite
247
247
  end
248
248
 
249
249
  api_params = {
250
- mfa: mfa,
250
+ mfa: mfa,
251
251
  }
252
252
 
253
253
  api_headers = {
@@ -266,7 +266,7 @@ module Appwrite
266
266
 
267
267
  # Add an authenticator app to be used as an MFA factor. Verify the
268
268
  # authenticator using the [verify
269
- # authenticator](/docs/references/cloud/client-web/account#verifyAuthenticator)
269
+ # authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator)
270
270
  # method.
271
271
  #
272
272
  # @param [AuthenticatorType] type Type of authenticator. Must be `totp`
@@ -298,7 +298,7 @@ module Appwrite
298
298
 
299
299
 
300
300
  # Verify an authenticator app after adding it using the [add
301
- # authenticator](/docs/references/cloud/client-web/account#addAuthenticator)
301
+ # authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator)
302
302
  # method.
303
303
  #
304
304
  # @param [AuthenticatorType] type Type of authenticator.
@@ -318,7 +318,7 @@ module Appwrite
318
318
  end
319
319
 
320
320
  api_params = {
321
- otp: otp,
321
+ otp: otp,
322
322
  }
323
323
 
324
324
  api_headers = {
@@ -338,10 +338,9 @@ module Appwrite
338
338
  # Delete an authenticator for a user by ID.
339
339
  #
340
340
  # @param [AuthenticatorType] type Type of authenticator.
341
- # @param [String] otp Valid verification token.
342
341
  #
343
- # @return [User]
344
- def delete_mfa_authenticator(type:, otp:)
342
+ # @return []
343
+ def delete_mfa_authenticator(type:)
345
344
  api_path = '/account/mfa/authenticators/{type}'
346
345
  .gsub('{type}', type)
347
346
 
@@ -349,12 +348,7 @@ module Appwrite
349
348
  raise Appwrite::Exception.new('Missing required parameter: "type"')
350
349
  end
351
350
 
352
- if otp.nil?
353
- raise Appwrite::Exception.new('Missing required parameter: "otp"')
354
- end
355
-
356
351
  api_params = {
357
- otp: otp,
358
352
  }
359
353
 
360
354
  api_headers = {
@@ -366,7 +360,6 @@ module Appwrite
366
360
  path: api_path,
367
361
  headers: api_headers,
368
362
  params: api_params,
369
- response_type: Models::User
370
363
  )
371
364
  end
372
365
 
@@ -386,7 +379,7 @@ module Appwrite
386
379
  end
387
380
 
388
381
  api_params = {
389
- factor: factor,
382
+ factor: factor,
390
383
  }
391
384
 
392
385
  api_headers = {
@@ -425,8 +418,8 @@ module Appwrite
425
418
  end
426
419
 
427
420
  api_params = {
428
- challengeId: challenge_id,
429
- otp: otp,
421
+ challengeId: challenge_id,
422
+ otp: otp,
430
423
  }
431
424
 
432
425
  api_headers = {
@@ -561,7 +554,7 @@ module Appwrite
561
554
  end
562
555
 
563
556
  api_params = {
564
- name: name,
557
+ name: name,
565
558
  }
566
559
 
567
560
  api_headers = {
@@ -594,8 +587,8 @@ module Appwrite
594
587
  end
595
588
 
596
589
  api_params = {
597
- password: password,
598
- oldPassword: old_password,
590
+ password: password,
591
+ oldPassword: old_password,
599
592
  }
600
593
 
601
594
  api_headers = {
@@ -634,8 +627,8 @@ module Appwrite
634
627
  end
635
628
 
636
629
  api_params = {
637
- phone: phone,
638
- password: password,
630
+ phone: phone,
631
+ password: password,
639
632
  }
640
633
 
641
634
  api_headers = {
@@ -691,7 +684,7 @@ module Appwrite
691
684
  end
692
685
 
693
686
  api_params = {
694
- prefs: prefs,
687
+ prefs: prefs,
695
688
  }
696
689
 
697
690
  api_headers = {
@@ -733,8 +726,8 @@ module Appwrite
733
726
  end
734
727
 
735
728
  api_params = {
736
- email: email,
737
- url: url,
729
+ email: email,
730
+ url: url,
738
731
  }
739
732
 
740
733
  api_headers = {
@@ -783,9 +776,9 @@ module Appwrite
783
776
  end
784
777
 
785
778
  api_params = {
786
- userId: user_id,
787
- secret: secret,
788
- password: password,
779
+ userId: user_id,
780
+ secret: secret,
781
+ password: password,
789
782
  }
790
783
 
791
784
  api_headers = {
@@ -904,8 +897,8 @@ module Appwrite
904
897
  end
905
898
 
906
899
  api_params = {
907
- email: email,
908
- password: password,
900
+ email: email,
901
+ password: password,
909
902
  }
910
903
 
911
904
  api_headers = {
@@ -942,8 +935,8 @@ module Appwrite
942
935
  end
943
936
 
944
937
  api_params = {
945
- userId: user_id,
946
- secret: secret,
938
+ userId: user_id,
939
+ secret: secret,
947
940
  }
948
941
 
949
942
  api_headers = {
@@ -980,8 +973,8 @@ module Appwrite
980
973
  end
981
974
 
982
975
  api_params = {
983
- userId: user_id,
984
- secret: secret,
976
+ userId: user_id,
977
+ secret: secret,
985
978
  }
986
979
 
987
980
  api_headers = {
@@ -1018,8 +1011,8 @@ module Appwrite
1018
1011
  end
1019
1012
 
1020
1013
  api_params = {
1021
- userId: user_id,
1022
- secret: secret,
1014
+ userId: user_id,
1015
+ secret: secret,
1023
1016
  }
1024
1017
 
1025
1018
  api_headers = {
@@ -1186,9 +1179,9 @@ module Appwrite
1186
1179
  end
1187
1180
 
1188
1181
  api_params = {
1189
- userId: user_id,
1190
- email: email,
1191
- phrase: phrase,
1182
+ userId: user_id,
1183
+ email: email,
1184
+ phrase: phrase,
1192
1185
  }
1193
1186
 
1194
1187
  api_headers = {
@@ -1240,10 +1233,10 @@ module Appwrite
1240
1233
  end
1241
1234
 
1242
1235
  api_params = {
1243
- userId: user_id,
1244
- email: email,
1245
- url: url,
1246
- phrase: phrase,
1236
+ userId: user_id,
1237
+ email: email,
1238
+ url: url,
1239
+ phrase: phrase,
1247
1240
  }
1248
1241
 
1249
1242
  api_headers = {
@@ -1290,9 +1283,9 @@ module Appwrite
1290
1283
  end
1291
1284
 
1292
1285
  api_params = {
1293
- success: success,
1294
- failure: failure,
1295
- scopes: scopes,
1286
+ success: success,
1287
+ failure: failure,
1288
+ scopes: scopes,
1296
1289
  }
1297
1290
 
1298
1291
  api_headers = {
@@ -1336,8 +1329,8 @@ module Appwrite
1336
1329
  end
1337
1330
 
1338
1331
  api_params = {
1339
- userId: user_id,
1340
- phone: phone,
1332
+ userId: user_id,
1333
+ phone: phone,
1341
1334
  }
1342
1335
 
1343
1336
  api_headers = {
@@ -1381,7 +1374,7 @@ module Appwrite
1381
1374
  end
1382
1375
 
1383
1376
  api_params = {
1384
- url: url,
1377
+ url: url,
1385
1378
  }
1386
1379
 
1387
1380
  api_headers = {
@@ -1419,8 +1412,8 @@ module Appwrite
1419
1412
  end
1420
1413
 
1421
1414
  api_params = {
1422
- userId: user_id,
1423
- secret: secret,
1415
+ userId: user_id,
1416
+ secret: secret,
1424
1417
  }
1425
1418
 
1426
1419
  api_headers = {
@@ -1489,8 +1482,8 @@ module Appwrite
1489
1482
  end
1490
1483
 
1491
1484
  api_params = {
1492
- userId: user_id,
1493
- secret: secret,
1485
+ userId: user_id,
1486
+ secret: secret,
1494
1487
  }
1495
1488
 
1496
1489
  api_headers = {
@@ -33,9 +33,9 @@ module Appwrite
33
33
  end
34
34
 
35
35
  api_params = {
36
- width: width,
37
- height: height,
38
- quality: quality,
36
+ width: width,
37
+ height: height,
38
+ quality: quality,
39
39
  }
40
40
 
41
41
  api_headers = {
@@ -61,7 +61,7 @@ module Appwrite
61
61
  # of image returned is 100x100px.
62
62
  #
63
63
  #
64
- # @param [CreditCard] code Credit Card Code. Possible values: amex, argencard, cabal, censosud, diners, discover, elo, hipercard, jcb, mastercard, naranja, targeta-shopping, union-china-pay, visa, mir, maestro.
64
+ # @param [CreditCard] code Credit Card Code. Possible values: amex, argencard, cabal, cencosud, diners, discover, elo, hipercard, jcb, mastercard, naranja, targeta-shopping, union-china-pay, visa, mir, maestro.
65
65
  # @param [Integer] width Image width. Pass an integer between 0 to 2000. Defaults to 100.
66
66
  # @param [Integer] height Image height. Pass an integer between 0 to 2000. Defaults to 100.
67
67
  # @param [Integer] quality Image quality. Pass an integer between 0 to 100. Defaults to 100.
@@ -76,9 +76,9 @@ module Appwrite
76
76
  end
77
77
 
78
78
  api_params = {
79
- width: width,
80
- height: height,
81
- quality: quality,
79
+ width: width,
80
+ height: height,
81
+ quality: quality,
82
82
  }
83
83
 
84
84
  api_headers = {
@@ -97,6 +97,7 @@ module Appwrite
97
97
  # Use this endpoint to fetch the favorite icon (AKA favicon) of any remote
98
98
  # website URL.
99
99
  #
100
+ # This endpoint does not follow HTTP redirects.
100
101
  #
101
102
  # @param [String] url Website URL which you want to fetch the favicon from.
102
103
  #
@@ -109,7 +110,7 @@ module Appwrite
109
110
  end
110
111
 
111
112
  api_params = {
112
- url: url,
113
+ url: url,
113
114
  }
114
115
 
115
116
  api_headers = {
@@ -151,9 +152,9 @@ module Appwrite
151
152
  end
152
153
 
153
154
  api_params = {
154
- width: width,
155
- height: height,
156
- quality: quality,
155
+ width: width,
156
+ height: height,
157
+ quality: quality,
157
158
  }
158
159
 
159
160
  api_headers = {
@@ -179,6 +180,7 @@ module Appwrite
179
180
  # image at source quality. If dimensions are not specified, the default size
180
181
  # of image returned is 400x400px.
181
182
  #
183
+ # This endpoint does not follow HTTP redirects.
182
184
  #
183
185
  # @param [String] url Image URL which you want to crop.
184
186
  # @param [Integer] width Resize preview image width, Pass an integer between 0 to 2000. Defaults to 400.
@@ -193,9 +195,9 @@ module Appwrite
193
195
  end
194
196
 
195
197
  api_params = {
196
- url: url,
197
- width: width,
198
- height: height,
198
+ url: url,
199
+ width: width,
200
+ height: height,
199
201
  }
200
202
 
201
203
  api_headers = {
@@ -238,10 +240,10 @@ module Appwrite
238
240
  api_path = '/avatars/initials'
239
241
 
240
242
  api_params = {
241
- name: name,
242
- width: width,
243
- height: height,
244
- background: background,
243
+ name: name,
244
+ width: width,
245
+ height: height,
246
+ background: background,
245
247
  }
246
248
 
247
249
  api_headers = {
@@ -275,10 +277,10 @@ module Appwrite
275
277
  end
276
278
 
277
279
  api_params = {
278
- text: text,
279
- size: size,
280
- margin: margin,
281
- download: download,
280
+ text: text,
281
+ size: size,
282
+ margin: margin,
283
+ download: download,
282
284
  }
283
285
 
284
286
  api_headers = {