dc_tunnel 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dc_tunnel.rb +27 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0d118f1185116a85690d26d6a04d8176cf3ef174fb212846fabcbae94ecc233
4
- data.tar.gz: b1d750ab66f2c9b8cf54d2650d9f844776101cb9df1f015eded664b7eedaefd7
3
+ metadata.gz: 9ecf81e7f40a191351a188e746df9b85954278e3d15be589e9bae397247a8bf2
4
+ data.tar.gz: 9b5a1267570f117536d084e325d1835577be2c49f9c9252b2f56b8612b1cd1d7
5
5
  SHA512:
6
- metadata.gz: 07263f9ae7b07b0dfecbf43cfb5c8a76b1fafe7853ccff1860538f8aa6815a405cd7bdd515fb8370065bb2999a07a84ef936cacb9b383492732b98a7febd1d2e
7
- data.tar.gz: 6ef5f20f77d76f70d8f12ea1b0a3941a758acb10e97c18da363f757a44eadd59826e8a712868a39c45f202ccd521b8e0e22403b46114daf0a80c5ae11080a886
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dc_tunnel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Qxchen