diff --git a/ruby/starter-template/.gitignore b/ruby/starter-template/.gitignore new file mode 100644 index 00000000..1a38dd68 --- /dev/null +++ b/ruby/starter-template/.gitignore @@ -0,0 +1,56 @@ +*.gem +*.rbc +/.config +/coverage/ +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +# Used by dotenv library to load environment variables. +# .env + +# Ignore Byebug command history file. +.byebug_history + +## Specific to RubyMotion: +.dat* +.repl_history +build/ +*.bridgesupport +build-iPhoneOS/ +build-iPhoneSimulator/ + +## Specific to RubyMotion (use of CocoaPods): +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# vendor/Pods/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +## Environment normalization: +/.bundle/ +/vendor/bundle +/lib/bundler/man/ + +# for a library or gem, you might want to ignore these files since the code is +# intended to run in multiaple environments; otherwise, check them in: +# Gemfile.lock +# .ruby-version +# .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc + +# Used by RuboCop. Remote config files pulled in from inherit_from directive. +# .rubocop-https?--* \ No newline at end of file diff --git a/ruby/starter-template/Gemfile b/ruby/starter-template/Gemfile new file mode 100644 index 00000000..a25455c8 --- /dev/null +++ b/ruby/starter-template/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gem 'appwrite' \ No newline at end of file diff --git a/ruby/starter-template/README.md b/ruby/starter-template/README.md new file mode 100644 index 00000000..45448454 --- /dev/null +++ b/ruby/starter-template/README.md @@ -0,0 +1,48 @@ +# ⚡ Ruby Starter Function + +A simple starter function. Edit `src/main.rb` to get started and create something awesome! 🚀 + +## 🧰 Usage + +### `GET` + +- Returns a "Hello, World!" message. + +**Response** + +Sample `200` Response: + +```text +Hello, World! 🌎 +``` + +### `POST`, `PUT`, `PATCH`, `DELETE` + +- Returns a "Learn More" JSON response. + +**Response** + +Sample `200` Response: + +```json +{ + "motto": "Build Fast. Scale Big. All in One Place.", + "learn": "https://appwrite.io/docs", + "connect": "https://appwrite.io/discord", + "getInspired": "https://builtwith.appwrite.io" +} +``` + +## ⚙️ Configuration + +| Setting | Value | +|-------------------|------------------| +| Runtime | Ruby (3.2) | +| Entrypoint | `src/main.rb` | +| Build Commands | `bundle install` | +| Permissions | `any` | +| Timeout (Seconds) | 15 | + +## 🔒 Environment Variables + +No environment variables required. diff --git a/ruby/starter-template/src/main.rb b/ruby/starter-template/src/main.rb new file mode 100644 index 00000000..0194e5d3 --- /dev/null +++ b/ruby/starter-template/src/main.rb @@ -0,0 +1,36 @@ +require "appwrite" + +# This is your Appwrite function +# It's executed each time we get a request +def main(context) + # Why not try the Appwrite SDK? + # + # client = Appwrite::Client.new + # client + # .set_endpoint('https://cloud.appwrite.io/v1') + # .set_project(req.variables['APPWRITE_PROJECT_ID']) + # .set_key(req.variables['APPWRITE_API_KEY']) + + # You can log messages to the console + context.log("Hello, Logs! 👋") + + # If something goes wrong, log an error + context.error("Hello, Errors! ⛔") + + # The `ctx.req` object contains the request data + if (context.req.method == "GET") + # Send a response with the res object helpers + # `ctx.res.send()` dispatches a string back to the client + return context.res.send("Hello, World! 🌎") + end + + # `ctx.res.json()` is a handy helper for sending JSON + return context.res.json( + { + "motto": "Build Fast. Scale Big. All in One Place.", + "learn": "https://appwrite.io/docs", + "connect": "https://appwrite.io/discord", + "getInspired": "https://builtwith.appwrite.io", + } + ) +end