appwrite 2.0.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +16 -0
  3. data/README.md +72 -3
  4. data/appwrite.gemspec +1 -1
  5. data/docs/examples/account/create-recovery.md +15 -0
  6. data/docs/examples/account/create-verification.md +15 -0
  7. data/docs/examples/account/delete-session.md +15 -0
  8. data/docs/examples/account/delete-sessions.md +15 -0
  9. data/docs/examples/account/delete.md +15 -0
  10. data/docs/examples/account/get-logs.md +15 -0
  11. data/docs/examples/account/get-prefs.md +15 -0
  12. data/docs/examples/account/get-sessions.md +15 -0
  13. data/docs/examples/account/get.md +15 -0
  14. data/docs/examples/account/update-email.md +15 -0
  15. data/docs/examples/account/update-name.md +15 -0
  16. data/docs/examples/account/update-password.md +15 -0
  17. data/docs/examples/account/update-prefs.md +15 -0
  18. data/docs/examples/account/update-recovery.md +15 -0
  19. data/docs/examples/account/update-verification.md +15 -0
  20. data/docs/examples/avatars/get-q-r.md +1 -1
  21. data/docs/examples/database/create-document.md +1 -1
  22. data/docs/examples/database/update-collection.md +1 -1
  23. data/docs/examples/database/update-document.md +1 -1
  24. data/docs/examples/functions/create.md +1 -1
  25. data/docs/examples/health/get-d-b.md +1 -1
  26. data/docs/examples/locale/get-countries-e-u.md +1 -1
  27. data/docs/examples/storage/create-file.md +1 -1
  28. data/docs/examples/teams/delete-membership.md +1 -1
  29. data/docs/examples/teams/update-membership-roles.md +15 -0
  30. data/docs/examples/teams/update-membership-status.md +15 -0
  31. data/docs/examples/users/{delete-user.md → delete.md} +1 -1
  32. data/docs/examples/users/update-status.md +1 -1
  33. data/lib/appwrite.rb +2 -0
  34. data/lib/appwrite/client.rb +21 -5
  35. data/lib/appwrite/exception.rb +14 -0
  36. data/lib/appwrite/services/account.rb +280 -0
  37. data/lib/appwrite/services/avatars.rb +125 -42
  38. data/lib/appwrite/services/database.rb +199 -53
  39. data/lib/appwrite/services/functions.rb +223 -60
  40. data/lib/appwrite/services/health.rb +13 -25
  41. data/lib/appwrite/services/locale.rb +8 -15
  42. data/lib/appwrite/services/storage.rb +123 -33
  43. data/lib/appwrite/services/teams.rb +187 -38
  44. data/lib/appwrite/services/users.rb +106 -34
  45. metadata +24 -4
@@ -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
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.2.0',
24
+ 'X-Appwrite-Response-Format' => '0.8.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,280 @@
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 delete_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('delete', path, {
227
+ 'content-type' => 'application/json',
228
+ }, params);
229
+ end
230
+
231
+ def create_verification(url:)
232
+ if url.nil?
233
+ raise Appwrite::Exception.new('Missing required parameter: "url"')
234
+ end
235
+
236
+ path = '/account/verification'
237
+
238
+ params = {}
239
+
240
+ if !url.nil?
241
+ params[:url] = url
242
+ end
243
+
244
+ return @client.call('post', path, {
245
+ 'content-type' => 'application/json',
246
+ }, params);
247
+ end
248
+
249
+ def update_verification(user_id:, secret:)
250
+ if user_id.nil?
251
+ raise Appwrite::Exception.new('Missing required parameter: "userId"')
252
+ end
253
+
254
+ if secret.nil?
255
+ raise Appwrite::Exception.new('Missing required parameter: "secret"')
256
+ end
257
+
258
+ path = '/account/verification'
259
+
260
+ params = {}
261
+
262
+ if !user_id.nil?
263
+ params[:userId] = user_id
264
+ end
265
+
266
+ if !secret.nil?
267
+ params[:secret] = secret
268
+ end
269
+
270
+ return @client.call('put', path, {
271
+ 'content-type' => 'application/json',
272
+ }, params);
273
+ end
274
+
275
+
276
+ protected
277
+
278
+ private
279
+ end
280
+ end
@@ -1,30 +1,54 @@
1
1
  module Appwrite
2
2
  class Avatars < Service
3
3
 
4
- def get_browser(code:, width: 100, height: 100, quality: 100)
4
+ def get_browser(code:, width: nil, height: nil, quality: nil)
5
+ if code.nil?
6
+ raise Appwrite::Exception.new('Missing required parameter: "code"')
7
+ end
8
+
5
9
  path = '/avatars/browsers/{code}'
6
10
  .gsub('{code}', code)
7
11
 
8
- params = {
9
- 'width': width,
10
- 'height': height,
11
- 'quality': quality
12
- }
12
+ params = {}
13
+
14
+ if !width.nil?
15
+ params[:width] = width
16
+ end
17
+
18
+ if !height.nil?
19
+ params[:height] = height
20
+ end
21
+
22
+ if !quality.nil?
23
+ params[:quality] = quality
24
+ end
13
25
 
14
26
  return @client.call('get', path, {
15
27
  'content-type' => 'application/json',
16
28
  }, params);
17
29
  end
