Module: YxSdk

Defined in:
lib/yx_sdk.rb,
lib/yx_sdk/client.rb,
lib/yx_sdk/config.rb,
lib/yx_sdk/version.rb,
lib/yx_sdk/api/user.rb,
lib/yx_sdk/handler/result_handler.rb

Defined Under Namespace

Modules: Api Classes: Client, Config, ResultHandler

Constant Summary collapse

DEFAULT_CODE =
200
VERSION =
"0.1.4"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config.



4
5
6
# File 'lib/yx_sdk/config.rb', line 4

def config
  @config
end

Class Method Details

.api_endpointObject



43
44
45
# File 'lib/yx_sdk.rb', line 43

def api_endpoint
  "https://api.netease.im"
end

.configure {|self.config ||= Config.new| ... } ⇒ Object

Yields:



6
7
8
# File 'lib/yx_sdk/config.rb', line 6

def configure
  yield self.config ||= Config.new
end

.endpoint_url(endpoint, url) ⇒ Object



35
36
37
# File 'lib/yx_sdk.rb', line 35

def endpoint_url(endpoint, url)
  send("#{endpoint}_endpoint") + url
end

.http_post_without_token(url, post_body = {}, url_params = {}, header = {}, endpoint = "plain") ⇒ Object



14
15
16
17
18
19
20
# File 'lib/yx_sdk.rb', line 14

def http_post_without_token(url, post_body={}, url_params={}, header = {}, endpoint="plain")
  post_api_url = endpoint_url(endpoint, url)
  if endpoint == "plain" || endpoint == CUSTOM_ENDPOINT
    post_body = JSON.dump(post_body)
  end
  load_json(resource(post_api_url, header).post(post_body, params: url_params))
end

.load_json(string) ⇒ Object

return hash



28
29
30
31
32
33
# File 'lib/yx_sdk.rb', line 28

def load_json(string)
  result_hash = JSON.parse(string.force_encoding("UTF-8").gsub(/[\u0011-\u001F]/, ""))
  code   = result_hash.delete("code")
  info = result_hash.delete("info")
  ResultHandler.new(code, info)
end

.plain_endpointObject



39
40
41
# File 'lib/yx_sdk.rb', line 39

def plain_endpoint
  "#{api_endpoint}/nimserver"
end

.resource(url, header) ⇒ Object



23
24
25
# File 'lib/yx_sdk.rb', line 23

def resource(url, header)
  RestClient::Resource.new(url, header)
end

.rest_client_optionsObject

可选配置: 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



14
15
16
17
18
19
# 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