<commit_before>require "baichuan/version"

module Baichuan
  class Client

    ACTION_ADD_USERS = 'taobao.openim.users.add'
    ACTION_GET_USERS = 'taobao.openim.users.get'
    ACTION_UPDATE_USERS = 'taobao.openim.users.update'
    ACTION_DELETE_USERS = 'taobao.openim.users.delete'

    ACTION_CUSTMSG_PUSH = 'taobao.openim.custmsg.push'
    ACTION_IMMSG_PUSH = 'taobao.openim.immsg.push'

    ACTION_GET_RELATIONS = 'taobao.openim.relations.get'
    ACTION_GET_CHATLOGS = 'taobao.openim.chatlogs.get'

    ACTION_CREATE_GROUP = 'taobao.openim.tribe.create'
    ACTION_GET_GROUP = 'taobao.openim.tribe.gettribeinfo'
    ACTION_JOIN_GROUP = 'taobao.openim.tribe.join'
    ACTION_INVITE_GROUP = 'taobao.openim.tribe.invite'
    ACTION_QUIT_GROUP = 'taobao.openim.tribe.quit'
    ACTION_EXPEL_GROUP = 'taobao.openim.tribe.expel'
    ACTION_DISSMISS_GROUP = 'taobao.openim.tribe.dismiss'
    ACTION_SET_MANAGER = 'taobao.openim.tribe.setmanager'
    ACTION_GET_MEMBERS = 'taobao.openim.tribe.getmembers'
    ACTION_UNSET_MANAGER = 'taobao.openim.tribe.unsetmanager'
    ACTION_GET_ALL_GROUPS = 'taobao.openim.tribe.getalltribes'
    ACTION_UPDATE_GROUP = 'taobao.openim.tribe.modifytribeinfo'
    ACTION_SET_MEMBER_NICK = 'taobao.openim.tribe.setmembernick'

    ACTION_IMPORT_CHAT_LOGS = 'taobao.openim.chatlogs.import'
    ACTION_IMPORT_GROUP_LOGS = 'taobao.openim.tribelogs.import'
    ACTION_GET_GROUP_LOGS = 'taobao.openim.tribelogs.get'
    ACTION_GET_APP_CHAT_LOGS = 'taobao.openim.app.chatlogs.get'

    ACTION_GET_DETAILS = 'taobao.openim.track.getdetails'
    ACTION_GET_SUMMARY = 'taobao.openim.track.getsummary'

    def initialize(app_key, secret, sandbox = false)
      @version = 1.0
      @api_host = sandbox ? 'https://gw.api.tbsandbox.com/router/rest' : 'https://eco.taobao.com/router/rest'
      @app_key = app_key || ENV['app_key']
      @secret = secret || ENV['secret']
    end

    def make_signature(params)
      Digest::MD5.hexdigest("#{@secret}#{params.sort.join}#{@secret}").upcase
    end

    def header
      {
        'User-Agent'   => 'BaiChuanSdk/BaiChuan-Ruby-Sdk #{RUBY_VERSION} (#{@version})',
        'Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8'
      }
    end

    def common_params(action)
      {
        method: action,
        app_key: @app_key,
        timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
        format: 'json',
        v: '2.0',
        sign_method: 'md5'
      }
    end

    def http_call(url, data)
      uri = URI.parse(url)
      http = Net::HTTP.new(uri.host, uri.port)
      http.use_ssl = uri.scheme == 'https'
      http.ssl_version = :TLSv1
      http.ciphers = ['RC4-SHA']
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      req = Net::HTTP::Post.new(uri.path, initheader = header)
      req.body = URI.encode_www_form(data)
      res = http.request(req)
      response_object(JSON.parse(res.body))
    end

    def response_object(body)
      response = Struct.new(:success, :data).new
      response.success = !body.has_key?('error_response')
      response.data = body
      response
    end

    def post(action, params)
      params = common_params(action).merge(params)
      params.merge!(sign: make_signature(params))
      http_call(@api_host, params)
    end

    def cust_msg_push(cust_msg)
      post( ACTION_CUSTMSG_PUSH, { custmsg: cust_msg } )
    end

    def im_msg_push(im_msg)
      post( ACTION_IMMSG_PUSH, { immsg: im_msg } )
    end

    def add_users(userinfos)
      post( ACTION_ADD_USERS, { userinfos: userinfos.to_json } )
    end

    def get_users(user_ids)
      post( ACTION_GET_USERS, { userids: user_ids.join(',') } )
    end

    def update_users(userinfos)
      post( ACTION_UPDATE_USERS, { userinfos: userinfos.to_json } )
    end
<commit_msg>im_msg.to_json<commit_after>require "baichuan/version"

