module Dingtalk

Constants

CUSTOM_ENDPOINT
ECO_ENDPOINT
GLOBAL_CODES
OK_CODE
OK_MSG
VERSION

Attributes

config[RW]
current_endpoint[RW]

Public Class Methods

api_endpoint() click to toggle source
# File lib/dingtalk.rb, line 65
def api_endpoint
  "https://oapi.dingtalk.com"
end
calculate_expire(expires_in) click to toggle source
# File lib/dingtalk.rb, line 73
def calculate_expire(expires_in)
  Time.now.to_i + expires_in.to_i - key_expired.to_i
end
configure() { |config ||= config| ... } click to toggle source
# File lib/dingtalk/config.rb, line 4
def configure
  yield self.config ||= Config.new
end
eco?() click to toggle source
# File lib/dingtalk.rb, line 28
def eco?
  @current_endpoint == ECO_ENDPOINT
end
eco_endpoint() click to toggle source
# File lib/dingtalk.rb, line 69
def eco_endpoint
  "https://eco.taobao.com/router/rest"
end
endpoint_url(url) click to toggle source
# File lib/dingtalk.rb, line 57
def endpoint_url(url)
  if eco?
    eco_endpoint
  else
    "#{api_endpoint}" + url
  end
end
http_get_without_token(url, url_params={}, endpoint="api") click to toggle source
# File lib/dingtalk.rb, line 32
def http_get_without_token(url, url_params={}, endpoint="api")
  @current_endpoint = endpoint
  load_json(resource(url).get(params: url_params), url)
end
http_post_without_token(url, _post_body={}, url_params={}, endpoint="api") click to toggle source
# File lib/dingtalk.rb, line 37
def http_post_without_token(url, _post_body={}, url_params={}, endpoint="api")
  @current_endpoint = endpoint
  load_json(resource(url).post(JSON.dump(_post_body), params: url_params, content_type: :json), url)
end
key_expired() click to toggle source
# File lib/dingtalk/config.rb, line 13
def key_expired
  return 100 if config.nil?
  config.key_expired || 100
end
load_json(string, url) click to toggle source
# File lib/dingtalk.rb, line 46
def load_json(string, url)
  result_hash = JSON.parse(string.force_encoding("UTF-8").gsub(/[\u0011-\u001F]/, ""))
  if eco?
    EcoResultHandler.new(url, result_hash)
  else
    code   = result_hash.delete("errcode")
    en_msg = result_hash.delete("errmsg")
    ResultHandler.new(code, en_msg, result_hash)
  end
end
redis() click to toggle source
# File lib/dingtalk/config.rb, line 8
def redis
  return nil if config.nil?
  @redis ||= config.redis
end
resource(url) click to toggle source
# File lib/dingtalk.rb, line 42
def resource(url)
  RestClient::Resource.new(endpoint_url(url), rest_client_options)
end
rest_client_options() click to toggle source
# File lib/dingtalk/config.rb, line 18
def rest_client_options
  if config.nil?
    return {timeout: 5, open_timeout: 5, verify_ssl: true}
  end
  config.rest_client_options
end