dc_tunnel 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dc_tunnel.rb +27 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ecf81e7f40a191351a188e746df9b85954278e3d15be589e9bae397247a8bf2
|
4
|
+
data.tar.gz: 9b5a1267570f117536d084e325d1835577be2c49f9c9252b2f56b8612b1cd1d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cf74e50da5aa831ef94b7713729d230bed113c4378342a23156d3c716d59bc7b4bcd87c4c7d8d671edeab328367ba677495e509fcc84a4af23e8cb066045ec5
|
7
|
+
data.tar.gz: fa853d2266bb759c9bfda78778db77aed96051923d7309aae1a542390aac785e26489ea0e591482495ba7a169dd75e194db057b600ad3c832b5a31cc5aae8076
|
data/lib/dc_tunnel.rb
CHANGED
@@ -2,17 +2,17 @@ class DcTunnel
|
|
2
2
|
require 'net/http'
|
3
3
|
|
4
4
|
def initialize(settings)
|
5
|
-
@settings=settings
|
5
|
+
@settings = settings
|
6
6
|
end
|
7
7
|
|
8
8
|
def get_settings
|
9
9
|
@settings
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def http_get(url)
|
13
13
|
puts "Tunnel : start get #{url} "
|
14
14
|
res = Net::HTTP.get(URI(url))
|
15
|
-
res = JSON.parse(res)
|
15
|
+
res = JSON.parse(res).symbolize_keys!
|
16
16
|
puts "Tunnel : got response #{res} "
|
17
17
|
res
|
18
18
|
end
|
@@ -20,7 +20,7 @@ class DcTunnel
|
|
20
20
|
def http_post(url, postdata)
|
21
21
|
puts "Tunnel : start get #{url} "
|
22
22
|
res = Net::HTTP.post_form(URI(url), postdata).body
|
23
|
-
res = JSON.parse(res)
|
23
|
+
res = JSON.parse(res).symbolize_keys!
|
24
24
|
puts "Tunnel : got response #{res} "
|
25
25
|
res
|
26
26
|
end
|
@@ -29,8 +29,8 @@ class DcTunnel
|
|
29
29
|
settings = self.get_settings
|
30
30
|
puts "Tunnel : sso_path set to #{settings[:sso_host]} "
|
31
31
|
auth = {
|
32
|
-
system_id:settings[:system_id],
|
33
|
-
system_token:settings[:system_token]
|
32
|
+
system_id: settings[:system_id],
|
33
|
+
system_token: settings[:system_token]
|
34
34
|
}
|
35
35
|
puts "Auth : #{auth}"
|
36
36
|
"#{settings[:sso_host]}#{path}.json?#{params.to_param}&#{auth.to_param}"
|
@@ -53,4 +53,25 @@ class DcTunnel
|
|
53
53
|
# id phone department_ids factory_ids
|
54
54
|
http_get self.sso_path("/users", params)
|
55
55
|
end
|
56
|
+
|
57
|
+
def synchronize
|
58
|
+
res = http_get self.sso_path('/users', {:system_ids => [self.get_settings[:system_id]]})
|
59
|
+
res['users'].each do |sso_user|
|
60
|
+
user = User.find_by_sso_id sso_user['id']
|
61
|
+
if user.nil?
|
62
|
+
create_attributes = {}
|
63
|
+
get_settings[:default_user_props].each do |item|
|
64
|
+
name = item[0]
|
65
|
+
value = item[1]
|
66
|
+
create_attributes[name] = sso_user[name].present? ? sso_user[name] : value
|
67
|
+
end
|
68
|
+
User.create create_attributes
|
69
|
+
else
|
70
|
+
user.update({
|
71
|
+
name: sso_user[:name],
|
72
|
+
phone: sso_user[:phone]
|
73
|
+
})
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
56
77
|
end
|