module Baichuan
  class Client

    ACTION_ADD_USERS = 'taobao.openim.users.add'
    ACTION_GET_USERS = 'taobao.openim.users.get'
    ACTION_UPDATE_USERS = 'taobao.openim.users.update'
    ACTION_DELETE_USERS = 'taobao.openim.users.delete'

    ACTION_CUSTMSG_PUSH = 'taobao.openim.custmsg.push'
    ACTION_IMMSG_PUSH = 'taobao.openim.immsg.push'

    ACTION_GET_RELATIONS = 'taobao.openim.relations.get'
    ACTION_GET_CHATLOGS = 'taobao.openim.chatlogs.get'

    ACTION_CREATE_GROUP = 'taobao.openim.tribe.create'
    ACTION_GET_GROUP = 'taobao.openim.tribe.gettribeinfo'
    ACTION_JOIN_GROUP = 'taobao.openim.tribe.join'
    ACTION_INVITE_GROUP = 'taobao.openim.tribe.invite'
    ACTION_QUIT_GROUP = 'taobao.openim.tribe.quit'
    ACTION_EXPEL_GROUP = 'taobao.openim.tribe.expel'
    ACTION_DISSMISS_GROUP = 'taobao.openim.tribe.dismiss'
    ACTION_SET_MANAGER = 'taobao.openim.tribe.setmanager'
    ACTION_GET_MEMBERS = 'taobao.openim.tribe.getmembers'
    ACTION_UNSET_MANAGER = 'taobao.openim.tribe.unsetmanager'
    ACTION_GET_ALL_GROUPS = 'taobao.openim.tribe.getalltribes'
    ACTION_UPDATE_GROUP = 'taobao.openim.tribe.modifytribeinfo'
    ACTION_SET_MEMBER_NICK = 'taobao.openim.tribe.setmembernick'

    ACTION_IMPORT_CHAT_LOGS = 'taobao.openim.chatlogs.import'
    ACTION_IMPORT_GROUP_LOGS = 'taobao.openim.tribelogs.import'
    ACTION_GET_GROUP_LOGS = 'taobao.openim.tribelogs.get'
    ACTION_GET_APP_CHAT_LOGS = 'taobao.openim.app.chatlogs.get'

    ACTION_GET_DETAILS = 'taobao.openim.track.getdetails'
    ACTION_GET_SUMMARY = 'taobao.openim.track.getsummary'

    def initialize(app_key, secret, sandbox = false)
      @version = 1.0
      @api_host = sandbox ? 'https://gw.api.tbsandbox.com/router/rest' : 'https://eco.taobao.com/router/rest'
      @app_key = app_key || ENV['app_key']
      @secret = secret || ENV['secret']
    end

    def make_signature(params)
      Digest::MD5.hexdigest("#{@secret}#{params.sort.join}#{@secret}").upcase
    end

    def header
      {
        'User-Agent'   => 'BaiChuanSdk/BaiChuan-Ruby-Sdk #{RUBY_VERSION} (#{@version})',
        'Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8'
      }
    end

    def common_params(action)
      {
        method: action,
        app_key: @app_key,
        timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
        format: 'json',
        v: '2.0',
        sign_method: 'md5'
      }
    end

    def http_call(url, data)
      uri = URI.parse(url)
      http = Net::HTTP.new(uri.host, uri.port)
      http.use_ssl = uri.scheme == 'https'
      http.ssl_version = :TLSv1
      http.ciphers = ['RC4-SHA']
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      req = Net::HTTP::Post.new(uri.path, initheader = header)
      req.body = URI.encode_www_form(data)
      res = http.request(req)
      response_object(JSON.parse(res.body))
    end

    def response_object(body)
      response = Struct.new(:success, :data).new
      response.success = !body.has_key?('error_response')
      response.data = body
      response
    end

    def post(action, params)
      params = common_params(action).merge(params)
      params.merge!(sign: make_signature(params))
      http_call(@api_host, params)
    end

    def cust_msg_push(cust_msg)
      post( ACTION_CUSTMSG_PUSH, { custmsg: cust_msg.to_json } )
    end

    def im_msg_push(im_msg)
      post( ACTION_IMMSG_PUSH, { immsg: im_msg.to_json } )
    end

    def add_users(userinfos)
      post( ACTION_ADD_USERS, { userinfos: userinfos.to_json } )
    end

    def get_users(user_ids)
      post( ACTION_GET_USERS, { userids: user_ids.join(',') } )
    end

    def update_users(userinfos)
      post( ACTION_UPDATE_USERS, { userinfos: userinfos.to_json } )
    end

{'fraction_non_alphanumeric': 0.12399313350059421, 'fraction_numerical': 0.0023768651789251288, 'mean_word_length': 3.2839366515837103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2705924', 'n_tokens_mistral': 2951, 'n_tokens_neox': 2890, 'n_words': 380}