-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
⚡ Write a generateShortUrl() Function using Ruby #39
Conversation
@tessamero Any news about this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is beautiful code! 🤯 Just a few requests!
Thank you so much for the PR 🤩. We're adding the |
@stnguyen90 Sorry about the delay! Please check now if everything is okay! |
3. Start the Open Runtime: | ||
|
||
``` | ||
docker run -p 3000:3000 -e INTERNAL_RUNTIME_KEY=secret-key -e INTERNAL_RUNTIME_ENTRYPOINT=index.rb --rm --interactive --tty --volume $PWD/code.tar.gz:/tmp/code.tar.gz:ro openruntimes/ruby:3.1 sh /usr/local/src/start.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This image still looks outdated.
is_invalid_provider = payload['provider'].nil? || payload['provider'].empty? | ||
provider_not_supported = !VALID_PROVIDERS.include?(payload['provider']) | ||
|
||
raise error_message if is_invalid_url || is_invalid_provider || provider_not_supported |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make sure to catch all exceptions and return a proper response message. For example, this isn't helpful:
$ curl -H "X-Internal-Challenge: secret-key" \
> -H "Content-Type: application/json" \
> -X POST http:https://localhost:3000/ \
> -d '{"payload": {}}'
{"stdout":"","stderr":"\n/usr/code-start/index.rb:48:in `validate_params'\n/usr/code-start/index.rb:15:in `main'\n/usr/local/src/server.rb:93:in `block in <top (required)>'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1684:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1684:in `block in compile!'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1002:in `block (3 levels) in route!'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1020:in `route_eval'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1002:in `block (2 levels) in route!'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1051:in `block in process_route'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1049:in `catch'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1049:in `process_route'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1000:in `block in route!'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:997:in `each'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:997:in `route!'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1121:in `block in dispatch!'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1092:in `catch'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1092:in `invoke'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1116:in `dispatch!'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:932:in `block in call!'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1092:in `catch'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1092:in `invoke'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:932:in `call!'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:921:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.3/lib/rack/protection/xss_header.rb:20:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.3/lib/rack/protection/path_traversal.rb:18:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.3/lib/rack/protection/json_csrf.rb:28:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.3/lib/rack/protection/base.rb:53:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.3/lib/rack/protection/base.rb:53:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.3/lib/rack/protection/frame_options.rb:33:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/logger.rb:17:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/common_logger.rb:38:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:261:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:254:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/head.rb:12:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/method_override.rb:24:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:219:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1995:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1554:in `block in call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1770:in `synchronize'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.3/lib/sinatra/base.rb:1554:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/puma-6.0.0/lib/puma/configuration.rb:268:in `call'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/puma-6.0.0/lib/puma/request.rb:89:in `block in handle_request'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/puma-6.0.0/lib/puma/thread_pool.rb:343:in `with_force_shutdown'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/puma-6.0.0/lib/puma/request.rb:88:in `handle_request'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/puma-6.0.0/lib/puma/server.rb:430:in `process_client'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/puma-6.0.0/lib/puma/server.rb:233:in `block in run'\n/usr/local/src/vendor/bundle/ruby/3.1.0/gems/puma-6.0.0/lib/puma/thread_pool.rb:150:in `block in spawn_thread'"}
}.freeze | ||
|
||
def main(req, res) | ||
payload = req.payload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this compatible with Appwrite functions, would you please test this with payload as a JSON string and parse it here. For example:
curl -H "X-Internal-Challenge: secret-key" \
-H "Content-Type: application/json" \
-X POST http:https://localhost:3000/ \
-d '{"payload": "{\"url\": \"https://google.com\"}"}'
Hey there 👋 |
Github Ticket
Closes APPWRITE-4189
Description
This PR adds an example function for generating a short URL using different providers.
The currently supported providers are:
Screenshots
Success Bitly
Success TinyURL
Error Bitly
Error TinyURL