-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.rb
executable file
·99 lines (82 loc) · 1.93 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require 'sinatra'
require 'haml'
require 'v8'
require 'json'
require 'coffee-script'
require 'carQuote'
require 'lifeQuote'
require 'carPremiumCalculator'
require 'lifePremiumCalculator'
require 'emailValidator'
require 'logger'
class App < Sinatra::Base
$logger = Logger.new(STDERR)
emailValidator = EmailValidator.new()
use Rack::Session::Cookie, :key => 'rack.session',
:path => '/',
:secret => 'secret_stuff'
get '/' do
session["quote"] ||= nil
haml :index
end
get "/bad" do
content_type :json
{ :login_successful => "false" }.to_json
end
get "/good" do
content_type :json
{ :login_successful => "true", :name => "Hans"}.to_json
end
get '/life' do
haml :life
end
get '/car' do
haml :car
end
get '/payment' do
@quote = session["quote"]
haml :payment
end
post '/pay' do
@quote = session["quote"]
haml :done
end
post '/quote' do
type = params["typeOfInsurance"]
if type == "life"
@quote = getLifeQuote(params)
else
@quote = getCarQuote(params)
end
session["quote"] = @quote
haml :quote
end
post '/checkemail' do
email = params["email"]
content_type :json
{:valid => emailValidator.isEmailValid?(email)}.to_json
end
get '/javascripts/application.js' do
coffee :application
end
not_found do
haml :not_found
end
def getLifeQuote(params)
age = params["age"]
email = params["email"]
occupationCategory = params["occupation"]
gender = params["gender"]
state = params["state"]
LifeQuote.new(age, email, state, occupationCategory, gender)
end
def getCarQuote(params)
age = params["age"]
email = params["email"]
make = params["make"]
year = params["year"]
gender = params["gender"]
state = params["state"]
CarQuote.new(age, email, state, make, gender, year)
end
end