Skip to content

Commit 9384369

Browse files
committed
Add functions examples
1 parent b71512e commit 9384369

File tree

5 files changed

+62
-11
lines changed

5 files changed

+62
-11
lines changed

.rubocop.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AllCops:
2-
TargetRubyVersion: 2.4
2+
TargetRubyVersion: 2.7
33
Style/StringLiterals:
44
Enabled: true
55
EnforcedStyle: double_quotes
@@ -15,3 +15,7 @@ GlobalVars:
1515
AllowedVariables:
1616
- $client
1717
- $collection_id
18+
- $document_id
19+
- $user_id
20+
- $function_id
21+
- $file_id

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM ruby:3.1-alpine
2-
COPY "Gemfile" "Gemfile"
2+
COPY Gemfile Gemfile
33
RUN bundle install
44
COPY . .
55
CMD bundle exec ruby lib/playground.rb

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This playground does not adhere to Ruby best practices but rather is intended to
2828
- Execute the command `docker compose up`
2929
6. You will see the JSON response in the console.
3030

31-
### APIs Covered in Playground:
31+
### API's Covered:
3232

3333
- Databse
3434
* [Create Collection](./lib/playground.rb#L53)
@@ -49,6 +49,11 @@ This playground does not adhere to Ruby best practices but rather is intended to
4949
* [List User](./lib/playground.rb#L29)
5050
* [Delete User](./lib/playground.rb#L38)
5151

52+
- Functions
53+
* [Create Function](./lib/playground.rb#L229)
54+
* [List Functions](./lib/playground.rb#L244)
55+
* [Delete Function](./lib/playground.rb#L253)
56+
5257
## Contributing
5358

5459
All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.9'
22

33
services:
4-
playground:
4+
playground-for-ruby:
55
build: .
66
volumes:
77
- "./:/app"

lib/playground.rb

+49-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def create_user
2929

3030
$user_id = response.id
3131

32-
puts JSON.pretty_generate(response.to_map)
32+
puts JSON.pretty_generate(response)
3333
end
3434

3535
def list_users
@@ -38,7 +38,7 @@ def list_users
3838

3939
response = users.list
4040

41-
puts JSON.pretty_generate(response.to_map)
41+
puts JSON.pretty_generate(response)
4242
end
4343

4444
def delete_user
@@ -110,7 +110,7 @@ def create_collection
110110
attributes: ["name", "email"]
111111
)
112112
responses.each do |response|
113-
puts JSON.pretty_generate(response.to_map)
113+
puts JSON.pretty_generate(response)
114114
end
115115
end
116116

@@ -120,7 +120,7 @@ def list_collections
120120

121121
response = database.list_collections
122122

123-
puts JSON.pretty_generate(response.to_map)
123+
puts JSON.pretty_generate(response)
124124
end
125125

126126
def delete_collection
@@ -183,7 +183,7 @@ def create_bucket
183183
)
184184

185185
$bucket_id = response.id
186-
puts JSON.pretty_generate(response.to_map)
186+
puts JSON.pretty_generate(response)
187187
end
188188

189189
def upload_file
@@ -198,7 +198,7 @@ def upload_file
198198

199199
$file_id = response.id
200200

201-
puts JSON.pretty_generate(response.to_map)
201+
puts JSON.pretty_generate(response)
202202
end
203203

204204
def list_files
@@ -207,7 +207,7 @@ def list_files
207207

208208
response = storage.list_files(bucket_id: $bucket_id)
209209

210-
puts JSON.pretty_generate(response.to_map)
210+
puts JSON.pretty_generate(response)
211211
end
212212

213213
def delete_file
@@ -231,21 +231,63 @@ def delete_bucket
231231
puts JSON.pretty_generate(response)
232232
end
233233

234+
def create_function
235+
functions = Appwrite::Functions.new($client)
236+
puts "Running Create Function API".green
237+
238+
response = functions.create(
239+
function_id: "unique()",
240+
name: "Test Function",
241+
runtime: "python-3.9",
242+
execute: ["role:all"]
243+
)
244+
245+
$function_id = response.id
246+
247+
puts JSON.pretty_generate(response)
248+
end
249+
250+
def list_functions
251+
functions = Appwrite::Functions.new($client)
252+
puts "Running List Functions API".green
253+
254+
response = functions.list
255+
256+
puts JSON.pretty_generate(response)
257+
end
258+
259+
def delete_function
260+
functions = Appwrite::Functions.new($client)
261+
puts "Running Delete Function API".green
262+
263+
response = functions.delete(function_id: $function_id)
264+
265+
puts JSON.pretty_generate(response)
266+
end
267+
268+
# Users
234269
create_user
235270
list_users
236271
delete_user
237272

273+
# Database
238274
create_collection
239275
list_collections
240276
create_document
241277
list_documents
242278
delete_document
243279
delete_collection
244280

281+
# Storage
245282
create_bucket
246283
upload_file
247284
list_files
248285
delete_file
249286
delete_bucket
250287

288+
# Functions
289+
create_function
290+
list_functions
291+
delete_function
292+
251293
puts "Successfully Ran playground!".bold.green

0 commit comments

Comments
 (0)