18
30
 
19
- def get_credit_card(code:, width: 100, height: 100, quality: 100)
31
+ def get_credit_card(code:, width: nil, height: nil, quality: nil)
32
+ if code.nil?
33
+ raise Appwrite::Exception.new('Missing required parameter: "code"')
34
+ end
35
+
20
36
  path = '/avatars/credit-cards/{code}'
21
37
  .gsub('{code}', code)
22
38
 
23
- params = {
24
- 'width': width,
25
- 'height': height,
26
- 'quality': quality
27
- }
39
+ params = {}
40
+
41
+ if !width.nil?
42
+ params[:width] = width
43
+ end
44
+
45
+ if !height.nil?
46
+ params[:height] = height
47
+ end
48
+
49
+ if !quality.nil?
50
+ params[:quality] = quality
51
+ end
28
52
 
29
53
  return @client.call('get', path, {
30
54
  'content-type' => 'application/json',
@@ -32,71 +56,130 @@ module Appwrite
32
56
  end
33
57
 
34
58
  def get_favicon(url:)
59
+ if url.nil?
60
+ raise Appwrite::Exception.new('Missing required parameter: "url"')
61
+ end
62
+
35
63
  path = '/avatars/favicon'
36
64
 
37
- params = {
38
- 'url': url
39
- }
65
+ params = {}
66
+
67
+ if !url.nil?
68
+ params[:url] = url
69
+ end
40
70
 
41
71
  return @client.call('get', path, {
42
72
  'content-type' => 'application/json',
43
73
  }, params);
44
74
  end
45
75
 
46
- def get_flag(code:, width: 100, height: 100, quality: 100)
76
+ def get_flag(code:, width: nil, height: nil, quality: nil)
77
+ if code.nil?
78
+ raise Appwrite::Exception.new('Missing required parameter: "code"')
79
+ end
80
+
47
81
  path = '/avatars/flags/{code}'
48
82
  .gsub('{code}', code)
49
83
 
50
- params = {
51
- 'width': width,
52
- 'height': height,
53
- 'quality': quality
54
- }
84
+ params = {}
85
+
86
+ if !width.nil?
87
+ params[:width] = width
88
+ end
89
+
90
+ if !height.nil?
91
+ params[:height] = height
92
+ end
93
+
94
+ if !quality.nil?
95
+ params[:quality] = quality
96
+ end
55
97
 
56
98
  return @client.call('get', path, {
57
99
  'content-type' => 'application/json',
58
100
  }, params);
59
101
  end
60
102
 
61
- def get_image(url:, width: 400, height: 400)
103
+ def get_image(url:, width: nil, height: nil)
104
+ if url.nil?
105
+ raise Appwrite::Exception.new('Missing required parameter: "url"')
106
+ end
107
+
62
108
  path = '/avatars/image'
63
109
 
64
- params = {
65
- 'url': url,
66
- 'width': width,
67
- 'height': height
68
- }
110
+ params = {}
111
+
112
+ if !url.nil?
113
+ params[:url] = url
114
+ end
115
+
116
+ if !width.nil?
117
+ params[:width] = width
118
+ end
119
+
120
+ if !height.nil?
121
+ params[:height] = height
122
+ end
69
123
 
70
124
  return @client.call('get', path, {
71
125
  'content-type' => 'application/json',
72
126
  }, params);
73
127
  end
74
128
 
75
- def get_initials(name: '', width: 500, height: 500, color: '', background: '')
129
+ def get_initials(name: nil, width: nil, height: nil, color: nil, background: nil)
76
130
  path = '/avatars/initials'
77
131
 
78
- params = {
79
- 'name': name,
80
- 'width': width,
81
- 'height': height,
82
- 'color': color,
83
- 'background': background
84
- }
132
+ params = {}
133
+
134
+ if !name.nil?
135
+ params[:name] = name
136
+ end
137
+
138
+ if !width.nil?
139
+ params[:width] = width
140
+ end
141
+
142
+ if !height.nil?
143
+ params[:height] = height
144
+ end
145
+
146
+ if !color.nil?
147
+ params[:color] = color
148
+ end
149
+
150
+ if !background.nil?
151
+ params[:background] = background
152
+ end
85
153
 
86
154
  return @client.call('get', path, {
87
155
  'content-type' => 'application/json',
88
156
  }, params);
89
157
  end
90
158
 
91
- def get_q_r(text:, size: 400, margin: 1, download: false)
159
+ def get_qr(text:, size: nil, margin: nil, download: nil)
160
+ if text.nil?
161
+ raise Appwrite::Exception.new('Missing required parameter: "text"')
162
+ end
163
+
92
164
  path = '/avatars/qr'
93
165
 
94
- params = {
95
- 'text': text,
96
- 'size': size,
97
- 'margin': margin,
98
- 'download': download
99
- }
166
+ params = {}
167
+
168
+ if !text.nil?
169
+ params[:text] = text
170
+ end
171
+
172
+ if !size.nil?
173
+ params[:size] = size
174
+ end
175
+
176
+ if !margin.nil?
177
+ params[:margin] = margin
178
+ end
179
+
180
+ if !download.nil?
181
+ params[:download] = download
182
+ end
100
183
 
101
184
  return @client.call('get', path, {
102
185
  'content-type' => 'application/json',