-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
70 lines (61 loc) · 1.38 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright © 2017, ACM@UIUC
#
# This file is part of the Groot Project.
#
# The Groot Project is open source software, released under the University of
# Illinois/NCSA Open Source License. You should have received a copy of
# this license in a file with the distribution.
require 'sinatra'
require 'sinatra/reloader' if development?
require 'json'
set :port, 8008
set :bind, '0.0.0.0'
fake_token = 'this-is-a-fake-token'
fake_user = {
'first-name' => 'Fake',
'last-name' => 'User',
'name' => 'jsmith2',
'email' => 'jsmith2@illinois.edu'
}
post '/session' do
{
'token' => fake_token,
'user' => {
'link' => {
'href' => "#{request.base_url}/user?username=#{fake_user['name']}",
'rel' => 'self'
},
'name' => fake_user['name']
},
'link' => {
'href' => "#{request.base_url}/session/#{fake_token}",
'rel' => 'self'
}
}.to_json
end
delete '/session' do
{
'message' => 'OK'
}.to_json
end
get '/session/:token' do
halt 500, { 'error' => 'Invalid token provided' }.to_json unless params[:token] == fake_token
{
'token' => fake_token,
'user' => fake_user,
'link' => {
'href' => "#{request.base_url}/session/#{fake_token}",
'rel' => 'self'
}
}.to_json
end
post '/session/:token' do
{
'message' => 'OK'
}.to_json
end
delete '/session/:token' do
{
'message' => 'OK'
}.to_json
end