module Yxt

Constants

VERSION

Attributes

apikey[RW]
base_url[RW]
secretkey[RW]

Public Class Methods

batch_change_org_ou(user_names, extend_key, tool_user_id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
insert_positions(position_hash) click to toggle source
# File lib/yxt-api/position.rb, line 4
def self.insert_positions(position_hash)
  request 'v1/udp/sy/position', datas: position_hash
end
remove_users_from_ou(user_names) click to toggle source
# 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 = {}) click to toggle source

Make an HTTP request with the given verb to YXT API server @param resource [String] @option options [Hash] @return [HTTP::Response]

# File lib/yxt-api.rb, line 26
def self.request(resource, options = {})
  @http ||= HTTP.persistent @base_url

  json_params = with_signature(options)

  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) click to toggle source
# 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_users(users_hash, islink: 1, is_send_notice: 0) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Class Methods

with_signature(options = {}) click to toggle source
# File lib/yxt-api.rb, line 51
def self.with_signature(options = {})
  salt = SecureRandom.hex(4) # like "301bccce"
  signature = Digest::SHA256.hexdigest("#{secretkey}#{salt}")

  {
    apikey: apikey,
    salt: salt,
    signature: signature
  }.merge options
end