yxt-api 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2ef7748d9a245112f17132cc8cd3a825c616dd840085236a6e4537dec92bab68
4
+ data.tar.gz: 5a747af6aed46fc9c49e02926367c9c18167e91e017ad68a0d14c8edd2492edc
5
+ SHA512:
6
+ metadata.gz: 193cc98a0a1a6067ccd669beb8ce939fc053ec78eab73b388e5ee566a7137828b236a2c809783a567eb692cfe8658a5dbb025ec8b33e4b3231efb263d28ba59d
7
+ data.tar.gz: fdeb76a0c97756c6133b251c1d7544188855aab184851715a727e28ebf281528ebc6e5edaf29c0172fbe962faf8f5e28b33cf6fed2c5c460e71eeabe185cecb3
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.idea
2
+ .DS_Store
3
+ /.bundle/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+ *.sublime-workspace
13
+ spec/examples.txt
14
+ .byebug_history
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Eric-Guo @ Tianhua Architectural Design Co., Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ yxt-api [![Gem Version][version-badge]][rubygems]
2
+ =======
3
+
4
+ An unofficial 云学堂 http://www.yxt.com/ API wrap gem.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'yxt-api'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install yxt-api
21
+
22
+ ## Usage
23
+
24
+ ### Config
25
+
26
+ Create `config/initializers/yxt-api.rb` and put following configurations into your Rails project.
27
+
28
+ ```ruby
29
+ Yxt.apikey = 'your_api_key'
30
+ Yxt.secretkey = 'your_secret_key'
31
+ Yxt.base_url = 'http://api.yunxuetang.com.cn' # notice no / at end
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thape-cn/yxt-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
42
+
43
+
44
+ [version-badge]: https://badge.fury.io/rb/yxt-api.svg
data/lib/yxt-api.rb ADDED
@@ -0,0 +1,58 @@
1
+ require 'http'
2
+ require 'json'
3
+ require 'digest'
4
+ require 'yxt-api/organization_unit'
5
+ require 'yxt-api/position'
6
+ require 'yxt-api/user'
7
+ require 'yxt-api/version'
8
+
9
+ module Yxt
10
+ class YxtAPI_Error < RuntimeError; end
11
+
12
+ class << self
13
+ attr_accessor :apikey
14
+ attr_accessor :secretkey
15
+
16
+ attr_accessor :base_url
17
+ end
18
+
19
+ # Make an HTTP request with the given verb to YXT API server
20
+ # @param resource [String]
21
+ # @option options [Hash]
22
+ # @return [HTTP::Response]
23
+ def self.request(resource, options = {})
24
+ @http ||= HTTP.persistent @base_url
25
+
26
+ json_params = with_signature(options)
27
+
28
+ res = @http.post("#{base_url}/#{resource}", json: json_params)
29
+
30
+ case res.code
31
+ when 40101
32
+ raise YxtAPI_Error, '授权码签名无效!'
33
+ when 50001
34
+ raise YxtAPI_Error, '未授权该API!'
35
+ when 50002
36
+ raise YxtAPI_Error, 'API 功能未授权!'
37
+ when 60100
38
+ raise YxtAPI_Error, '服务内部错误!'
39
+ when 60101
40
+ raise YxtAPI_Error, '业务处理错误!'
41
+ end
42
+
43
+ res
44
+ end
45
+
46
+ private_class_method
47
+
48
+ def self.with_signature(options = {})
49
+ salt = SecureRandom.hex(4) # like "301bccce"
50
+ signature = Digest::SHA256.hexdigest("#{secretkey}#{salt}")
51
+
52
+ {
53
+ apikey: apikey,
54
+ salt: salt,
55
+ signature: signature
56
+ }.merge options
57
+ end
58
+ end
@@ -0,0 +1,21 @@
1
+ module Yxt
2
+ def self.sync_ous(ous_hash, isBaseInfo: false)
3
+ request 'el/sync/ous', isBaseInfo: isBaseInfo, ouInfo: ous_hash.to_json.to_s
4
+ end
5
+
6
+ def self.delete_ous(ou_code_or_third_system_ids)
7
+ request 'el/sync/deleteous', OuCodeOrThirdSystemID: ou_code_or_third_system_ids.to_json.to_s
8
+ end
9
+
10
+ def self.remove_user_from_all_ous(user_names)
11
+ request 'el/sync/removeusersfromou', userNames: user_names.to_json.to_s
12
+ end
13
+
14
+ def self.batch_change_org_ou(new_ou_id, user_names)
15
+ request 'el/sync/batchchangeorgou', newOuID: new_ou_id, userNames: user_names.to_json.to_s
16
+ end
17
+
18
+ def self.get_ou_code_by_ou_name(ou_name, islink: true)
19
+ request 'el/sync/getoucodebyouname', islink: islink, ouname: ou_name
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Yxt
2
+ def self.sync_position(position_hash)
3
+ request 'el/sync/position', positionInfo: position_hash.to_json.to_s
4
+ end
5
+
6
+ def self.sync_position_for_no_pno(position_hash)
7
+ request 'el/sync/positionfornopno', positionInfo: position_hash.to_json.to_s
8
+ end
9
+
10
+ def self.update_position_name(position_no, position_name)
11
+ request 'el/sync/updatepositioninfo', positionNo: position_no, positionName: position_name
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module Yxt
2
+ def self.sync_users(users_hash, islink: true)
3
+ request 'el/sync/users', islink: islink, users: users_hash.to_json.to_s
4
+ end
5
+
6
+ def self.disable_users(user_names, isClearEmailAndMobile: false)
7
+ request 'el/sync/disabledusers', userNames: user_names.to_json.to_s, isClearEmailAndMobile: isClearEmailAndMobile
8
+ end
9
+
10
+ def self.enable_users(user_names)
11
+ request 'el/sync/enabledusers', userNames: user_names.to_json.to_s
12
+ end
13
+
14
+ def self.delete_users(user_names)
15
+ request 'el/sync/deletedusers', userNames: user_names.to_json.to_s
16
+ end
17
+
18
+ def self.check_user(user_name)
19
+ request 'el/sync/cku', userNames: user_name
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Yxt
2
+ VERSION = '0.0.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yxt-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eric Guo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEQDCCAqigAwIBAgIBATANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBplcmlj
14
+ Lmd1b2N6L0RDPWdtYWlsL0R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zSeb5/IPaeN+RB4Rh7D
30
+ 2msnkJhsf0IQbNNUt53tkE5KhwAkHGdY5solSLPwtUmmdW1kNt7OfGBTi5CjXwFg
31
+ Jh+lbxasy+KwHA6+9O5b8Qm2QSBN5bJGd2a63QE5p8cjRBnaRuiKn4wkmqMj/C0Z
32
+ OyM5lSs5iGML+eVE/dCsV+YFmSr6Ue8vokmKdrBDjtAkHwmVA0TpqHVmT+9bVUPn
33
+ Jl+EzvEfsjriqcj9+WGPo4R7XDQQnseHqzlXNedkrLFX/nTnEs5RKBZ6Ter1KRU6
34
+ ivoox98/nhOs6bHcSFPsxXdxUihcCfCzj+zcaHNEqpvTI/36Bnl2XW6dUJNaFQDc
35
+ oWOyq5ZkxqnYrYXactjW0+vcPv6WHoHXmjv4dF7iFp8r0mvK
36
+ -----END CERTIFICATE-----
37
+ date: 2019-04-08 00:00:00.000000000 Z
38
+ dependencies:
39
+ - !ruby/object:Gem::Dependency
40
+ name: http
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.0.3
46
+ - - "<"
47
+ - !ruby/object:Gem::Version
48
+ version: '5'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.0.3
56
+ - - "<"
57
+ - !ruby/object:Gem::Version
58
+ version: '5'
59
+ - !ruby/object:Gem::Dependency
60
+ name: rake
61
+ requirement: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - "~>"
64
+ - !ruby/object:Gem::Version
65
+ version: '11.3'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '11.3'
73
+ - !ruby/object:Gem::Dependency
74
+ name: rspec
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '3.5'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '3.5'
87
+ description: Helping rubyist integration with YXT API easier.
88
+ email:
89
+ - eric.guocz@gmail.com
90
+ executables: []
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - ".gitignore"
95
+ - LICENSE
96
+ - README.md
97
+ - lib/yxt-api.rb
98
+ - lib/yxt-api/organization_unit.rb
99
+ - lib/yxt-api/position.rb
100
+ - lib/yxt-api/user.rb
101
+ - lib/yxt-api/version.rb
102
+ homepage: https://github.com/thape-cn/yxt-api
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: '2.3'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubygems_version: 3.0.3
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: An unofficial 云学堂 http://www.yxt.com/ API wrap gem
125
+ test_files: []
metadata.gz.sig ADDED
Binary file