appwrite 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/appwrite/client.rb +69 -5
  3. data/lib/appwrite/exception.rb +3 -1
  4. data/lib/appwrite/file.rb +4 -2
  5. data/lib/appwrite/models/attribute_list.rb +5 -5
  6. data/lib/appwrite/models/bucket.rb +82 -0
  7. data/lib/appwrite/models/bucket_list.rb +32 -0
  8. data/lib/appwrite/models/collection_list.rb +5 -5
  9. data/lib/appwrite/models/continent_list.rb +5 -5
  10. data/lib/appwrite/models/country_list.rb +5 -5
  11. data/lib/appwrite/models/currency_list.rb +5 -5
  12. data/lib/appwrite/models/deployment.rb +77 -0
  13. data/lib/appwrite/models/deployment_list.rb +32 -0
  14. data/lib/appwrite/models/document_list.rb +5 -5
  15. data/lib/appwrite/models/execution.rb +5 -5
  16. data/lib/appwrite/models/execution_list.rb +5 -5
  17. data/lib/appwrite/models/file.rb +18 -3
  18. data/lib/appwrite/models/file_list.rb +5 -5
  19. data/lib/appwrite/models/function.rb +5 -5
  20. data/lib/appwrite/models/function_list.rb +5 -5
  21. data/lib/appwrite/models/index_list.rb +5 -5
  22. data/lib/appwrite/models/language_list.rb +5 -5
  23. data/lib/appwrite/models/log_list.rb +5 -5
  24. data/lib/appwrite/models/membership_list.rb +5 -5
  25. data/lib/appwrite/models/phone_list.rb +5 -5
  26. data/lib/appwrite/models/runtime_list.rb +5 -5
  27. data/lib/appwrite/models/session.rb +15 -5
  28. data/lib/appwrite/models/session_list.rb +5 -5
  29. data/lib/appwrite/models/team.rb +5 -5
  30. data/lib/appwrite/models/team_list.rb +5 -5
  31. data/lib/appwrite/models/user_list.rb +5 -5
  32. data/lib/appwrite/services/account.rb +62 -32
  33. data/lib/appwrite/services/avatars.rb +7 -8
  34. data/lib/appwrite/services/database.rb +52 -53
  35. data/lib/appwrite/services/functions.rb +175 -125
  36. data/lib/appwrite/services/health.rb +22 -23
  37. data/lib/appwrite/services/locale.rb +14 -15
  38. data/lib/appwrite/services/storage.rb +309 -47
  39. data/lib/appwrite/services/teams.rb +25 -22
  40. data/lib/appwrite/services/users.rb +31 -31
  41. data/lib/appwrite.rb +5 -3
  42. metadata +8 -6
  43. data/lib/appwrite/models/tag.rb +0 -47
  44. data/lib/appwrite/models/tag_list.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: faf26d54d0dd35ecb6279029fc13a153e824c91a0f6daa78dd0b3aa9b14e7337
4
- data.tar.gz: 35bfcac6e7bcc0aeadc0a91a5ae07a9c18ab9f2d01e17f4e2132ff243f0f2690
3
+ metadata.gz: c885588668d4133732a6a6acf50beaa77734e71057417396d474e93b492029c5
4
+ data.tar.gz: 7711957f95eb038ad03e6c503a55dc61b3e0c7313e15308451a254cb35093b29
5
5
  SHA512:
6
- metadata.gz: 072d20868a6b076d8dfa50f2c18d9f1c263523b871307cbaebd98df406f388bf6b7b6aff4b499a9f03168df2ead42cb45d20f4354559e38149e407d34f6a8d73
7
- data.tar.gz: 52e32436fd5f535fabbc46bf0bde38df598a8ef7a0b2cc092ee9867943877854c00cfd8aa845d86090789b9a84eb0eeaeb0456460a4a8176c6a370f4f6747c03
6
+ metadata.gz: e7eb2a20711fd0e4f0650e39c89ae553d36f9f1e3dd2cdd5408b37555c6b75dbd45078018f5a68de3f5b568d91430871114e2afc287c5dbf058abe20ef33ea4d
7
+ data.tar.gz: 79804f75cbf28704a84d4c83401cc9873bc46bab9aa5b31198db05929f441fb6c8baee04adb3c04b0f385cbb0a5347df542ec37d6d1f80032c700a899c7a6a4e
@@ -9,10 +9,11 @@ module Appwrite
9
9
  class Client
