appwrite 1.0.8 → 2.0.2

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.
Files changed (98) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +16 -0
  3. data/CHANGELOG.md +1 -0
  4. data/Gemfile +1 -0
  5. data/LICENSE +1 -1
  6. data/README.md +10 -6
  7. data/appwrite.gemspec +3 -3
  8. data/docs/examples/avatars/get-browser.md +15 -0
  9. data/docs/examples/avatars/get-credit-card.md +15 -0
  10. data/docs/examples/avatars/get-favicon.md +15 -0
  11. data/docs/examples/avatars/get-flag.md +15 -0
  12. data/docs/examples/avatars/get-image.md +15 -0
  13. data/docs/examples/avatars/get-initials.md +15 -0
  14. data/docs/examples/avatars/get-q-r.md +15 -0
  15. data/docs/examples/database/create-collection.md +15 -0
  16. data/docs/examples/database/create-document.md +15 -0
  17. data/docs/examples/database/delete-collection.md +15 -0
  18. data/docs/examples/database/delete-document.md +15 -0
  19. data/docs/examples/database/get-collection.md +15 -0
  20. data/docs/examples/database/get-document.md +15 -0
  21. data/docs/examples/database/list-collections.md +15 -0
  22. data/docs/examples/database/list-documents.md +15 -0
  23. data/docs/examples/database/update-collection.md +15 -0
  24. data/docs/examples/database/update-document.md +15 -0
  25. data/docs/examples/functions/create-execution.md +15 -0
  26. data/docs/examples/functions/create-tag.md +15 -0
  27. data/docs/examples/functions/create.md +15 -0
  28. data/docs/examples/functions/delete-tag.md +15 -0
  29. data/docs/examples/functions/delete.md +15 -0
  30. data/docs/examples/functions/get-execution.md +15 -0
  31. data/docs/examples/functions/get-tag.md +15 -0
  32. data/docs/examples/functions/get.md +15 -0
  33. data/docs/examples/functions/list-executions.md +15 -0
  34. data/docs/examples/functions/list-tags.md +15 -0
  35. data/docs/examples/functions/list.md +15 -0
  36. data/docs/examples/functions/update-tag.md +15 -0
  37. data/docs/examples/functions/update.md +15 -0
  38. data/docs/examples/health/get-anti-virus.md +15 -0
  39. data/docs/examples/health/get-cache.md +15 -0
  40. data/docs/examples/health/get-d-b.md +15 -0
  41. data/docs/examples/health/get-queue-certificates.md +15 -0
  42. data/docs/examples/health/get-queue-functions.md +15 -0
  43. data/docs/examples/health/get-queue-logs.md +15 -0
  44. data/docs/examples/health/get-queue-tasks.md +15 -0
  45. data/docs/examples/health/get-queue-usage.md +15 -0
  46. data/docs/examples/health/get-queue-webhooks.md +15 -0
  47. data/docs/examples/health/get-storage-local.md +15 -0
  48. data/docs/examples/health/get-time.md +15 -0
  49. data/docs/examples/health/get.md +15 -0
  50. data/docs/examples/locale/get-continents.md +15 -0
  51. data/docs/examples/locale/get-countries-e-u.md +15 -0
  52. data/docs/examples/locale/get-countries-phones.md +15 -0
  53. data/docs/examples/locale/get-countries.md +15 -0
  54. data/docs/examples/locale/get-currencies.md +15 -0
  55. data/docs/examples/locale/get-languages.md +15 -0
  56. data/docs/examples/locale/get.md +15 -0
  57. data/docs/examples/storage/create-file.md +15 -0
  58. data/docs/examples/storage/delete-file.md +15 -0
  59. data/docs/examples/storage/get-file-download.md +15 -0
  60. data/docs/examples/storage/get-file-preview.md +15 -0
  61. data/docs/examples/storage/get-file-view.md +15 -0
  62. data/docs/examples/storage/get-file.md +15 -0
  63. data/docs/examples/storage/list-files.md +15 -0
  64. data/docs/examples/storage/update-file.md +15 -0
  65. data/docs/examples/teams/create-membership.md +15 -0
  66. data/docs/examples/teams/create.md +15 -0
  67. data/docs/examples/teams/delete-membership.md +15 -0
  68. data/docs/examples/teams/delete.md +15 -0
  69. data/docs/examples/teams/get-memberships.md +15 -0
  70. data/docs/examples/teams/get.md +15 -0
  71. data/docs/examples/teams/list.md +15 -0
  72. data/docs/examples/teams/update.md +15 -0
  73. data/docs/examples/users/create.md +15 -0
  74. data/docs/examples/users/delete-session.md +15 -0
  75. data/docs/examples/users/delete-sessions.md +15 -0
  76. data/docs/examples/users/delete-user.md +15 -0
  77. data/docs/examples/users/get-logs.md +15 -0
  78. data/docs/examples/users/get-prefs.md +15 -0
  79. data/docs/examples/users/get-sessions.md +15 -0
  80. data/docs/examples/users/get.md +15 -0
  81. data/docs/examples/users/list.md +15 -0
  82. data/docs/examples/users/update-prefs.md +15 -0
  83. data/docs/examples/users/update-status.md +15 -0
  84. data/lib/appwrite.rb +4 -3
  85. data/lib/appwrite/client.rb +46 -13
  86. data/lib/appwrite/file.rb +23 -0
  87. data/lib/appwrite/services/avatars.rb +17 -1
  88. data/lib/appwrite/services/database.rb +27 -29
  89. data/lib/appwrite/services/functions.rb +194 -0
  90. data/lib/appwrite/services/health.rb +141 -0
  91. data/lib/appwrite/services/locale.rb +12 -1
  92. data/lib/appwrite/services/storage.rb +9 -10
  93. data/lib/appwrite/services/teams.rb +21 -48
  94. data/lib/appwrite/services/users.rb +32 -20
  95. metadata +86 -11
  96. data/lib/appwrite/services/account.rb +0 -114
  97. data/lib/appwrite/services/auth.rb +0 -131
  98. data/lib/appwrite/services/projects.rb +0 -410
