appwrite 2.0.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/Gemfile +1 -1
  4. data/README.md +74 -6
  5. data/appwrite.gemspec +2 -2
  6. data/docs/examples/account/create-recovery.md +15 -0
  7. data/docs/examples/account/create-verification.md +15 -0
  8. data/docs/examples/account/delete-session.md +15 -0
  9. data/docs/examples/account/delete-sessions.md +15 -0
  10. data/docs/examples/account/delete.md +15 -0
  11. data/docs/examples/account/get-logs.md +15 -0
  12. data/docs/examples/account/get-prefs.md +15 -0
  13. data/docs/examples/account/get-session.md +15 -0
  14. data/docs/examples/account/get-sessions.md +15 -0
  15. data/docs/examples/account/get.md +15 -0
  16. data/docs/examples/account/update-email.md +15 -0
  17. data/docs/examples/account/update-name.md +15 -0
  18. data/docs/examples/account/update-password.md +15 -0
  19. data/docs/examples/account/update-prefs.md +15 -0
  20. data/docs/examples/account/update-recovery.md +15 -0
  21. data/docs/examples/account/update-verification.md +15 -0
  22. data/docs/examples/avatars/get-q-r.md +1 -1
  23. data/docs/examples/database/create-document.md +1 -1
  24. data/docs/examples/database/update-collection.md +1 -1
  25. data/docs/examples/database/update-document.md +1 -1
  26. data/docs/examples/functions/create.md +1 -1
  27. data/docs/examples/health/get-d-b.md +1 -1
  28. data/docs/examples/locale/get-countries-e-u.md +1 -1
  29. data/docs/examples/storage/create-file.md +1 -1
  30. data/docs/examples/teams/delete-membership.md +1 -1
  31. data/docs/examples/teams/update-membership-roles.md +15 -0
  32. data/docs/examples/teams/update-membership-status.md +15 -0
  33. data/docs/examples/users/{delete-user.md → delete.md} +1 -1
  34. data/docs/examples/users/update-status.md +1 -1
  35. data/docs/examples/users/update-verification.md +15 -0
  36. data/lib/appwrite.rb +2 -0
  37. data/lib/appwrite/client.rb +21 -5
  38. data/lib/appwrite/exception.rb +14 -0
  39. data/lib/appwrite/services/account.rb +295 -0
  40. data/lib/appwrite/services/avatars.rb +125 -42
  41. data/lib/appwrite/services/database.rb +199 -53
  42. data/lib/appwrite/services/functions.rb +223 -60
  43. data/lib/appwrite/services/health.rb +13 -25
  44. data/lib/appwrite/services/locale.rb +8 -15
  45. data/lib/appwrite/services/storage.rb +127 -33
  46. data/lib/appwrite/services/teams.rb +187 -38
  47. data/lib/appwrite/services/users.rb +129 -34
  48. metadata +24 -3
@@ -10,6 +10,6 @@ client
10
10
 
11
11
  functions = Appwrite::Functions.new(client);
12
12
 
13
- response = functions.create(name: '[NAME]', execute: [], env: 'node-14.5');
13
+ response = functions.create(name: '[NAME]', execute: [], runtime: 'java-11.0');
14
14
 
15
15
  puts response
@@ -10,6 +10,6 @@ client
10
10
 
11
11
  health = Appwrite::Health.new(client);
12
12
 
13
- response = health.get_d_b();
13
+ response = health.get_db();
14
14
 
15
15
  puts response
@@ -10,6 +10,6 @@ client
10
10
 
11
11
  locale = Appwrite::Locale.new(client);
12
12
 
13
- response = locale.get_countries_e_u();
13
+ response = locale.get_countries_eu();
14
14
 
15
15
  puts response
@@ -10,6 +10,6 @@ client
10
10
 
11
11
  storage = Appwrite::Storage.new(client);
12
12
 
13
- response = storage.create_file(file: Appwrite::File.new(), read: [], write: []);
13
+ response = storage.create_file(file: Appwrite::File.new());
14
14
 
15
15
  puts response
@@ -10,6 +10,6 @@ client
10
10
 
11
11
  teams = Appwrite::Teams.new(client);
12
12
 
13
- response = teams.delete_membership(team_id: '[TEAM_ID]', invite_id: '[INVITE_ID]');
13
+ response = teams.delete_membership(team_id: '[TEAM_ID]', membership_id: '[MEMBERSHIP_ID]');
14
14
 
15
15
  puts response
