Skip to content

Instantly share code, notes, and snippets.

@lambda2
Last active September 22, 2016 13:10
Show Gist options
  • Save lambda2/2061ee935c6170f9e748 to your computer and use it in GitHub Desktop.
Save lambda2/2061ee935c6170f9e748 to your computer and use it in GitHub Desktop.
Webservice example implementation

Webservice basic implementation

gem install sinatra
ruby server.rb
require 'sinatra'
require "base64"
require "json"
# The secret key associated with your campus endpoint
SECRET = "laclesecrete"
#
# ================ Closes ================
#
post '/users/:login/close' do
key = params.delete(:key)
if key == SECRET
# TODO: Close the user
status 201
"Creating close for user #{params[:login]}"
end
end
post '/users/:login/unclose' do
key = params.delete(:key)
if key == SECRET
# TODO: Delete the close
status 204
"Deleting close for user #{params[:login]}"
end
end
#
# ================ Users ================
#
post '/users/new' do
key = params.delete(:key)
if key == SECRET
new_user = params
# TODO: Create the user
status 201
"Creating user #{params[:login]}"
end
end
post '/users/:login/update' do
key = params.delete(:key)
if key == SECRET
new_user = params
# TODO: Mettre a jour le user
status 204
"Updating user #{params[:login]}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment