appwrite 11.0.2 → 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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/appwrite/client.rb +54 -76
  3. data/lib/appwrite/enums/image_format.rb +1 -0
  4. data/lib/appwrite/enums/name.rb +1 -2
  5. data/lib/appwrite/enums/runtime.rb +4 -0
  6. data/lib/appwrite/models/attribute_boolean.rb +10 -0
  7. data/lib/appwrite/models/attribute_datetime.rb +10 -0
  8. data/lib/appwrite/models/attribute_email.rb +10 -0
  9. data/lib/appwrite/models/attribute_enum.rb +10 -0
  10. data/lib/appwrite/models/attribute_float.rb +10 -0
  11. data/lib/appwrite/models/attribute_integer.rb +10 -0
  12. data/lib/appwrite/models/attribute_ip.rb +10 -0
  13. data/lib/appwrite/models/attribute_relationship.rb +10 -0
  14. data/lib/appwrite/models/attribute_string.rb +10 -0
  15. data/lib/appwrite/models/attribute_url.rb +10 -0
  16. data/lib/appwrite/models/build.rb +67 -0
  17. data/lib/appwrite/models/deployment.rb +5 -0
  18. data/lib/appwrite/models/document.rb +4 -9
  19. data/lib/appwrite/models/document_list.rb +1 -2
  20. data/lib/appwrite/models/execution.rb +8 -3
  21. data/lib/appwrite/models/function.rb +13 -3
  22. data/lib/appwrite/models/index.rb +13 -3
  23. data/lib/appwrite/models/preferences.rb +4 -9
  24. data/lib/appwrite/models/runtime.rb +5 -0
  25. data/lib/appwrite/models/specification.rb +42 -0
  26. data/lib/appwrite/models/specification_list.rb +32 -0
  27. data/lib/appwrite/multipart.rb +127 -0
  28. data/lib/appwrite/payload.rb +94 -0
  29. data/lib/appwrite/services/account.rb +52 -58
  30. data/lib/appwrite/services/avatars.rb +23 -21
  31. data/lib/appwrite/services/databases.rb +136 -114
  32. data/lib/appwrite/services/functions.rb +174 -72
  33. data/lib/appwrite/services/graphql.rb +2 -2
  34. data/lib/appwrite/services/health.rb +15 -15
  35. data/lib/appwrite/services/messaging.rb +225 -225
  36. data/lib/appwrite/services/storage.rb +40 -40
  37. data/lib/appwrite/services/teams.rb +19 -19
  38. data/lib/appwrite/services/users.rb +104 -68
  39. data/lib/appwrite.rb +5 -1
  40. metadata +7 -3
  41. 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 = {
@@ -299,7 +299,7 @@ module Appwrite
299
299
 
300
300
  # Verify an authenticator app after adding it using the [add
301
301
  # authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator)
302
- # method. add
302
+ # method.
303
303
  #
304
304
  # @param [AuthenticatorType] type Type of authenticator.
305
305
  # @param [String] otp Valid verification token.
@@ -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
342
  # @return []
344
- def delete_mfa_authenticator(type:, otp:)
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 = {
@@ -385,7 +379,7 @@ module Appwrite
385
379
  end
386
380
 
387
381
  api_params = {
388
- factor: factor,
382
+ factor: factor,
389
383
  }
390
384
 
391
385
  api_headers = {
@@ -424,8 +418,8 @@ module Appwrite
424
418
  end
425
419
 
426
420
  api_params = {
427
- challengeId: challenge_id,
428
- otp: otp,
421
+ challengeId: challenge_id,
422
+ otp: otp,
429
423
  }
430
424
 
431
425
  api_headers = {
@@ -560,7 +554,7 @@ module Appwrite
560
554
  end
561
555
 
562
556
  api_params = {
563
- name: name,
557
+ name: name,
564
558
  }
565
559
 
566
560
  api_headers = {
@@ -593,8 +587,8 @@ module Appwrite
593
587
  end
594
588
 
595
589
  api_params = {
596
- password: password,
597
- oldPassword: old_password,
590
+ password: password,
591
+ oldPassword: old_password,
598
592
  }
599
593
 
600
594
  api_headers = {
@@ -633,8 +627,8 @@ module Appwrite
633
627
  end
634
628
 
635
629
  api_params = {
636
- phone: phone,
637
- password: password,
630
+ phone: phone,
631
+ password: password,
638
632
  }
639
633
 
640
634
  api_headers = {
@@ -690,7 +684,7 @@ module Appwrite
690
684
  end
691
685
 
692
686
  api_params = {
693
- prefs: prefs,
687
+ prefs: prefs,
694
688
  }
695
689
 
696
690
  api_headers = {
@@ -732,8 +726,8 @@ module Appwrite
732
726
  end
733
727
 
734
728
  api_params = {
735
- email: email,
736
- url: url,
729
+ email: email,
730
+ url: url,
737
731
  }
738
732
 
739
733
  api_headers = {
@@ -782,9 +776,9 @@ module Appwrite
782
776
  end
783
777
 
784
778
  api_params = {
785
- userId: user_id,
786
- secret: secret,
787
- password: password,
779
+ userId: user_id,
780
+ secret: secret,
781
+ password: password,
788
782
  }
789
783
 
790
784
  api_headers = {
@@ -903,8 +897,8 @@ module Appwrite
903
897
  end
904
898
 
905
899
  api_params = {
906
- email: email,
907
- password: password,
900
+ email: email,
901
+ password: password,
908
902
  }
909
903
 
910
904
  api_headers = {
@@ -941,8 +935,8 @@ module Appwrite
941
935
  end
942
936
 
943
937
  api_params = {
944
- userId: user_id,
945
- secret: secret,
938
+ userId: user_id,
939
+ secret: secret,
946
940
  }
947
941
 
948
942
  api_headers = {
@@ -979,8 +973,8 @@ module Appwrite
979
973
  end
980
974
 
981
975
  api_params = {
982
- userId: user_id,
983
- secret: secret,
976
+ userId: user_id,
977
+ secret: secret,
984
978
  }
985
979
 
986
980
  api_headers = {
@@ -1017,8 +1011,8 @@ module Appwrite
1017
1011
  end
1018
1012
 
1019
1013
  api_params = {
1020
- userId: user_id,
1021
- secret: secret,
1014
+ userId: user_id,
1015
+ secret: secret,
1022
1016
  }
1023
1017
 
1024
1018
  api_headers = {
@@ -1185,9 +1179,9 @@ module Appwrite
1185
1179
  end
1186
1180
 
1187
1181
  api_params = {
1188
- userId: user_id,
1189
- email: email,
1190
- phrase: phrase,
1182
+ userId: user_id,
1183
+ email: email,
1184
+ phrase: phrase,
1191
1185
  }
1192
1186
 
1193
1187
  api_headers = {
@@ -1239,10 +1233,10 @@ module Appwrite
1239
1233
  end
1240
1234
 
1241
1235
  api_params = {
1242
- userId: user_id,
1243
- email: email,
1244
- url: url,
1245
- phrase: phrase,
1236
+ userId: user_id,
1237
+ email: email,
1238
+ url: url,
1239
+ phrase: phrase,
1246
1240
  }
1247
1241
 
1248
1242
  api_headers = {
@@ -1289,9 +1283,9 @@ module Appwrite
1289
1283
  end
1290
1284
 
1291
1285
  api_params = {
1292
- success: success,
1293
- failure: failure,
1294
- scopes: scopes,
1286
+ success: success,
1287
+ failure: failure,
1288
+ scopes: scopes,
1295
1289
  }
1296
1290
 
1297
1291
  api_headers = {
@@ -1335,8 +1329,8 @@ module Appwrite
1335
1329
  end
1336
1330
 
1337
1331
  api_params = {
1338
- userId: user_id,
1339
- phone: phone,
1332
+ userId: user_id,
1333
+ phone: phone,
1340
1334
  }
1341
1335
 
1342
1336
  api_headers = {
@@ -1380,7 +1374,7 @@ module Appwrite
1380
1374
  end
1381
1375
 
1382
1376
  api_params = {
1383
- url: url,
1377
+ url: url,
1384
1378
  }
1385
1379
 
1386
1380
  api_headers = {
@@ -1418,8 +1412,8 @@ module Appwrite
1418
1412
  end
1419
1413
 
1420
1414
  api_params = {
1421
- userId: user_id,
1422
- secret: secret,
1415
+ userId: user_id,
1416
+ secret: secret,
1423
1417
  }
1424
1418
 
1425
1419
  api_headers = {
@@ -1488,8 +1482,8 @@ module Appwrite
1488
1482
  end
1489
1483
 
1490
1484
  api_params = {
1491
- userId: user_id,
1492
- secret: secret,
1485
+ userId: user_id,
1486
+ secret: secret,
1493
1487
  }
1494
1488
 
1495
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 = {
@@ -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 = {