arkaan 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/arkaan/utils/controller.rb +22 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a31199bbce66658b871208d0b4225f242842912
|
4
|
+
data.tar.gz: b1c6d940b08a683cfeffd51858bf9177ae9cd3a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2769ae73df7c8280fd6f32e0f23f4b9b5d7a365dbad5c23f9e5df4cb751726145ab065e44074c4e7b498cd9833ef8388143a14ea11ed1838084bb6b5fd75df9
|
7
|
+
data.tar.gz: 008b88cd408d6cb199cf8dc005f8d7113bc9d5ee6de9e294b79896f8636562641df8cb27d8460ea69de507a0788dc8e52435ef23b551278bed0287bcea7393b1
|
@@ -3,13 +3,14 @@ module Arkaan
|
|
3
3
|
# Base controller to handle the standard error when accessing the API.
|
4
4
|
# @author Vincent Courtois <courtois.vincenet@outlook.com>
|
5
5
|
class Controller < Sinatra::Base
|
6
|
+
|
6
7
|
before do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
add_body_to_params
|
9
|
+
check_presence('token', 'app_key')
|
10
|
+
|
11
|
+
gateway = Arkaan::Monitoring::Gateway.where(token: params['token']).first
|
12
|
+
application = Arkaan::OAuth::Application.where(key: params['app_key']).first
|
13
|
+
|
13
14
|
if gateway.nil?
|
14
15
|
halt 404, {message: 'gateway_not_found'}.to_json
|
15
16
|
elsif application.nil?
|
@@ -19,11 +20,21 @@ module Arkaan
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
#
|
23
|
-
# @param [String]
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
# Checks the presence of several fields given as parameters and halts the execution if it's not present.
|
24
|
+
# @param fields [Array<String>] an array of fields names to search in the parameters
|
25
|
+
def check_presence(*fields)
|
26
|
+
fields.each do |field|
|
27
|
+
halt 400, {message: 'bad_request'}.to_json if params[field].nil?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Adds the parsed body to the parameters, overwriting the parameters of the querystring with the values
|
32
|
+
# of the SON body if they have similar keys.
|
33
|
+
def add_body_to_params
|
34
|
+
parsed_body = JSON.parse(request.body.read.to_s) rescue {}
|
35
|
+
parsed_body.keys.each do |key|
|
36
|
+
params[key] = parsed_body[key]
|
37
|
+
end
|
27
38
|
end
|
28
39
|
end
|
29
40
|
end
|