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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c3e47fde436c74f25ffcda42ee528aec4390bad
4
- data.tar.gz: 77d43af5c6ee632e331464196d689752d62be8ef
3
+ metadata.gz: 94ce6d4c26a580c10a20be66259e463b255b4834
4
+ data.tar.gz: ca2ea9d050f1b554e0e13d371170e369ee6d55c7
5
5
  SHA512:
6
- metadata.gz: c2c20aea3eb75cc8936be04a6426d9219ff9a8a60c624b5a0fc569dc6757d83abfa4395a7552f1101a7d90cd12e56659e5c4441560be87688ebeb6fd09157346
7
- data.tar.gz: c4d1e4b4ec242792695691dc5195106c537ca716ec741d766514a6e47a7ef7e387e530bc9f066e91e3816bc5e39ed8f9636d485bfeca9a90138739c2b096be7e
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 = nil
22
- @module_name = nil
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
- # def method_missing(method)
27
- # @roles.include?(method[0..-2].to_sym)
28
- # end
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
- # first name
45
- person.first_name = header['HTTP_NIBRFIRST'] if header['HTTP_NIBRFIRST'] && header['HTTP_NIBRFIRST'].strip.size > 0
46
-
47
- # last name
48
- person.last_name = header['HTTP_NIBRLAST'] if header["HTTP_NIBRLAST"] && header['HTTP_NIBRFIRST'].strip.size > 0
49
-
50
- # email
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
- response = Typhoeus.post(url, body: payload(action: args[:action]), userpwd: userpwd)
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
- self.id = item['id']
100
- self.reference = item['reference']
101
- self.first_name = item['first_name']
102
- self.last_name = item['last_name']
103
- self.email = item['email']
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
- self.module_key = modul['reference']
107
- self.module_name = modul['name']
108
- self.roles = modul['roles']
109
- self.last_error_message = nil
118
+ @module_key = modul['reference']
119
+ @module_name = modul['name']
120
+ @roles = modul['roles']
121
+ @last_error_message = nil
110
122
  rescue
111
- self.last_error_message = "Unable to parse servcie response data"
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
- self.last_error_message = data['response_message']
130
+ @last_error_message = data['response_message']
119
131
  rescue
120
- self.last_error_message = "#{response.request.url}: [#{response.code}] #{response.return_message}"
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
@@ -1,4 +1,5 @@
1
1
  require 'rails/engine'
2
+ require 'typhoeus'
2
3
 
3
4
  module Cmssso
4
5
  class Engine < ::Rails::Engine
data/lib/ehsso/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ehsso
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehsso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Steiner