@@ -0,0 +1,15 @@
1
+ require 'appwrite'
2
+
3
+ client = Appwrite::Client.new()
4
+
5
+ client
6
+ .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
7
+ .set_project('5df5acd0d48c2') # Your project ID
8
+ .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
9
+ ;
10
+
11
+ teams = Appwrite::Teams.new(client);
12
+
13
+ response = teams.update_membership_roles(team_id: '[TEAM_ID]', membership_id: '[MEMBERSHIP_ID]', roles: []);
14
+
15
+ puts response
@@ -0,0 +1,15 @@
1
+ require 'appwrite'
2
+
3
+ client = Appwrite::Client.new()
4
+
5
+ client
6
+ .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
7
+ .set_project('5df5acd0d48c2') # Your project ID
8
+ .set_jwt('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') # Your secret JSON Web Token
9
+ ;
10
+
11
+ teams = Appwrite::Teams.new(client);
12
+
13
+ response = teams.update_membership_status(team_id: '[TEAM_ID]', membership_id: '[MEMBERSHIP_ID]', user_id: '[USER_ID]', secret: '[SECRET]');
14
+
15
+ puts response
@@ -10,6 +10,6 @@ client
10
10
 
11
11
  users = Appwrite::Users.new(client);
12
12
 
13
- response = users.delete_user(user_id: '[USER_ID]');
13
+ response = users.delete(user_id: '[USER_ID]');
14
14
 
15
15
  puts response
@@ -10,6 +10,6 @@ client
10
10
 
11
11
  users = Appwrite::Users.new(client);
12
12
 
13
- response = users.update_status(user_id: '[USER_ID]', status: '1');
13
+ response = users.update_status(user_id: '[USER_ID]', status: 1);
14
14
 
15
15
  puts response
@@ -0,0 +1,15 @@
1
+ require 'appwrite'
2
+
3
+ client = Appwrite::Client.new()
4
+
5
+ client
6
+ .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
7
+ .set_project('5df5acd0d48c2') # Your project ID
8
+ .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
9
+ ;
10
+
11
+ users = Appwrite::Users.new(client);
12
+
13
+ response = users.update_verification(user_id: '[USER_ID]', email_verification: false);
14
+
15
+ puts response
data/lib/appwrite.rb CHANGED
@@ -4,7 +4,9 @@ require 'json'
4
4
  require 'mime/types'
5
5
  require_relative 'appwrite/client'
6
6
  require_relative 'appwrite/service'
7
+ require_relative 'appwrite/exception'
7
8
  require_relative 'appwrite/file'
9
+ require_relative 'appwrite/services/account'
8
10
  require_relative 'appwrite/services/avatars'
9
11
  require_relative 'appwrite/services/database'
10
12
  require_relative 'appwrite/services/functions'
@@ -20,8 +20,8 @@ module Appwrite
20
20
  @headers = {
21
21
  'content-type' => '',
22
22
  'user-agent' => RUBY_PLATFORM + ':ruby-' + RUBY_VERSION,
23
- 'x-sdk-version' => 'appwrite:ruby:2.0.0'
24
-
23
+ 'x-sdk-version' => 'appwrite:ruby:2.3.0',
24
+ 'X-Appwrite-Response-Format' => '0.9.0'
25
25
  }
26
26
  @endpoint = 'https://appwrite.io/v1';
27
27
  end
@@ -38,6 +38,12 @@ module Appwrite
38
38
  return self
39
39
  end
40
40
 
41
+ def set_jwt(value)
42
+ add_header('x-appwrite-jwt', value)
43
+
44
+ return self
45
+ end
46
+
41
47
  def set_locale(value)
42
48
  add_header('x-appwrite-locale', value)
43
49
 
@@ -51,7 +57,7 @@ module Appwrite
51
57
  end
52
58
 
53
59
  def add_header(key, value)
54
- @headers[key.downcase] = value.downcase
60
+ @headers[key.downcase] = value
55
61
 
56
62
  return self
57
63
  end
@@ -89,7 +95,7 @@ module Appwrite
89
95
  begin
90
96
  response = http.send_request(method.upcase, uri.request_uri, payload, headers)
91
97
  rescue => error
92
- raise 'Request Failed: ' + error.message
98
+ raise Appwrite::Exception.new(error.message)
93
99
  end
94
100
 
95
101
  # Handle Redirects
@@ -99,8 +105,18 @@ module Appwrite
99
105
 
