ehsso 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/person.rb +39 -27
- data/lib/ehsso/engine.rb +1 -0
- data/lib/ehsso/version.rb +1 -1
- 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: 94ce6d4c26a580c10a20be66259e463b255b4834
|
4
|
+
data.tar.gz: ca2ea9d050f1b554e0e13d371170e369ee6d55c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 827835b7f4f13457d884127e38287123c13ecd693ca41d415b3e75ff9f780267d3fb65678de3ee63958639239855d0358bf2ec18d4928839bf70128c6ece3eea
|
7
|
+
data.tar.gz: 21cb75eaa573958b8236692211e7eef907ff27e930d994172a4e0e654de6f2fa431c0126837c82bb13869f780d410aaa0c034d92f21d3835a17cd89b36b394c1
|
data/app/models/person.rb
CHANGED
@@ -7,6 +7,9 @@ module Ehsso
|
|
7
7
|
attr_accessor :first_name
|
8
8
|
attr_accessor :last_name
|
9
9
|
attr_accessor :email
|
10
|
+
attr_accessor :module_key
|
11
|
+
attr_accessor :module_name
|
12
|
+
attr_accessor :roles
|
10
13
|
|
11
14
|
attr_reader :last_error_message
|
12
15
|
|
@@ -18,14 +21,20 @@ module Ehsso
|
|
18
21
|
@email = args[:email]
|
19
22
|
|
20
23
|
# for this purpose we deal with only one module
|
21
|
-
@module_key =
|
22
|
-
@module_name =
|
23
|
-
@roles = []
|
24
|
+
@module_key = args[:module_key]
|
25
|
+
@module_name = args[:module_name]
|
26
|
+
@roles = args[:roles].is_a?(Array) ? args[:roles] : []
|
24
27
|
end
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
def valid?
|
30
|
+
@last_error_message.nil?
|
31
|
+
end
|
32
|
+
|
33
|
+
# you can use methods like guest?, user?, operator?, administrator? etc.
|
34
|
+
def method_missing(method)
|
35
|
+
raise "Method [#{method}] not defined or allowed" unless method[-1] == '?'
|
36
|
+
@roles.include?(method[0..-2].upcase)
|
37
|
+
end
|
29
38
|
|
30
39
|
def full_name
|
31
40
|
return nil if self.last_name.nil? && self.first_name.nil?
|
@@ -41,14 +50,13 @@ module Ehsso
|
|
41
50
|
return nil if header['HTTP_NIBR521'].nil? || header['HTTP_NIBR521'].size == 0
|
42
51
|
person.reference = header['HTTP_NIBR521'].downcase
|
43
52
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
person.email = header['HTTP_NIBREMAIL'].downcase if header['HTTP_NIBREMAIL'] && header['HTTP_NIBREMAIL'].strip.size > 0
|
53
|
+
[
|
54
|
+
[:first_name=, 'HTTP_NIBRFIRST'],
|
55
|
+
[:last_name=, 'HTTP_NIBRLAST'],
|
56
|
+
[:email=, 'HTTP_NIBREMAIL']
|
57
|
+
].each do |method, key|
|
58
|
+
person.send(method, header[key]) if header[key] && header[key].strip.size > 0
|
59
|
+
end
|
52
60
|
|
53
61
|
return person
|
54
62
|
end
|
@@ -86,7 +94,11 @@ module Ehsso
|
|
86
94
|
def handle_service_call(args={})
|
87
95
|
url = [Ehsso.configuration.base_url, 'people'].join('/')
|
88
96
|
userpwd = Ehsso.configuration.username_and_password
|
89
|
-
|
97
|
+
|
98
|
+
# allows to mock class for rspec
|
99
|
+
service_class = args[:service_class] || Typhoeus
|
100
|
+
|
101
|
+
response = service_class.post(url, body: payload(action: args[:action]), userpwd: userpwd)
|
90
102
|
handle_response(response)
|
91
103
|
end
|
92
104
|
|
@@ -96,28 +108,28 @@ module Ehsso
|
|
96
108
|
data = JSON.parse(response.body)
|
97
109
|
|
98
110
|
item = data['response'][0]
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
111
|
+
@id = item['id']
|
112
|
+
@reference = item['reference']
|
113
|
+
@first_name = item['first_name']
|
114
|
+
@last_name = item['last_name']
|
115
|
+
@email = item['email']
|
104
116
|
|
105
117
|
modul = item['modules'][0]
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
118
|
+
@module_key = modul['reference']
|
119
|
+
@module_name = modul['name']
|
120
|
+
@roles = modul['roles']
|
121
|
+
@last_error_message = nil
|
110
122
|
rescue
|
111
|
-
|
123
|
+
@last_error_message = "Unable to parse service response data"
|
112
124
|
end
|
113
125
|
else
|
114
126
|
# something went wrong
|
115
127
|
begin
|
116
128
|
# try to parse the body to get valid error message
|
117
129
|
data = JSON.parse(response.body)
|
118
|
-
|
130
|
+
@last_error_message = data['response_message']
|
119
131
|
rescue
|
120
|
-
|
132
|
+
@last_error_message = "#{response.request.url}: [#{response.code}] #{response.return_message}"
|
121
133
|
end
|
122
134
|
end
|
123
135
|
end
|
data/lib/ehsso/engine.rb
CHANGED
data/lib/ehsso/version.rb
CHANGED