appwrite 4.0.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c885588668d4133732a6a6acf50beaa77734e71057417396d474e93b492029c5
4
- data.tar.gz: 7711957f95eb038ad03e6c503a55dc61b3e0c7313e15308451a254cb35093b29
3
+ metadata.gz: 244426e7a1b826998665f527b91af45e1425573b462e51875beb40d4e6e779d5
4
+ data.tar.gz: 59b014041d4dc658b3b13aa4eed684b7a5d85e439042a5ac5ee6431e283aa5f8
5
5
  SHA512:
6
- metadata.gz: e7eb2a20711fd0e4f0650e39c89ae553d36f9f1e3dd2cdd5408b37555c6b75dbd45078018f5a68de3f5b568d91430871114e2afc287c5dbf058abe20ef33ea4d
7
- data.tar.gz: 79804f75cbf28704a84d4c83401cc9873bc46bab9aa5b31198db05929f441fb6c8baee04adb3c04b0f385cbb0a5347df542ec37d6d1f80032c700a899c7a6a4e
6
+ metadata.gz: '09e057f7cf1b9518ab1eca3a64e6b87cf951641a3a3025c5534bb49a720029424711bbb45379f24f4c49a0f990280e71620594a20246d15290e88bf8587c58ea'
7
+ data.tar.gz: 31369de41cefe9745d2dc5264d3176b24698bb385271c321e6bd18c091d6ad5974ff97759dee0825a9b8774dae8135c3518fe45605cfbc60bc4d82f295deabdb
@@ -12,8 +12,8 @@ module Appwrite
12
12
  @chunk_size = 5*1024*1024
13
13
  @headers = {
14
14
  'user-agent' => RUBY_PLATFORM + ':ruby-' + RUBY_VERSION,
15
- 'x-sdk-version' => 'appwrite:ruby:4.0.0',
16
- 'X-Appwrite-Response-Format' => '0.13.0'
15
+ 'x-sdk-version' => 'appwrite:ruby:6.0.0',
16
+ 'X-Appwrite-Response-Format' => '0.15.0'
17
17
  }
18
18
  @endpoint = 'https://HOSTNAME/v1'
19
19
  end
@@ -129,15 +129,24 @@ module Appwrite
129
129
  headers:,
130
130
  params:,
131
131
  param_name: '',
132
+ id_param_name: nil,
132
133
  on_progress: nil,
133
134
  response_type: nil
134
135
  )
135
- file_path = params[param_name.to_sym]
136
- size = ::File.size(file_path)
136
+ input_file = params[param_name.to_sym]
137
+
138
+ case input_file.source_type
139
+ when 'path'
140
+ size = ::File.size(input_file.path)
141
+ when 'string'
142
+ size = input_file.data.bytesize
143
+ end
137
144
 
138
145
  if size < @chunk_size
139
- slice = ::File.read(file_path)
140
- params[param_name] = File.new(file_path, slice)
146
+ if input_file.source_type == 'path'
147
+ input_file.data = IO.read(input_file.path)
148
+ end
149
+ params[param_name.to_sym] = input_file
141
150
  return call(
142
151
  method: 'POST',
143
152
  path: path,
@@ -147,13 +156,34 @@ module Appwrite
147
156
  )
148
157
  end
149
158
 
150
- input = ::File.open(file_path)
151
159
  offset = 0
160
+ id_param_name = id_param_name.to_sym if id_param_name
161
+ if id_param_name&.empty? == false && params[id_param_name] != "unique()"
162
+ # Make a request to check if a file already exists
163
+ current = call(
164
+ method: "GET",
165
+ path: "#{path}/#{params[id_param_name]}",
166
+ headers: headers,
167
+ params: {}
168
+ )
169
+ chunks_uploaded = current['chunksUploaded'].to_i
170
+ offset = [size, (chunks_uploaded * @chunk_size)].min
171
+ end
152
172
 
153
173
  while offset < size
