Module: Yxt
- Defined in:
- lib/yxt-api.rb,
lib/yxt-api/user.rb,
lib/yxt-api/version.rb,
lib/yxt-api/position.rb,
lib/yxt-api/job_level.rb,
lib/yxt-api/organization_unit.rb
Defined Under Namespace
Classes: YxtAPI_Error
Constant Summary collapse
- VERSION =
'0.0.3'
Class Attribute Summary collapse
-
.apikey ⇒ Object
Returns the value of attribute apikey.
-
.base_url ⇒ Object
Returns the value of attribute base_url.
-
.secretkey ⇒ Object
Returns the value of attribute secretkey.
Class Method Summary collapse
- .batch_change_org_ou(user_names, extend_key, tool_user_id) ⇒ Object
- .delete_ous(ou_code_or_third_system_ids) ⇒ Object
- .disable_users(user_names, is_clear_email_and_mobile: 0) ⇒ Object
- .enable_users(user_names) ⇒ Object
- .get_ou_code_by_ou_name(extend_key, page_index = 1, page_size = 30) ⇒ Object
- .remove_users_from_ou(user_names) ⇒ Object
-
.request(resource, options = {}) ⇒ HTTP::Response
Make an HTTP request with the given verb to YXT API server.
- .sync_ous(ous_hash) ⇒ Object
- .sync_position(position_hash) ⇒ Object
- .sync_users(users_hash, islink: 1, is_send_notice: 0) ⇒ Object
- .upd_grade(grades_hash) ⇒ Object
- .update_position_info(position_no, position_name) ⇒ Object
- .with_signature(options = {}) ⇒ Object
Class Attribute Details
.apikey ⇒ Object
Returns the value of attribute apikey.
16 17 18 |
# File 'lib/yxt-api.rb', line 16 def apikey @apikey end |
.base_url ⇒ Object
Returns the value of attribute base_url.
19 20 21 |
# File 'lib/yxt-api.rb', line 19 def base_url @base_url end |
.secretkey ⇒ Object
Returns the value of attribute secretkey.
17 18 19 |
# File 'lib/yxt-api.rb', line 17 def secretkey @secretkey end |
Class Method Details
.batch_change_org_ou(user_names, extend_key, tool_user_id) ⇒ Object
16 17 18 19 |
# File 'lib/yxt-api/organization_unit.rb', line 16 def self.batch_change_org_ou(user_names, extend_key, tool_user_id) request 'v1/udp/sy/batchchangeorgou', userNames: user_names, extendKey: extend_key, toolUserId: tool_user_id end |
.delete_ous(ou_code_or_third_system_ids) ⇒ Object
8 9 10 |
# File 'lib/yxt-api/organization_unit.rb', line 8 def self.delete_ous(ou_code_or_third_system_ids) request 'v1/udp/sy/deleteous', datas: ou_code_or_third_system_ids end |
.disable_users(user_names, is_clear_email_and_mobile: 0) ⇒ Object
9 10 11 12 |
# File 'lib/yxt-api/user.rb', line 9 def self.disable_users(user_names, is_clear_email_and_mobile: 0) request 'v1/udp/sy/disabledusers', isClearEmailAndMobile: is_clear_email_and_mobile, datas: user_names end |
.enable_users(user_names) ⇒ Object
14 15 16 |
# File 'lib/yxt-api/user.rb', line 14 def self.enable_users(user_names) request 'v1/udp/sy/enabledusers', datas: user_names end |
.get_ou_code_by_ou_name(extend_key, page_index = 1, page_size = 30) ⇒ Object
21 22 23 |
# File 'lib/yxt-api/organization_unit.rb', line 21 def self.get_ou_code_by_ou_name(extend_key, page_index = 1, page_size = 30) request 'v1/udp/sy/deptout', extendKey: extend_key, pageIndex: page_index, pageSize: page_size end |
.remove_users_from_ou(user_names) ⇒ Object
12 13 14 |
# File 'lib/yxt-api/organization_unit.rb', line 12 def self.remove_users_from_ou(user_names) request 'v1/udp/sy/removeusersfromou', datas: user_names end |
.request(resource, options = {}) ⇒ HTTP::Response
Make an HTTP request with the given verb to YXT API server
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/yxt-api.rb', line 26 def self.request(resource, = {}) @http ||= HTTP.persistent @base_url json_params = with_signature() res = @http.post("#{base_url}/#{resource}", json: json_params) case res.code when 40101 raise YxtAPI_Error, '授权码签名无效!' when 50001 raise YxtAPI_Error, '未授权该API!' when 50002 raise YxtAPI_Error, 'API 功能未授权!' when 60100 raise YxtAPI_Error, '服务内部错误!' when 60101 raise YxtAPI_Error, '业务处理错误!' end res end |
.sync_ous(ous_hash) ⇒ Object
4 5 6 |
# File 'lib/yxt-api/organization_unit.rb', line 4 def self.sync_ous(ous_hash) request 'v1/udp/sy/ous', datas: ous_hash end |
.sync_position(position_hash) ⇒ Object
4 5 6 |
# File 'lib/yxt-api/position.rb', line 4 def self.sync_position(position_hash) request 'v1/udp/sy/position', datas: position_hash end |
.sync_users(users_hash, islink: 1, is_send_notice: 0) ⇒ Object
4 5 6 7 |
# File 'lib/yxt-api/user.rb', line 4 def self.sync_users(users_hash, islink: 1, is_send_notice: 0) request 'v1/udp/sy/users', islink: islink, isSendNotice: is_send_notice, datas: users_hash end |
.upd_grade(grades_hash) ⇒ Object
4 5 6 |
# File 'lib/yxt-api/job_level.rb', line 4 def self.upd_grade(grades_hash) request 'v1/udp/sy/updgrade', datas: grades_hash end |
.update_position_info(position_no, position_name) ⇒ Object
8 9 10 |
# File 'lib/yxt-api/position.rb', line 8 def self.update_position_info(position_no, position_name) request 'v1/udp/sy/updatepositioninfo', positionNo: position_no, positionName: position_name end |
.with_signature(options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/yxt-api.rb', line 51 def self.with_signature( = {}) salt = SecureRandom.hex(4) # like "301bccce" signature = Digest::SHA256.hexdigest("#{secretkey}#{salt}") { apikey: apikey, salt: salt, signature: signature }.merge end |