-
Notifications
You must be signed in to change notification settings - Fork 0
/
shop.rb
71 lines (55 loc) · 989 Bytes
/
shop.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
# dev hint: shotgun login.rb
require 'rubygems'
require 'sinatra'
require 'rest-client'
require 'json'
require 'rack-flash'
class Shop < Sinatra::Base
use Rack::Flash
enable :sessions
configure do
set :public_folder, Proc.new { File.join(root, "static") }
enable :sessions
end
get '/' do
@title = 'shop'
@sidebar = 'side'
erb 'ciao'
end
## helpers
def self.put_or_post(*a, &b)
put *a, &b
post *a, &b
end
helpers do
def json_status(code, reason)
status code
{
:status => code,
:reason => reason
}.to_json
end
def accept_params(params, *fields)
h = { }
fields.each do |name|
h[name] = params[name] if params[name]
end
h
end
end
get "*" do
status 404
end
put_or_post "*" do
status 404
end
delete "*" do
status 404
end
not_found do
json_status 404, "Not found"
end
error do
json_status 500, env['sinatra.error'].message
end
end