154
- slice = input.read(@chunk_size)
174
+ case input_file.source_type
175
+ when 'path'
176
+ string = IO.read(input_file.path, @chunk_size, offset)
177
+ when 'string'
178
+ string = input_file.data.byteslice(offset, [@chunk_size, size - offset].min)
179
+ end
180
+
181
+ params[param_name.to_sym] = InputFile::from_string(
182
+ string,
183
+ filename: input_file.filename,
184
+ mime_type: input_file.mime_type
185
+ )
155
186
 
156
- params[param_name] = File.new(file_path, slice)
157
187
  headers['content-range'] = "bytes #{offset}-#{[offset + @chunk_size - 1, size].min}/#{size}"
158
188
 
159
189
  result = call(
@@ -173,8 +203,8 @@ module Appwrite
173
203
  id: result['$id'],
174
204
  progress: ([offset, size].min).to_f/size.to_f * 100.0,
175
205
  size_uploaded: [offset, size].min,
176
- chunks_total: result['chunks_total'],
177
- chunks_uploaded: result['chunks_uploaded']
206
+ chunks_total: result['chunksTotal'],
207
+ chunks_uploaded: result['chunksUploaded']
178
208
  }) unless on_progress.nil?
179
209
  end
180
210
 
@@ -267,10 +297,10 @@ module Appwrite
267
297
  ''
268
298
  else
269
299
  post_body = []
270
- if value.instance_of? File
271
- post_body << "Content-Disposition: form-data; name=\"#{key}\"; filename=\"#{value.name}\"\r\n"
300
+ if value.instance_of? InputFile
301
+ post_body << "Content-Disposition: form-data; name=\"#{key}\"; filename=\"#{value.filename}\"\r\n"
272
302
  post_body << "Content-Type: #{value.mime_type}\r\n\r\n"
273
- post_body << value.content
303
+ post_body << value.data
274
304
  post_body << "\r\n--#{@boundary}--\r\n"
275
305
  else
276
306
  post_body << "Content-Disposition: form-data; name=\"#{key}\"\r\n\r\n"
@@ -0,0 +1,33 @@
1
+ require 'mime/types'
2
+
3
+ module Appwrite
4
+ class InputFile
5
+ attr_accessor :path
6
+ attr_accessor :filename
7
+ attr_accessor :mime_type
8
+ attr_accessor :source_type
9
+ attr_accessor :data
10
+
11
+ def self.from_path(path)
12
+ instance = InputFile.new
13
+ instance.path = path
14
+ instance.filename = ::File.basename(path)
15
+ instance.mime_type = MIME::Types.type_for(path).first.content_type
16
+ instance.source_type = 'path'
17
+ instance
18
+ end
19
+
20
+ def self.from_string(string, filename: nil, mime_type: nil)
21
+ instance = InputFile.new
22
+ instance.data = string
23
+ instance.filename = filename
24
+ instance.mime_type = mime_type
25
+ instance.source_type = 'string'
26
+ instance
27
+ end
28
+
29
+ def self.from_bytes(bytes, filename: nil, mime_type: nil)
30
+ self.from_string(bytes.pack('C*'), filename: filename, mime_type: mime_type)
31
+ end
32
+ end
33
+ end
@@ -4,11 +4,11 @@ module Appwrite
4
4
  module Models
5
5
  class Bucket
6
6
  attr_reader :id
7
+ attr_reader :created_at
8
+ attr_reader :updated_at
7
9
  attr_reader :read
8
10
  attr_reader :write
9
11
  attr_reader :permission
10
- attr_reader :date_created
11
- attr_reader :date_updated
12
12
  attr_reader :name
13
13
  attr_reader :enabled
14
14
  attr_reader :maximum_file_size
@@ -18,11 +18,11 @@ module Appwrite
18
18
 
19
19
  def initialize(
20
20
  id:,
21
+ created_at:,
22
+ updated_at:,
21
23
  read:,
22
24
  write:,
23
25
  permission:,
24
- date_created:,
25
- date_updated:,
26
26
  name:,
27
27
  enabled:,
28
28
  maximum_file_size:,
@@ -31,11 +31,11 @@ module Appwrite
31
31
  antivirus:
32
32
  )
