-
Notifications
You must be signed in to change notification settings - Fork 3
/
roda-app.rb
89 lines (77 loc) · 2.28 KB
/
roda-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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'roda'
require 'byebug'
require 'slackbotsy'
require 'open-uri'
require 'set'
require 'rack/csrf'
Dir['./helpers/*.rb'].each { |file| require file }
require_relative 'models'
Dir[File.join('./services', '**/*.rb')].each do |f|
require f
end
Dir['./configurations/*.rb'].each { |file| require file }
class RodaApp < Roda
# bots init
opts[:reservation_bot] = Slackbotsy::Bot.new(ReservationSlackConfig::CONFIG)
plugin :assets, css: ['signin.css', 'reservations.css'],
js: ['reservations.js']
opts[:pull_request_bot] = Slackbotsy::Bot.new(PullRequestSlackConfig::CONFIG)
opts[:food_bot] = Slackbotsy::Bot.new(FoodSlackConfig::CONFIG)
plugin :render, engine: 'haml'
plugin :json, :classes=>[Sequel::Model, Array, Hash]
plugin :default_headers, 'Content-Type'=>'application/json'
plugin :multi_route
plugin :shared_vars
plugin :sinatra_helpers
plugin :partials
plugin :flash
use Rack::Session::Cookie, secret: ENV.fetch('SECRET_TOKEN')
use Rack::Csrf, :raise => true, :skip_if => api_request?
use Warden::Manager do |manager|
manager.scope_defaults :default,
strategies: [:password],
action: 'user_sessions/unauthenticated'
manager.failure_app = self
end
route do |r|
require_relative 'apps/user_sessions'
require_relative 'apps/user_registrations'
require_relative 'apps/reservation'
require_relative 'apps/pull_request'
require_relative 'apps/order'
r.assets
# /
r.root do
env['warden'].authenticate!
response['Content-Type'] = 'text/html'
r.params['day'] ? @day = ( Date.parse r.params['day'] ) : @day = Date.today
@reservations = Reservation.by_day(@day)
view('reservations/index')
end
# /user_sessions
r.on 'user_sessions' do
response['Content-Type'] = 'text/html'
r.route 'user_sessions'
end
# /user_registrations
r.on 'user_registrations' do
response['Content-Type'] = 'text/html'
r.route 'user_registrations'
end
# /api
r.on 'api' do
# /api/reservations
r.on 'reservations' do
r.route 'reservation'
end
# /api/pull_requests
r.on 'pull_requests' do
r.route 'pull_request'
end
# /api/orders
r.on 'orders' do
r.route 'order'
end
end
end
end