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
|
# File 'app/controllers/marty/rpc_controller.rb', line 5
def evaluate
massaged_params = massage_params(params)
api_config = get_api_config(massaged_params) || {}
api = api_config[:api_class].try(:constantize) || Marty::Api::Base
api.respond_to(self) do
begin
next massaged_params if massaged_params.include?(:error)
api_params = api.process_params(massaged_params)
auth = api.is_authorized?(api_params)
next PERMISSION_DENIED_ERROR unless auth
next auth if auth.is_a?(Hash) && auth[:error]
start_time = Time.zone.now
api.before_evaluate(api_params)
result = api.evaluate(api_params, request, api_config)
api.after_evaluate(api_params, result)
if api_config[:logged]
log_params = api_params + { start_time: start_time, auth: auth }
api.log(result, log_params, request)
end
next result.except('backtrace', :backtrace) if result.is_a?(Hash)
result
rescue StandardError => e
Marty::Logger.log('rpc_controller', 'failure', e.message)
INTERNAL_SERVER_ERROR
end
end
end
|