10
10
 
11
11
  def initialize
12
+ @chunk_size = 5*1024*1024
12
13
  @headers = {
13
14
  'user-agent' => RUBY_PLATFORM + ':ruby-' + RUBY_VERSION,
14
- 'x-sdk-version' => 'appwrite:ruby:3.0.0',
15
- 'X-Appwrite-Response-Format' => '0.12.0'
15
+ 'x-sdk-version' => 'appwrite:ruby:4.0.0',
16
+ 'X-Appwrite-Response-Format' => '0.13.0'
16
17
  }
17
18
  @endpoint = 'https://HOSTNAME/v1'
18
19
  end
@@ -123,6 +124,65 @@ module Appwrite
123
124
  fetch(method, uri, headers, params, response_type)
124
125
  end
125
126
 
127
+ def chunked_upload(
128
+ path:,
129
+ headers:,
130
+ params:,
131
+ param_name: '',
132
+ on_progress: nil,
133
+ response_type: nil
134
+ )
135
+ file_path = params[param_name.to_sym]
136
+ size = ::File.size(file_path)
137
+
138
+ if size < @chunk_size
139
+ slice = ::File.read(file_path)
140
+ params[param_name] = File.new(file_path, slice)
141
+ return call(
142
+ method: 'POST',
143
+ path: path,
144
+ headers: headers,
145
+ params: params,
146
+ response_type: response_type,
147
+ )
148
+ end
149
+
150
+ input = ::File.open(file_path)
151
+ offset = 0
152
+
153
+ while offset < size
154
+ slice = input.read(@chunk_size)
155
+
156
+ params[param_name] = File.new(file_path, slice)
157
+ headers['content-range'] = "bytes #{offset}-#{[offset + @chunk_size - 1, size].min}/#{size}"
158
+
159
+ result = call(
160
+ method: 'POST',
161
+ path: path,
162
+ headers: headers,
163
+ params: params,
164
+ )
165
+
166
+ offset += @chunk_size
167
+
168
+ if defined? result['$id']
169
+ headers['x-Appwrite-id'] = result['$id']
170
+ end
171
+
172
+ on_progress.call({
173
+ id: result['$id'],
174
+ progress: ([offset, size].min).to_f/size.to_f * 100.0,
175
+ size_uploaded: [offset, size].min,
176
+ chunks_total: result['chunks_total'],
177
+ chunks_uploaded: result['chunks_uploaded']
178
+ }) unless on_progress.nil?
179
+ end
180
+
181
+ return result unless response_type.respond_to?("from")
182
+
183
+ response_type.from(map: result)
184
+ end
185
+
126
186
  private
127
187
 