33
33
  @id = id
34
+ @created_at = created_at
35
+ @updated_at = updated_at
34
36
  @read = read
35
37
  @write = write
36
38
  @permission = permission
37
- @date_created = date_created
38
- @date_updated = date_updated
39
39
  @name = name
40
40
  @enabled = enabled
41
41
  @maximum_file_size = maximum_file_size
@@ -47,11 +47,11 @@ module Appwrite
47
47
  def self.from(map:)
48
48
  Bucket.new(
49
49
  id: map["$id"],
50
+ created_at: map["$createdAt"],
51
+ updated_at: map["$updatedAt"],
50
52
  read: map["$read"],
51
53
  write: map["$write"],
52
54
  permission: map["permission"],
53
- date_created: map["dateCreated"],
54
- date_updated: map["dateUpdated"],
55
55
  name: map["name"],
56
56
  enabled: map["enabled"],
57
57
  maximum_file_size: map["maximumFileSize"],
@@ -64,11 +64,11 @@ module Appwrite
64
64
  def to_map
65
65
  {
66
66
  "$id": @id,
67
+ "$createdAt": @created_at,
68
+ "$updatedAt": @updated_at,
67
69
  "$read": @read,
68
70
  "$write": @write,
69
71
  "permission": @permission,
70
- "dateCreated": @date_created,
71
- "dateUpdated": @date_updated,
72
72
  "name": @name,
73
73
  "enabled": @enabled,
74
74
  "maximumFileSize": @maximum_file_size,
@@ -4,8 +4,11 @@ module Appwrite
4
4
  module Models
5
5
  class Collection
6
6
  attr_reader :id
7
+ attr_reader :created_at
8
+ attr_reader :updated_at
7
9
  attr_reader :read
8
10
  attr_reader :write
11
+ attr_reader :database_id
9
12
  attr_reader :name
10
13
  attr_reader :enabled
11
14
  attr_reader :permission
@@ -14,8 +17,11 @@ module Appwrite
14
17
 
15
18
  def initialize(
16
19
  id:,
20
+ created_at:,
21
+ updated_at:,
17
22
  read:,
18
23
  write:,
24
+ database_id:,
19
25
  name:,
20
26
  enabled:,
21
27
  permission:,
@@ -23,8 +29,11 @@ module Appwrite
23
29
  indexes:
24
30
  )
25
31
  @id = id
32
+ @created_at = created_at
33
+ @updated_at = updated_at
26
34
  @read = read
27
35
  @write = write
36
+ @database_id = database_id
28
37
  @name = name
29
38
  @enabled = enabled
30
39
  @permission = permission
@@ -35,8 +44,11 @@ module Appwrite
35
44
  def self.from(map:)
36
45
  Collection.new(
37
46
  id: map["$id"],
47
+ created_at: map["$createdAt"],
48
+ updated_at: map["$updatedAt"],
38
49
  read: map["$read"],
39
50
  write: map["$write"],
51
+ database_id: map["databaseId"],
40
52
  name: map["name"],
41
53
  enabled: map["enabled"],
42
54
  permission: map["permission"],
@@ -48,8 +60,11 @@ module Appwrite
48
60
  def to_map
49
61
  {
50
62
  "$id": @id,
63
+ "$createdAt": @created_at,
64
+ "$updatedAt": @updated_at,
51
65
  "$read": @read,
52
66
  "$write": @write,
67
+ "databaseId": @database_id,
53
68
  "name": @name,
54
69
  "enabled": @enabled,
55
70
  "permission": @permission,
@@ -0,0 +1,32 @@
1
+ #frozen_string_literal: true
2
+
3
+ module Appwrite
4
+ module Models
5
+ class Database
6
+ attr_reader :id
7
+ attr_reader :name
8
+
9
+ def initialize(
10
+ id:,
11
+ name:
12
+ )
13
+ @id = id
14
+ @name = name
15
+ end
16
+
17
+ def self.from(map:)
18
+ Database.new(
19
+ id: map["$id"],
20
+ name: map["name"]
21
+ )
22
+ end
23
+
24
+ def to_map
25
+ {
26
+ "$id": @id,
27
+ "name": @name
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ #frozen_string_literal: true
2
+
3
+ module Appwrite
4
+ module Models
5
+ class DatabaseList
6
+ attr_reader :total
7
+ attr_reader :databases
8
+
9
+ def initialize(
10
+ total:,
11
+ databases:
12
+ )
13
+ @total = total
14
+ @databases = databases
15
+ end
16
+
17
+ def self.from(map:)
18
+ DatabaseList.new(
19
+ total: map["total"],
20
+ databases: map["databases"].map { |it| Database.from(map: it) }
21
+ )
22
+ end
23
+
24
+ def to_map
25
+ {
26
+ "total": @total,
27
+ "databases": @databases.map { |it| it.to_map }
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -4,9 +4,10 @@ module Appwrite
4
4
  module Models
5
5
  class Deployment
6
6
  attr_reader :id
7
+ attr_reader :created_at
8
+ attr_reader :updated_at
7
9
  attr_reader :resource_id
8
10
  attr_reader :resource_type
9
- attr_reader :date_created
10
11
  attr_reader :entrypoint
11
12
  attr_reader :size
12
13
  attr_reader :build_id
@@ -17,9 +18,10 @@ module Appwrite
17
18
 
18
19
  def initialize(
19
20
  id:,
21
+ created_at:,
22
+ updated_at:,
20
23
  resource_id:,
21
24
  resource_type:,
22
- date_created:,
23
25
  entrypoint:,
24
26
  size:,
25
27
  build_id:,
@@ -29,9 +31,10 @@ module Appwrite
29
31
  build_stderr:
30
32
  )
31
33
  @id = id
34
+ @created_at = created_at
35
+ @updated_at = updated_at
32
36
  @resource_id = resource_id
33
37
  @resource_type = resource_type
34
- @date_created = date_created
35
38
  @entrypoint = entrypoint
36
39
  @size = size
37
40
  @build_id = build_id
@@ -44,9 +47,10 @@ module Appwrite
44
47
  def self.from(map:)
45
48
  Deployment.new(
46
49
  id: map["$id"],
50
+ created_at: map["$createdAt"],
51
+ updated_at: map["$updatedAt"],
47
52
  resource_id: map["resourceId"],
48
53
  resource_type: map["resourceType"],
49
- date_created: map["dateCreated"],
50
54
  entrypoint: map["entrypoint"],
51
55
  size: map["size"],
52
56
  build_id: map["buildId"],
@@ -60,9 +64,10 @@ module Appwrite
60
64
  def to_map
61
65
  {
62
66
  "$id": @id,
67
+ "$createdAt": @created_at,
68
+ "$updatedAt": @updated_at,
63
69
  "resourceId": @resource_id,
64
70
  "resourceType": @resource_type,
65
- "dateCreated": @date_created,
66
71
  "entrypoint": @entrypoint,
67
72
  "size": @size,
68
73
  "buildId": @build_id,
@@ -5,18 +5,24 @@ module Appwrite
5
5
  class Document
6
6
  attr_reader :id
7
7
  attr_reader :collection
8
+ attr_reader :created_at
9
+ attr_reader :updated_at
8
10
  attr_reader :read
9
11
  attr_reader :write
10
12
 
11
13
  def initialize(
12
14
  id:,
13
15
  collection:,
16
+ created_at:,
17
+ updated_at:,
14
18
  read:,
15
19
  write:,
16
20
  data:
17
21
  )
18
22
  @id = id
19
23
  @collection = collection
24
+ @created_at = created_at
25
+ @updated_at = updated_at
20
26
  @read = read
21
27
  @write = write
22
28
  @data = data
@@ -26,6 +32,8 @@ module Appwrite
26
32
  Document.new(
27
33
  id: map["$id"],
28
34
  collection: map["$collection"],
35
+ created_at: map["$createdAt"],
36
+ updated_at: map["$updatedAt"],
29
37
  read: map["$read"],
30
38
  write: map["$write"],
31
39
  data: map["data"]
@@ -36,6 +44,8 @@ module Appwrite
36
44
  {
37
45
  "$id": @id,
38
46
  "$collection": @collection,
47
+ "$createdAt": @created_at,
48
+ "$updatedAt": @updated_at,
39
49
  "$read": @read,
40
50
  "$write": @write,
41
51
  "data": @data
@@ -4,36 +4,39 @@ module Appwrite
4
4
  module Models
5
5
  class Execution
6
6
  attr_reader :id
7
+ attr_reader :created_at
8
+ attr_reader :updated_at
7
9
  attr_reader :read
8
10
  attr_reader :function_id
9
- attr_reader :date_created
10
11
  attr_reader :trigger
11
12
  attr_reader :status
12
13
  attr_reader :status_code
13
- attr_reader :stdout
14
+ attr_reader :response
14
15
  attr_reader :stderr
15
16
  attr_reader :time
16
17
 
17
18
  def initialize(
18
19
  id:,
20
+ created_at:,
21
+ updated_at:,
19
22
  read:,
20
23
  function_id:,
21
- date_created:,
22
24
  trigger:,
23
25
  status:,
24
26
  status_code:,
25
- stdout:,
27
+ response:,
26
28
  stderr:,
27
29
  time:
28
30
  )
29
31
  @id = id
32
+ @created_at = created_at
33
+ @updated_at = updated_at
30
34
  @read = read
31
35
  @function_id = function_id
32
- @date_created = date_created
33
36
  @trigger = trigger
34
37
  @status = status
35
38
  @status_code = status_code
36
- @stdout = stdout
39
+ @response = response
37
40
  @stderr = stderr
38
41
  @time = time
39
42
  end
@@ -41,13 +44,14 @@ module Appwrite
41
44
  def self.from(map:)
42
45
  Execution.new(
43
46
  id: map["$id"],
47
+ created_at: map["$createdAt"],
48
+ updated_at: map["$updatedAt"],
44
49
  read: map["$read"],
45
50
  function_id: map["functionId"],
46
- date_created: map["dateCreated"],
47
51
  trigger: map["trigger"],
48
52
  status: map["status"],
49
53
  status_code: map["statusCode"],
50
- stdout: map["stdout"],
54
+ response: map["response"],
51
55
  stderr: map["stderr"],
52
56
  time: map["time"]
53
57
  )
@@ -56,13 +60,14 @@ module Appwrite
56
60
  def to_map
57
61
  {
58
62
  "$id": @id,
63
+ "$createdAt": @created_at,
64
+ "$updatedAt": @updated_at,
59
65
  "$read": @read,
60
66
  "functionId": @function_id,
61
- "dateCreated": @date_created,
62
67
  "trigger": @trigger,
63
68
  "status": @status,
64
69
  "statusCode": @status_code,
65
- "stdout": @stdout,
70
+ "response": @response,
66
71
  "stderr": @stderr,
67
72
  "time": @time
68
73
  }
@@ -5,10 +5,11 @@ module Appwrite
5
5
  class File
6
6
  attr_reader :id
7
7
  attr_reader :bucket_id
8
+ attr_reader :created_at
9
+ attr_reader :updated_at
8
10
  attr_reader :read
9
11
  attr_reader :write
10
12
  attr_reader :name
11
- attr_reader :date_created
12
13
  attr_reader :signature
13
14
  attr_reader :mime_type
14
15
  attr_reader :size_original
@@ -18,10 +19,11 @@ module Appwrite
18
19
  def initialize(
19
20
  id:,
20
21
  bucket_id:,
22
+ created_at:,
23
+ updated_at:,
21
24
  read:,
22
25
  write:,
23
26
  name:,
24
- date_created:,
25
27
  signature:,
26
28
  mime_type:,
27
29
  size_original:,
@@ -30,10 +32,11 @@ module Appwrite
30
32
  )
31
33
  @id = id
32
34
  @bucket_id = bucket_id
35
+ @created_at = created_at
36
+ @updated_at = updated_at
33
37
  @read = read
34
38
  @write = write
35
39
  @name = name
36
- @date_created = date_created
37
40
  @signature = signature
38
41
  @mime_type = mime_type
39
42
  @size_original = size_original
@@ -45,10 +48,11 @@ module Appwrite
45
48
  File.new(
46
49
  id: map["$id"],
47
50
  bucket_id: map["bucketId"],
51
+ created_at: map["$createdAt"],
52
+ updated_at: map["$updatedAt"],
48
53
  read: map["$read"],
49
54
  write: map["$write"],
50
55
  name: map["name"],
51
- date_created: map["dateCreated"],
52
56
  signature: map["signature"],
53
57
  mime_type: map["mimeType"],
54
58
  size_original: map["sizeOriginal"],
@@ -61,10 +65,11 @@ module Appwrite
61
65
  {
62
66
  "$id": @id,
63
67
  "bucketId": @bucket_id,
68
+ "$createdAt": @created_at,
69
+ "$updatedAt": @updated_at,
64
70
  "$read": @read,
65
71
  "$write": @write,
66
72
  "name": @name,
67
- "dateCreated": @date_created,
68
73
  "signature": @signature,
69
74
  "mimeType": @mime_type,
70
75
  "sizeOriginal": @size_original,
@@ -4,10 +4,10 @@ module Appwrite
4
4
  module Models
5
5
  class Function
6
6
  attr_reader :id
7
+ attr_reader :created_at
8
+ attr_reader :updated_at
7
9
  attr_reader :execute
8
10
  attr_reader :name
9
- attr_reader :date_created
10
- attr_reader :date_updated
11
11
  attr_reader :status
12
12
  attr_reader :runtime
13
13
  attr_reader :deployment
@@ -20,10 +20,10 @@ module Appwrite
20
20
 
21
21
  def initialize(
22
22
  id:,
23
+ created_at:,
24
+ updated_at:,
23
25
  execute:,
24
26
  name:,
25
- date_created:,
26
- date_updated:,
27
27
  status:,
28
28
  runtime:,
29
29
  deployment:,
@@ -35,10 +35,10 @@ module Appwrite
35
35
  timeout:
36
36
  )
37
37
  @id = id
38
+ @created_at = created_at
39
+ @updated_at = updated_at
38
40
  @execute = execute
39
41
  @name = name
40
- @date_created = date_created
41
- @date_updated = date_updated
42
42
  @status = status
43
43
  @runtime = runtime
44
44
  @deployment = deployment
@@ -53,10 +53,10 @@ module Appwrite
53
53
  def self.from(map:)
54
54
  Function.new(
55
55
  id: map["$id"],
56
+ created_at: map["$createdAt"],
57
+ updated_at: map["$updatedAt"],
56
58
  execute: map["execute"],
57
59
  name: map["name"],
58
- date_created: map["dateCreated"],
59
- date_updated: map["dateUpdated"],
60
60
  status: map["status"],
61
61
  runtime: map["runtime"],
62
62
  deployment: map["deployment"],
@@ -72,10 +72,10 @@ module Appwrite
72
72
  def to_map
73
73
  {
74
74
  "$id": @id,
75
+ "$createdAt": @created_at,
76
+ "$updatedAt": @updated_at,
75
77
  "execute": @execute,
76
78
  "name": @name,
77
- "dateCreated": @date_created,
78
- "dateUpdated": @date_updated,
79
79
  "status": @status,
80
80
  "runtime": @runtime,
81
81
  "deployment": @deployment,