forked from postrank-labs/goliath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalid.rb
More file actions
executable file
·42 lines (31 loc) · 912 Bytes
/
Copy pathvalid.rb
File metadata and controls
executable file
·42 lines (31 loc) · 912 Bytes
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
#!/usr/bin/env ruby
$:<< '../lib' << 'lib'
require 'goliath'
class ValidSingleParam < Goliath::API
use Goliath::Rack::Params
use Goliath::Rack::Validation::RequiredParam, {:key => 'test'}
# If you are using Golaith version <=0.9.1 you need to use Goliath::Rack::ValidationError
# to prevent the request from remaining open after an error occurs
#use Goliath::Rack::ValidationError
def response(env)
[200, {}, 'OK']
end
end
class ValidNestedParams < Goliath::API
use Goliath::Rack::Params
# For this validation to pass you need to have this as parameter (json body here)
# {
# 'data' : {
# 'login' : 'my_login'
# }
# }
#
use Goliath::Rack::Validation::RequiredParam, :key => %w(data login)
def response(env)
[200, {}, 'OK']
end
end
class Router < Goliath::API
map '/valid_param1', ValidSingleParam
map '/valid_param2', ValidNestedParams
end