128
188
  def fetch(
@@ -172,11 +232,11 @@ module Appwrite
172
232
  begin
173
233
  result = JSON.parse(response.body)
174
234
  rescue JSON::ParserError => e
175
- raise Appwrite::Exception.new(response.body, response.code, response)
235
+ raise Appwrite::Exception.new(response.body, response.code, nil, response)
176
236
  end
177
237
 
178
238
  if response.code.to_i >= 400
179
- raise Appwrite::Exception.new(result['message'], result['status'], result)
239
+ raise Appwrite::Exception.new(result['message'], result['status'], result['type'], result)
180
240
  end
181
241
 
182
242
  unless response_type.respond_to?("from")
@@ -190,7 +250,11 @@ module Appwrite
190
250
  raise Appwrite::Exception.new(response.body, response.code, response)
191
251
  end
192
252
 
193
- return response.body if response.body_permitted?
253
+ if response.respond_to?("body_permitted?")
254
+ return response.body if response.body_permitted?
255
+ end
256
+
257
+ return response
194
258
  end
195
259
 
196
260
  def encode_form_data(value, key=nil)
@@ -2,10 +2,12 @@ module Appwrite
2
2
  class Exception < StandardError
3
3
  attr_reader :code
4
4
  attr_reader :response
5
+ attr_reader :type
5
6
 
6
- def initialize(message, code = 0, response = nil)
7
+ def initialize(message, code = 0, type = nil, response = nil)
7
8
  super(message)
8
9
  @code = code
10
+ @type = type
9
11
  @response = response
10
12
  end
11
13
  end
data/lib/appwrite/file.rb CHANGED
@@ -2,13 +2,15 @@ require 'mime/types'
2
2
 
3
3
  module Appwrite
4
4
  class File
5
+ attr_reader :path
5
6
  attr_reader :name
6
7
  attr_reader :content
7
8
  attr_reader :mime_type
8
9
 
9
- def initialize(path)
10
+ def initialize(path, content)
11
+ @path = path
12
+ @content = content
10
13
  @name = ::File.basename(path)
11
- @content = ::File.read(path)
12
14
  @mime_type = MIME::Types.type_for(path)
13
15
  end
14
16
  end
@@ -3,27 +3,27 @@
3
3
  module Appwrite
4
4
  module Models
5
5
  class AttributeList
6
- attr_reader :sum
6
+ attr_reader :total
7
7
  attr_reader :attributes
8
8
 
9
9
  def initialize(
10
- sum:,
10
+ total:,
11
11
  attributes:
12
12
  )
13
- @sum = sum
13
+ @total = total
14
14
  @attributes = attributes
15
15
  end
16
16
 
17
17
  def self.from(map:)
18
18
  AttributeList.new(
19
- sum: map["sum"],
19
+ total: map["total"],
20
20
  attributes: map["attributes"]
21
21
  )
22
22
  end
23
23
 
24
24
  def to_map
25
25
  {
26
- "sum": @sum,
26
+ "total": @total,
27
27
  "attributes": @attributes
28
28
  }
29
29
  end
@@ -0,0 +1,82 @@
1
+ #frozen_string_literal: true
2
+
3
+ module Appwrite
4
+ module Models
5
+ class Bucket
6
+ attr_reader :id
7
+ attr_reader :read
8
+ attr_reader :write
9
+ attr_reader :permission
10
+ attr_reader :date_created
11
+ attr_reader :date_updated
12
+ attr_reader :name
13
+ attr_reader :enabled
14
+ attr_reader :maximum_file_size
15
+ attr_reader :allowed_file_extensions
16
+ attr_reader :encryption
17
+ attr_reader :antivirus
18
+
19
+ def initialize(
20
+ id:,
21
+ read:,
22
+ write:,
23
+ permission:,
24
+ date_created:,
25
+ date_updated:,
26
+ name:,
27
+ enabled:,
28
+ maximum_file_size:,
29
+ allowed_file_extensions:,
30
+ encryption:,
31
+ antivirus:
32
+ )
33
+ @id = id
34
+ @read = read
35
+ @write = write
36
+ @permission = permission
37
+ @date_created = date_created
38
+ @date_updated = date_updated
39
+ @name = name
40
+ @enabled = enabled
41
+ @maximum_file_size = maximum_file_size
42
+ @allowed_file_extensions = allowed_file_extensions
43
+ @encryption = encryption
44
+ @antivirus = antivirus
45
+ end
46
+
47
+ def self.from(map:)
48
+ Bucket.new(
49
+ id: map["$id"],
50
+ read: map["$read"],
51
+ write: map["$write"],
52
+ permission: map["permission"],
53
+ date_created: map["dateCreated"],
54
+ date_updated: map["dateUpdated"],
55
+ name: map["name"],
56
+ enabled: map["enabled"],
57
+ maximum_file_size: map["maximumFileSize"],
58
+ allowed_file_extensions: map["allowedFileExtensions"],
59
+ encryption: map["encryption"],
60
+ antivirus: map["antivirus"]
61
+ )
62
+ end
63
+
64
+ def to_map
65
+ {
66
+ "$id": @id,
67
+ "$read": @read,
68
+ "$write": @write,
69
+ "permission": @permission,
70
+ "dateCreated": @date_created,
71
+ "dateUpdated": @date_updated,
72
+ "name": @name,
73
+ "enabled": @enabled,
74
+ "maximumFileSize": @maximum_file_size,
75
+ "allowedFileExtensions": @allowed_file_extensions,
76
+ "encryption": @encryption,
77
+ "antivirus": @antivirus
78
+ }
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,32 @@
1
+ #frozen_string_literal: true
2
+
3
+ module Appwrite
4
+ module Models
5
+ class BucketList
6
+ attr_reader :total
7
+ attr_reader :buckets
8
+
9
+ def initialize(
10
+ total:,
11
+ buckets:
12
+ )
13
+ @total = total
14
+ @buckets = buckets
15
+ end
16
+
17
+ def self.from(map:)
18
+ BucketList.new(
19
+ total: map["total"],
20
+ buckets: map["buckets"].map { |it| Bucket.from(map: it) }
21
+ )
22
+ end
23
+
24
+ def to_map
25
+ {
26
+ "total": @total,
27
+ "buckets": @buckets.map { |it| it.to_map }
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -3,27 +3,27 @@
3
3
  module Appwrite
4
4
  module Models
5
5
  class CollectionList
6
- attr_reader :sum
6
+ attr_reader :total
7
7
  attr_reader :collections
8
8
 
9
9
  def initialize(
10
- sum:,
10
+ total:,
11
11
  collections:
12
12
  )
13
- @sum = sum
13
+ @total = total
14
14
  @collections = collections
15
15
  end
16
16
 
17
17
  def self.from(map:)
18
18
  CollectionList.new(
19
- sum: map["sum"],
19
+ total: map["total"],
20
20
  collections: map["collections"].map { |it| Collection.from(map: it) }
21
21
  )
22
22
  end
23
23
 
24
24
  def to_map
25
25
  {
26
- "sum": @sum,
26
+ "total": @total,
27
27
  "collections": @collections.map { |it| it.to_map }
28
28
  }
29
29
  end
@@ -3,27 +3,27 @@
3
3
  module Appwrite
4
4
  module Models
5
5
  class ContinentList
6
- attr_reader :sum
6
+ attr_reader :total
7
7
  attr_reader :continents
8
8
 
9
9
  def initialize(
10
- sum:,
10
+ total:,
11
11
  continents:
12
12
  )
13
- @sum = sum
13
+ @total = total
14
14
  @continents = continents
15
15
  end
16
16
 
17
17
  def self.from(map:)
18
18
  ContinentList.new(
19
- sum: map["sum"],
19
+ total: map["total"],
20
20
  continents: map["continents"].map { |it| Continent.from(map: it) }
21
21
  )
22
22
  end
23
23
 
24
24
  def to_map
25
25
  {
26
- "sum": @sum,
26
+ "total": @total,
27
27
  "continents": @continents.map { |it| it.to_map }
28
28
  }
29
29
  end
@@ -3,27 +3,27 @@
3
3
  module Appwrite
4
4
  module Models
5
5
  class CountryList
6
- attr_reader :sum
6
+ attr_reader :total
7
7
  attr_reader :countries
8
8
 
9
9
  def initialize(
10
- sum:,
10
+ total:,
11
11
  countries:
12
12
  )
13
- @sum = sum
13
+ @total = total
14
14
  @countries = countries
15
15
  end
16
16
 
17
17
  def self.from(map:)
18
18
  CountryList.new(
19
- sum: map["sum"],
19
+ total: map["total"],
20
20
  countries: map["countries"].map { |it| Country.from(map: it) }
21
21
  )
22
22
  end
23
23
 
24
24
  def to_map
25
25
  {
26
- "sum": @sum,
26
+ "total": @total,
27
27
  "countries": @countries.map { |it| it.to_map }
28
28
  }
29
29
  end
@@ -3,27 +3,27 @@
3
3
  module Appwrite
4
4
  module Models
5
5
  class CurrencyList
6
- attr_reader :sum
6
+ attr_reader :total
7
7
  attr_reader :currencies
8
8
 
9
9
  def initialize(
10
- sum:,
10
+ total:,
11
11
  currencies:
12
12
  )
13
- @sum = sum
13
+ @total = total
14
14
  @currencies = currencies
15
15
  end
16
16
 
17
17
  def self.from(map:)
18
18
  CurrencyList.new(
19
- sum: map["sum"],
19
+ total: map["total"],
20
20
  currencies: map["currencies"].map { |it| Currency.from(map: it) }
21
21
  )
22
22
  end
23
23
 
24
24
  def to_map
25
25
  {
26
- "sum": @sum,
26
+ "total": @total,
27
27
  "currencies": @currencies.map { |it| it.to_map }
28
28
  }
29
29
  end
@@ -0,0 +1,77 @@
1
+ #frozen_string_literal: true
2
+
3
+ module Appwrite
4
+ module Models
5
+ class Deployment
6
+ attr_reader :id
7
+ attr_reader :resource_id
8
+ attr_reader :resource_type
9
+ attr_reader :date_created
10
+ attr_reader :entrypoint
11
+ attr_reader :size
12
+ attr_reader :build_id
13
+ attr_reader :activate
14
+ attr_reader :status
15
+ attr_reader :build_stdout
16
+ attr_reader :build_stderr
17
+
18
+ def initialize(
19
+ id:,
20
+ resource_id:,
21
+ resource_type:,
22
+ date_created:,
23
+ entrypoint:,
24
+ size:,
25
+ build_id:,
26
+ activate:,
27
+ status:,
28
+ build_stdout:,
29
+ build_stderr:
30
+ )
31
+ @id = id
32
+ @resource_id = resource_id
33
+ @resource_type = resource_type
34
+ @date_created = date_created
35
+ @entrypoint = entrypoint
36
+ @size = size
37
+ @build_id = build_id
38
+ @activate = activate
39
+ @status = status
40
+ @build_stdout = build_stdout
41
+ @build_stderr = build_stderr
42
+ end
43
+
44
+ def self.from(map:)
45
+ Deployment.new(
46
+ id: map["$id"],
47
+ resource_id: map["resourceId"],
48
+ resource_type: map["resourceType"],
49
+ date_created: map["dateCreated"],
50
+ entrypoint: map["entrypoint"],
51
+ size: map["size"],
52
+ build_id: map["buildId"],
53
+ activate: map["activate"],
54
+ status: map["status"],
55
+ build_stdout: map["buildStdout"],
56
+ build_stderr: map["buildStderr"]
57
+ )
58
+ end
59
+
60
+ def to_map
61
+ {
62
+ "$id": @id,
63
+ "resourceId": @resource_id,
64
+ "resourceType": @resource_type,
65
+ "dateCreated": @date_created,
66
+ "entrypoint": @entrypoint,
67
+ "size": @size,
68
+ "buildId": @build_id,
69
+ "activate": @activate,
70
+ "status": @status,
71
+ "buildStdout": @build_stdout,
72
+ "buildStderr": @build_stderr
73
+ }
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,32 @@
1
+ #frozen_string_literal: true
2
+
3
+ module Appwrite
4
+ module Models
5
+ class DeploymentList
6
+ attr_reader :total
7
+ attr_reader :deployments
8
+
9
+ def initialize(
10
+ total:,
11
+ deployments:
12
+ )
13
+ @total = total
14
+ @deployments = deployments
15
+ end
16
+
17
+ def self.from(map:)
18
+ DeploymentList.new(
19
+ total: map["total"],
20
+ deployments: map["deployments"].map { |it| Deployment.from(map: it) }
21
+ )
22
+ end
23
+
24
+ def to_map
25
+ {
26
+ "total": @total,
27
+ "deployments": @deployments.map { |it| it.to_map }
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -3,27 +3,27 @@
3
3
  module Appwrite
4
4
  module Models
5
5
  class DocumentList
6
- attr_reader :sum
6
+ attr_reader :total
7
7
  attr_reader :documents
8
8
 
9
9
  def initialize(
10
- sum:,
10
+ total:,
11
11
  documents:
12
12
  )
13
- @sum = sum
13
+ @total = total
14
14
  @documents = documents
15
15
  end
16
16
 
17
17
  def self.from(map:)
18
18
  DocumentList.new(
19
- sum: map["sum"],
19
+ total: map["total"],
20
20
  documents: map["documents"].map { |it| Document.from(map: it) }
21
21
  )
22
22
  end
23
23
 
24
24
  def to_map
25
25
  {
26
- "sum": @sum,
26
+ "total": @total,
27
27
  "documents": @documents.map { |it| it.to_map }
28
28
  }
29
29
  end
@@ -9,7 +9,7 @@ module Appwrite
9
9
  attr_reader :date_created
10
10
  attr_reader :trigger
11
11
  attr_reader :status
12
- attr_reader :exit_code
12
+ attr_reader :status_code
13
13
  attr_reader :stdout
14
14
  attr_reader :stderr
15
15
  attr_reader :time
@@ -21,7 +21,7 @@ module Appwrite
21
21
  date_created:,
22
22
  trigger:,
23
23
  status:,
24
- exit_code:,
24
+ status_code:,
25
25
  stdout:,
26
26
  stderr:,
27
27
  time:
@@ -32,7 +32,7 @@ module Appwrite
32
32
  @date_created = date_created
33
33
  @trigger = trigger
34
34
  @status = status
35
- @exit_code = exit_code
35
+ @status_code = status_code
36
36
  @stdout = stdout
37
37
  @stderr = stderr
38
38
  @time = time
@@ -46,7 +46,7 @@ module Appwrite
46
46
  date_created: map["dateCreated"],
47
47
  trigger: map["trigger"],
48
48
  status: map["status"],
49
- exit_code: map["exitCode"],
49
+ status_code: map["statusCode"],
50
50
  stdout: map["stdout"],
51
51
  stderr: map["stderr"],
52
52
  time: map["time"]
@@ -61,7 +61,7 @@ module Appwrite
61
61
  "dateCreated": @date_created,
62
62
  "trigger": @trigger,
63
63
  "status": @status,
64
- "exitCode": @exit_code,
64
+ "statusCode": @status_code,
65
65
  "stdout": @stdout,
66
66
  "stderr": @stderr,
67
67
  "time": @time
@@ -3,27 +3,27 @@
3
3
  module Appwrite
4
4
  module Models
5
5
  class ExecutionList
6
- attr_reader :sum
6
+ attr_reader :total
7
7
  attr_reader :executions
8
8
 
9
9
  def initialize(
10
- sum:,
10
+ total:,
11
11
  executions:
12
12
  )
13
- @sum = sum
13
+ @total = total
14
14
  @executions = executions
15
15
  end
16
16
 
17
17
  def self.from(map:)
18
18
  ExecutionList.new(
19
- sum: map["sum"],
19
+ total: map["total"],
20
20
  executions: map["executions"].map { |it| Execution.from(map: it) }
21
21
  )
22
22
  end
23
23
 
24
24
  def to_map
25
25
  {
26
- "sum": @sum,
26
+ "total": @total,
27
27
  "executions": @executions.map { |it| it.to_map }
28
28
  }
29
29
  end