dc_tunnel 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/dc_tunnel.rb +56 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b0d118f1185116a85690d26d6a04d8176cf3ef174fb212846fabcbae94ecc233
4
+ data.tar.gz: b1d750ab66f2c9b8cf54d2650d9f844776101cb9df1f015eded664b7eedaefd7
5
+ SHA512:
6
+ metadata.gz: 07263f9ae7b07b0dfecbf43cfb5c8a76b1fafe7853ccff1860538f8aa6815a405cd7bdd515fb8370065bb2999a07a84ef936cacb9b383492732b98a7febd1d2e
7
+ data.tar.gz: 6ef5f20f77d76f70d8f12ea1b0a3941a758acb10e97c18da363f757a44eadd59826e8a712868a39c45f202ccd521b8e0e22403b46114daf0a80c5ae11080a886
data/lib/dc_tunnel.rb ADDED
@@ -0,0 +1,56 @@
1
+ class DcTunnel
2
+ require 'net/http'
3
+
4
+ def initialize(settings)
5
+ @settings=settings
6
+ end
7
+
8
+ def get_settings
9
+ @settings
10
+ end
11
+
12
+ def http_get(url)
13
+ puts "Tunnel : start get #{url} "
14
+ res = Net::HTTP.get(URI(url))
15
+ res = JSON.parse(res)
16
+ puts "Tunnel : got response #{res} "
17
+ res
18
+ end
19
+
20
+ def http_post(url, postdata)
21
+ puts "Tunnel : start get #{url} "
22
+ res = Net::HTTP.post_form(URI(url), postdata).body
23
+ res = JSON.parse(res)
24
+ puts "Tunnel : got response #{res} "
25
+ res
26
+ end
27
+
28
+ def sso_path(path, params = {})
29
+ settings = self.get_settings
30
+ puts "Tunnel : sso_path set to #{settings[:sso_host]} "
31
+ auth = {
32
+ system_id:settings[:system_id],
33
+ system_token:settings[:system_token]
34
+ }
35
+ puts "Auth : #{auth}"
36
+ "#{settings[:sso_host]}#{path}.json?#{params.to_param}&#{auth.to_param}"
37
+ end
38
+
39
+ def get_user(id)
40
+ http_get self.sso_path("/users/#{id}")
41
+ end
42
+
43
+ def get_factories(params = {})
44
+ http_get self.sso_path("/factories", params)
45
+ end
46
+
47
+ def get_departments(params = {})
48
+ http_get self.sso_path('/departments', params)
49
+ end
50
+
51
+ def get_users(params = {})
52
+ # available params:
53
+ # id phone department_ids factory_ids
54
+ http_get self.sso_path("/users", params)
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dc_tunnel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Qxchen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 信诺系统通信工具
14
+ email: 370306609@qq.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/dc_tunnel.rb
20
+ homepage:
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.0.2
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Tunnel!
43
+ test_files: []