@@ -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_status(user_id: '[USER_ID]', status: '1');
14
+
15
+ puts response
data/lib/appwrite.rb CHANGED
@@ -1,14 +1,15 @@
1
1
  require 'net/http'
2
2
  require 'uri'
3
3
  require 'json'
4
+ require 'mime/types'
4
5
  require_relative 'appwrite/client'
5
6
  require_relative 'appwrite/service'
6
- require_relative 'appwrite/services/account'
7
- require_relative 'appwrite/services/auth'
7
+ require_relative 'appwrite/file'
8
8
  require_relative 'appwrite/services/avatars'
9
9
  require_relative 'appwrite/services/database'
10
+ require_relative 'appwrite/services/functions'
11
+ require_relative 'appwrite/services/health'
10
12
  require_relative 'appwrite/services/locale'
11
- require_relative 'appwrite/services/projects'
12
13
  require_relative 'appwrite/services/storage'
13
14
  require_relative 'appwrite/services/teams'
14
15
  require_relative 'appwrite/services/users'
@@ -20,7 +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:1.0.8'
23
+ 'x-sdk-version' => 'appwrite:ruby:2.0.0'
24
+
24
25
  }
25
26
  @endpoint = 'https://appwrite.io/v1';
26
27
  end
@@ -43,12 +44,6 @@ module Appwrite
43
44
  return self
44
45
  end
45
46
 
46
- def set_mode(value)
47
- add_header('x-appwrite-mode', value)
48
-
49
- return self
50
- end
51
-
52
47
  def set_endpoint(endpoint)
53
48
  @endpoint = endpoint
54
49
 
@@ -62,17 +57,30 @@ module Appwrite
62
57
  end
