module YxSdk

Constants

DEFAULT_CODE
VERSION

Attributes

config[RW]

Public Class Methods

api_endpoint() click to toggle source
# File lib/yx_sdk.rb, line 50
def api_endpoint
  "https://api.netease.im"
end
configure() { |config ||= config| ... } click to toggle source
# File lib/yx_sdk/config.rb, line 6
def configure
  yield self.config ||= Config.new
end
endpoint_url(endpoint, url) click to toggle source
# File lib/yx_sdk.rb, line 42
def endpoint_url(endpoint, url)
  send("#{endpoint}_endpoint") + url
end
http_post_without_token(url, url_params={}, header = {}, endpoint="plain") click to toggle source
# File lib/yx_sdk.rb, line 18
def http_post_without_token(url, url_params={}, header = {}, endpoint="plain")
  post_api_url = endpoint_url(endpoint, url)
  post_body = ''
  if endpoint == "plain" || endpoint == CUSTOM_ENDPOINT
    url_params.each {|k,v| post_body = post_body + "#{k}=#{v}&"}
  end
  puts "request url is #{post_api_url}, header is #{header}, post_body is #{post_body[0..-1]}"
  load_json(resource(post_api_url, header).post(post_body[0..-1]))
end
load_json(string) click to toggle source

return hash

# File lib/yx_sdk.rb, line 34
def load_json(string)
  result_hash = JSON.parse(string.force_encoding("UTF-8").gsub(/[\u0011-\u001F]/, ""))
  puts "response #{result_hash}"
  code   = result_hash.delete("code")
  info = result_hash.delete("info")
  ResultHandler.new(code, info)
end
plain_endpoint() click to toggle source
# File lib/yx_sdk.rb, line 46
def plain_endpoint
  "#{api_endpoint}/nimserver"
end
resource(url, header) click to toggle source
# File lib/yx_sdk.rb, line 29
def resource(url, header)
  RestClient::Resource.new(url, :headers => header)
end
rest_client_options() click to toggle source

可选配置: RestClient timeout, etc. key 必须是符号 如果出现 RestClient::SSLCertificateNotVerified Exception: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed 这个错,除了改 verify_ssl: true,请参考:www.extendi.it/blog/2015/5/23/47-sslv3-read-server-certificate-b-certificate-verify-failed

# File lib/yx_sdk/config.rb, line 14
def rest_client_options
  if config.nil?
    return {timeout: 5, open_timeout: 5, verify_ssl: true}
  end
  config.rest_client_options
end