100
106
  return fetch(method, uri, headers, {}, limit - 1)
101
107
  end
108
+
109
+ begin
110
+ res = JSON.parse(response.body);
111
+ rescue JSON::ParserError => e
112
+ raise Appwrite::Exception.new(response.body, response.code, nil)
113
+ end
114
+
115
+ if(response.code.to_i >= 400)
116
+ raise Appwrite::Exception.new(res['message'], res['status'], res)
117
+ end
102
118
 
103
- return JSON.parse(response.body);
119
+ return res;
104
120
  end
105
121
 
106
122
  def encodeFormData(value, key=nil)
@@ -0,0 +1,14 @@
1
+ module Appwrite
2
+ class Exception < StandardError
3
+ @code = 0;
4
+ @response = nil;
5
+
6
+ def initialize(message, code, response)
7
+ super(message)
8
+ @code = code
9
+ @response = response
10
+ end
11
+ attr_reader :code
12
+ attr_reader :response
13
+ end
14
+ end
@@ -0,0 +1,295 @@
1
+ module Appwrite
2
+ class Account < Service
3
+
4
+ def get()
5
+ path = '/account'
6
+
7
+ params = {}
8
+
9
+ return @client.call('get', path, {
10
+ 'content-type' => 'application/json',
11
+ }, params);
12
+ end
13
+
14
+ def delete()
15
+ path = '/account'
16
+
17
+ params = {}
18
+
19
+ return @client.call('delete', path, {
20
+ 'content-type' => 'application/json',
21
+ }, params);
22
+ end
23
+
24
+ def update_email(email:, password:)
25
+ if email.nil?
26
+ raise Appwrite::Exception.new('Missing required parameter: "email"')
27
+ end
28
+
29
+ if password.nil?
30
+ raise Appwrite::Exception.new('Missing required parameter: "password"')
31
+ end
32
+
33
+ path = '/account/email'
34
+
35
+ params = {}
36
+
37
+ if !email.nil?
38
+ params[:email] = email
39
+ end
40
+
41
+ if !password.nil?
42
+ params[:password] = password
43
+ end
44
+
45
+ return @client.call('patch', path, {
46
+ 'content-type' => 'application/json',
47
+ }, params);
48
+ end
49
+
50
+ def get_logs()
51
+ path = '/account/logs'
52
+
53
+ params = {}
54
+
55
+ return @client.call('get', path, {
56
+ 'content-type' => 'application/json',
57
+ }, params);
58
+ end
59
+
60
+ def update_name(name:)
61
+ if name.nil?
62
+ raise Appwrite::Exception.new('Missing required parameter: "name"')
63
+ end
64
+
65
+ path = '/account/name'
66
+
67
+ params = {}
68
+
69
+ if !name.nil?
70
+ params[:name] = name
71
+ end
72
+
73
+ return @client.call('patch', path, {
74
+ 'content-type' => 'application/json',
75
+ }, params);
76
+ end
77
+
78
+ def update_password(password:, old_password: nil)
79
+ if password.nil?
80
+ raise Appwrite::Exception.new('Missing required parameter: "password"')
81
+ end
82
+
83
+ path = '/account/password'
84
+
85
+ params = {}
86
+
87
+ if !password.nil?
88
+ params[:password] = password
89
+ end
90
+
91
+ if !old_password.nil?
92
+ params[:oldPassword] = old_password
93
+ end
94
+
95
+ return @client.call('patch', path, {
96
+ 'content-type' => 'application/json',
97
+ }, params);
98
+ end
99
+
100
+ def get_prefs()
101
+ path = '/account/prefs'
102
+
103
+ params = {}
104
+
105
+ return @client.call('get', path, {
106
+ 'content-type' => 'application/json',
107
+ }, params);
108
+ end
109
+
110
+ def update_prefs(prefs:)
111
+ if prefs.nil?
112
+ raise Appwrite::Exception.new('Missing required parameter: "prefs"')
113
+ end
114
+
115
+ path = '/account/prefs'
116
+
117
+ params = {}
118
+
119
+ if !prefs.nil?
120
+ params[:prefs] = prefs
121
+ end
122
+
123
+ return @client.call('patch', path, {
124
+ 'content-type' => 'application/json',
125
+ }, params);
126
+ end
127
+
128
+ def create_recovery(email:, url:)
129
+ if email.nil?
130
+ raise Appwrite::Exception.new('Missing required parameter: "email"')
131
+ end
132
+
133
+ if url.nil?
134
+ raise Appwrite::Exception.new('Missing required parameter: "url"')
135
+ end
136
+
137
+ path = '/account/recovery'
138
+
139
+ params = {}
140
+
141
+ if !email.nil?
142
+ params[:email] = email
143
+ end
144
+
145
+ if !url.nil?
146
+ params[:url] = url
147
+ end
148
+
149
+ return @client.call('post', path, {
150
+ 'content-type' => 'application/json',
151
+ }, params);
152
+ end
153
+
154
+ def update_recovery(user_id:, secret:, password:, password_again:)
155
+ if user_id.nil?
156
+ raise Appwrite::Exception.new('Missing required parameter: "userId"')
157
+ end
158
+
159
+ if secret.nil?
160
+ raise Appwrite::Exception.new('Missing required parameter: "secret"')
161
+ end
162
+
163
+ if password.nil?
164
+ raise Appwrite::Exception.new('Missing required parameter: "password"')
165
+ end
166
+
167
+ if password_again.nil?
168
+ raise Appwrite::Exception.new('Missing required parameter: "passwordAgain"')
169
+ end
170
+
171
+ path = '/account/recovery'
172
+
173
+ params = {}
174
+
175
+ if !user_id.nil?
176
+ params[:userId] = user_id
177
+ end
178
+
179
+ if !secret.nil?
180
+ params[:secret] = secret
181
+ end
182
+
183
+ if !password.nil?
184
+ params[:password] = password
185
+ end
186
+
187
+ if !password_again.nil?
188
+ params[:passwordAgain] = password_again
189
+ end
190
+
191
+ return @client.call('put', path, {
192
+ 'content-type' => 'application/json',
193
+ }, params);
194
+ end
195
+
196
+ def get_sessions()
197
+ path = '/account/sessions'
198
+
199
+ params = {}
200
+
201
+ return @client.call('get', path, {
202
+ 'content-type' => 'application/json',
203
+ }, params);
204
+ end
205
+
206
+ def delete_sessions()
207
+ path = '/account/sessions'
208
+
209
+ params = {}
210
+
211
+ return @client.call('delete', path, {
212
+ 'content-type' => 'application/json',
213
+ }, params);
214
+ end
215
+
216
+ def get_session(session_id:)
217
+ if session_id.nil?
218
+ raise Appwrite::Exception.new('Missing required parameter: "sessionId"')
219
+ end
220
+
221
+ path = '/account/sessions/{sessionId}'
222
+ .gsub('{sessionId}', session_id)
223
+
224
+ params = {}
225
+
226
+ return @client.call('get', path, {
227
+ 'content-type' => 'application/json',
228
+ }, params);
229
+ end
230
+
231
+ def delete_session(session_id:)
232
+ if session_id.nil?
233
+ raise Appwrite::Exception.new('Missing required parameter: "sessionId"')
234
+ end
235
+
236
+ path = '/account/sessions/{sessionId}'
237
+ .gsub('{sessionId}', session_id)
238
+
239
+ params = {}
240
+
241
+ return @client.call('delete', path, {
242
+ 'content-type' => 'application/json',
243
+ }, params);
244
+ end
245
+
246
+ def create_verification(url:)
247
+ if url.nil?
248
+ raise Appwrite::Exception.new('Missing required parameter: "url"')
249
+ end
250
+
251
+ path = '/account/verification'
252
+
253
+ params = {}
254
+
255
+ if !url.nil?
256
+ params[:url] = url
257
+ end
258
+
259
+ return @client.call('post', path, {
260
+ 'content-type' => 'application/json',
261
+ }, params);
262
+ end
263
+
264
+ def update_verification(user_id:, secret:)
265
+ if user_id.nil?
266
+ raise Appwrite::Exception.new('Missing required parameter: "userId"')
267
+ end
268
+
269
+ if secret.nil?
270
+ raise Appwrite::Exception.new('Missing required parameter: "secret"')
271
+ end
272
+
273
+ path = '/account/verification'
274
+
275
+ params = {}
276
+
277
+ if !user_id.nil?
278
+ params[:userId] = user_id
279
+ end
280
+
281
+ if !secret.nil?
282
+ params[:secret] = secret
283
+ end
284
+
285
+ return @client.call('put', path, {
286
+ 'content-type' => 'application/json',
287
+ }, params);
288
+ end
289
+
290
+
291
+ protected
292
+
293
+ private
294
+ end
295
+ end