63
58
 
64
59
  def call(method, path = '', headers = {}, params = {})
65
- uri = URI.parse(@endpoint + path + ((method == METHOD_GET) ? '?' + encode(params) : ''))
60
+ uri = URI.parse(@endpoint + path + ((method == METHOD_GET && params.length) ? '?' + encode(params) : ''))
61
+ return fetch(method, uri, headers, params)
62
+ end
63
+
64
+ protected
65
+
66
+ private
67
+
68
+ def fetch(method, uri, headers, params, limit = 5)
69
+ raise ArgumentError, 'Too Many HTTP Redirects' if limit == 0
70
+
66
71
  http = Net::HTTP.new(uri.host, uri.port)
67
72
  http.use_ssl = (uri.scheme == 'https')
68
73
  payload = ''
69
74
 
70
75
  headers = @headers.merge(headers)
71
-
76
+ @BOUNDARY = "----A30#3ad1"
72
77
  if (method != METHOD_GET)
73
78
  case headers['content-type'][0, headers['content-type'].index(';') || headers['content-type'].length]
74
79
  when 'application/json'
75
80
  payload = params.to_json
81
+ when 'multipart/form-data'
82
+ payload = "--#{@BOUNDARY}\r\n" + encodeFormData(params)
83
+ headers['content-type'] = "multipart/form-data; boundary=#{@BOUNDARY}"
76
84
  else
77
85
  payload = encode(params)
78
86
  end
@@ -83,13 +91,38 @@ module Appwrite
83
91
  rescue => error
84
92
  raise 'Request Failed: ' + error.message
85
93
  end
94
+
95
+ # Handle Redirects
96
+ if (response.class == Net::HTTPRedirection || response.class == Net::HTTPMovedPermanently)
97
+ location = response['location']
98
+ uri = URI.parse(uri.scheme + "://" + uri.host + "" + location)
99
+
100
+ return fetch(method, uri, headers, {}, limit - 1)
101
+ end
86
102
 
87
103
  return JSON.parse(response.body);
88
104
  end
89
-
90
- protected
91
-
92
- private
105
+
106
+ def encodeFormData(value, key=nil)
107
+ case value
108
+ when Hash then value.map { |k,v| encodeFormData(v,k) }.join
109
+ when Array then value.map { |v| encodeFormData(v, "#{key}[]") }.join
110
+ when nil then ''
111
+ else
112
+ post_body = []
113
+ if(value.instance_of? File)
114
+ post_body << "Content-Disposition: form-data; name=\"#{key}\"; filename=\"#{value.name}\"\r\n"
115
+ post_body << "Content-Type: #{value.mimeType}\r\n\r\n"
116
+ post_body << value.content
117
+ post_body << "\r\n--#{@BOUNDARY}--\r\n"
118
+ else
119
+ post_body << "Content-Disposition: form-data; name=\"#{key}\"\r\n\r\n"
120
+ post_body << "#{value.to_s}"
121
+ post_body << "\r\n--#{@BOUNDARY}\r\n"
122
+ end
123
+ post_body.join
124
+ end
125
+ end
93
126
 
94
127
  def encode(value, key = nil)
95
128
  case value
@@ -0,0 +1,23 @@
1
+ require 'mime/types'
2
+
3
+ module Appwrite
4
+ class File
5
+ def initialize(path)
6
+ @name = ::File.basename(path)
7
+ @content = ::File.read(path)
8
+ @mimeType = MIME::Types.type_for(path)
9
+ end
10
+
11
+ def name
12
+ @name
13
+ end
14
+
15
+ def content
16
+ @content
17
+ end
18
+
19
+ def mimeType
20
+ @mimeType
21
+ end
22
+ end
23
+ end
@@ -72,7 +72,23 @@ module Appwrite
72
72
  }, params);
73
73
  end
74
74
 
75
- def get_q_r(text:, size: 400, margin: 1, download: 0)
75
+ def get_initials(name: '', width: 500, height: 500, color: '', background: '')
76
+ path = '/avatars/initials'
77
+
78
+ params = {
79
+ 'name': name,
80
+ 'width': width,
81
+ 'height': height,
82
+ 'color': color,
83
+ 'background': background
84
+ }
85
+
86
+ return @client.call('get', path, {
87
+ 'content-type' => 'application/json',
88
+ }, params);
89
+ end
90
+
91
+ def get_q_r(text:, size: 400, margin: 1, download: false)
76
92
  path = '/avatars/qr'
77
93
 
78
94
  params = {
@@ -2,7 +2,7 @@ module Appwrite
2
2
  class Database < Service
3
3
 
4
4
  def list_collections(search: '', limit: 25, offset: 0, order_type: 'ASC')
5
- path = '/database'
5
+ path = '/database/collections'
6
6
 
7
7
  params = {
8
8
  'search': search,
@@ -17,7 +17,7 @@ module Appwrite
17
17
  end
18
18
 
19
19
  def create_collection(name:, read:, write:, rules:)
20
- path = '/database'
20
+ path = '/database/collections'
21
21
 
22
22
  params = {
23
23
  'name': name,
@@ -32,8 +32,8 @@ module Appwrite
32
32
  end
33
33
 
34
34
  def get_collection(collection_id:)
35
- path = '/database/{collectionId}'
36
- .gsub('{collection_id}', collection_id)
35
+ path = '/database/collections/{collectionId}'
36
+ .gsub('{collectionId}', collection_id)
37
37
 
38
38
  params = {
39
39
  }
@@ -44,8 +44,8 @@ module Appwrite
44
44
  end
45
45
 
46
46
  def update_collection(collection_id:, name:, read:, write:, rules: [])
47
- path = '/database/{collectionId}'
48
- .gsub('{collection_id}', collection_id)
47
+ path = '/database/collections/{collectionId}'
48
+ .gsub('{collectionId}', collection_id)
49
49
 
50
50
  params = {
51
51
  'name': name,
@@ -60,8 +60,8 @@ module Appwrite
60
60
  end
61
61
 
62
62
  def delete_collection(collection_id:)
63
- path = '/database/{collectionId}'
64
- .gsub('{collection_id}', collection_id)
63
+ path = '/database/collections/{collectionId}'
64
+ .gsub('{collectionId}', collection_id)
65
65
 
66
66
  params = {
67
67
  }
@@ -71,20 +71,18 @@ module Appwrite
71
71
  }, params);
72
72
  end
73
73
 
74
- def list_documents(collection_id:, filters: [], offset: 0, limit: 50, order_field: '$uid', order_type: 'ASC', order_cast: 'string', search: '', first: 0, last: 0)
75
- path = '/database/{collectionId}/documents'
76
- .gsub('{collection_id}', collection_id)
74
+ def list_documents(collection_id:, filters: [], limit: 25, offset: 0, order_field: '', order_type: 'ASC', order_cast: 'string', search: '')
75
+ path = '/database/collections/{collectionId}/documents'
76
+ .gsub('{collectionId}', collection_id)
77
77
 
78
78
  params = {
79
79
  'filters': filters,
80
- 'offset': offset,
81
80
  'limit': limit,
82
- 'order-field': order_field,
83
- 'order-type': order_type,
84
- 'order-cast': order_cast,
85
- 'search': search,
86
- 'first': first,
87
- 'last': last
81
+ 'offset': offset,
82
+ 'orderField': order_field,
83
+ 'orderType': order_type,
84
+ 'orderCast': order_cast,
85
+ 'search': search
88
86
  }
89
87
 
90
88
  return @client.call('get', path, {
@@ -93,8 +91,8 @@ module Appwrite
93
91
  end
94
92
 
95
93
  def create_document(collection_id:, data:, read:, write:, parent_document: '', parent_property: '', parent_property_type: 'assign')
96
- path = '/database/{collectionId}/documents'
97
- .gsub('{collection_id}', collection_id)
94
+ path = '/database/collections/{collectionId}/documents'
95
+ .gsub('{collectionId}', collection_id)
98
96
 
99
97
  params = {
100
98
  'data': data,
@@ -111,9 +109,9 @@ module Appwrite
111
109
  end
112
110
 
113
111
  def get_document(collection_id:, document_id:)
114
- path = '/database/{collectionId}/documents/{documentId}'
115
- .gsub('{collection_id}', collection_id)
116
- .gsub('{document_id}', document_id)
112
+ path = '/database/collections/{collectionId}/documents/{documentId}'
113
+ .gsub('{collectionId}', collection_id)
114
+ .gsub('{documentId}', document_id)
117
115
 
118
116
  params = {
119
117
  }
@@ -124,9 +122,9 @@ module Appwrite
124
122
  end
125
123
 
126
124
  def update_document(collection_id:, document_id:, data:, read:, write:)
127
- path = '/database/{collectionId}/documents/{documentId}'
128
- .gsub('{collection_id}', collection_id)
129
- .gsub('{document_id}', document_id)
125
+ path = '/database/collections/{collectionId}/documents/{documentId}'
126
+ .gsub('{collectionId}', collection_id)
127
+ .gsub('{documentId}', document_id)
130
128
 
131
129
  params = {
132
130
  'data': data,
@@ -140,9 +138,9 @@ module Appwrite
140
138
  end
141
139
 
142
140
  def delete_document(collection_id:, document_id:)
143
- path = '/database/{collectionId}/documents/{documentId}'
144
- .gsub('{collection_id}', collection_id)
145
- .gsub('{document_id}', document_id)
141
+ path = '/database/collections/{collectionId}/documents/{documentId}'
142
+ .gsub('{collectionId}', collection_id)
143
+ .gsub('{documentId}', document_id)
146
144
 
147
145
  params = {
148
146
  }
@@ -0,0 +1,194 @@
1
+ module Appwrite
2
+ class Functions < Service
3
+
4
+ def list(search: '', limit: 25, offset: 0, order_type: 'ASC')
5
+ path = '/functions'
6
+
7
+ params = {
8
+ 'search': search,
9
+ 'limit': limit,
10
+ 'offset': offset,
11
+ 'orderType': order_type
12
+ }
13
+
14
+ return @client.call('get', path, {
15
+ 'content-type' => 'application/json',
16
+ }, params);
17
+ end
18
+
19
+ def create(name:, execute:, env:, vars: {}, events: [], schedule: '', timeout: 15)
20
+ path = '/functions'
21
+
22
+ params = {
23
+ 'name': name,
24
+ 'execute': execute,
25
+ 'env': env,
26
+ 'vars': vars,
27
+ 'events': events,
28
+ 'schedule': schedule,
29
+ 'timeout': timeout
30
+ }
31
+
32
+ return @client.call('post', path, {
33
+ 'content-type' => 'application/json',
34
+ }, params);
35
+ end
36
+
37
+ def get(function_id:)
38
+ path = '/functions/{functionId}'
39
+ .gsub('{functionId}', function_id)
40
+
41
+ params = {
42
+ }
43
+
44
+ return @client.call('get', path, {
45
+ 'content-type' => 'application/json',
46
+ }, params);
47
+ end
48
+
49
+ def update(function_id:, name:, execute:, vars: {}, events: [], schedule: '', timeout: 15)
50
+ path = '/functions/{functionId}'
51
+ .gsub('{functionId}', function_id)
52
+
53
+ params = {
54
+ 'name': name,
55
+ 'execute': execute,
56
+ 'vars': vars,
57
+ 'events': events,
58
+ 'schedule': schedule,
59
+ 'timeout': timeout
60
+ }
61
+
62
+ return @client.call('put', path, {
63
+ 'content-type' => 'application/json',
64
+ }, params);
65
+ end
66
+
67
+ def delete(function_id:)
68
+ path = '/functions/{functionId}'
69
+ .gsub('{functionId}', function_id)
70
+
71
+ params = {
72
+ }
73
+
74
+ return @client.call('delete', path, {
75
+ 'content-type' => 'application/json',
76
+ }, params);
77
+ end
78
+
79
+ def list_executions(function_id:, search: '', limit: 25, offset: 0, order_type: 'ASC')
80
+ path = '/functions/{functionId}/executions'
81
+ .gsub('{functionId}', function_id)
82
+
83
+ params = {
84
+ 'search': search,
85
+ 'limit': limit,
86
+ 'offset': offset,
87
+ 'orderType': order_type
88
+ }
89
+
90
+ return @client.call('get', path, {
91
+ 'content-type' => 'application/json',
92
+ }, params);
93
+ end
94
+
95
+ def create_execution(function_id:)
96
+ path = '/functions/{functionId}/executions'
97
+ .gsub('{functionId}', function_id)
98
+
99
+ params = {
100
+ }
101
+
102
+ return @client.call('post', path, {
103
+ 'content-type' => 'application/json',
104
+ }, params);
105
+ end
106
+
107
+ def get_execution(function_id:, execution_id:)
108
+ path = '/functions/{functionId}/executions/{executionId}'
109
+ .gsub('{functionId}', function_id)
110
+ .gsub('{executionId}', execution_id)
111
+
112
+ params = {
113
+ }
114
+
115
+ return @client.call('get', path, {
116
+ 'content-type' => 'application/json',
117
+ }, params);
118
+ end
119
+
120
+ def update_tag(function_id:, tag:)
121
+ path = '/functions/{functionId}/tag'
122
+ .gsub('{functionId}', function_id)
123
+
124
+ params = {
125
+ 'tag': tag
126
+ }
127
+
128
+ return @client.call('patch', path, {
129
+ 'content-type' => 'application/json',
130
+ }, params);
131
+ end
132
+
133
+ def list_tags(function_id:, search: '', limit: 25, offset: 0, order_type: 'ASC')
134
+ path = '/functions/{functionId}/tags'
135
+ .gsub('{functionId}', function_id)
136
+
137
+ params = {
138
+ 'search': search,
139
+ 'limit': limit,
140
+ 'offset': offset,
141
+ 'orderType': order_type
142
+ }
143
+
144
+ return @client.call('get', path, {
145
+ 'content-type' => 'application/json',
146
+ }, params);
147
+ end
148
+
149
+ def create_tag(function_id:, command:, code:)
150
+ path = '/functions/{functionId}/tags'
151
+ .gsub('{functionId}', function_id)
152
+
153
+ params = {
154
+ 'command': command,
155
+ 'code': code
156
+ }
157
+
158
+ return @client.call('post', path, {
159
+ 'content-type' => 'multipart/form-data',
160
+ }, params);
161
+ end
162
+
163
+ def get_tag(function_id:, tag_id:)
164
+ path = '/functions/{functionId}/tags/{tagId}'
165
+ .gsub('{functionId}', function_id)
166
+ .gsub('{tagId}', tag_id)
167
+
168
+ params = {
169
+ }
170
+
171
+ return @client.call('get', path, {
172
+ 'content-type' => 'application/json',
173
+ }, params);
174
+ end
175
+
176
+ def delete_tag(function_id:, tag_id:)
177
+ path = '/functions/{functionId}/tags/{tagId}'
178
+ .gsub('{functionId}', function_id)
179
+ .gsub('{tagId}', tag_id)
180
+
181
+ params = {
182
+ }
183
+
184
+ return @client.call('delete', path, {
185
+ 'content-type' => 'application/json',
186
+ }, params);
187
+ end
188
+
189
+
190
+ protected
191
+
192
+ private
193
+ end
194
+ end