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.7"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.config ⇒ Object
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_endpoint ⇒ Object
50
51
52
|
# File 'lib/yx_sdk.rb', line 50
def api_endpoint
"https://api.netease.im"
end
|
6
7
8
|
# File 'lib/yx_sdk/config.rb', line 6
def configure
yield self.config ||= Config.new
end
|
.endpoint_url(endpoint, url) ⇒ Object
42
43
44
|
# 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") ⇒ Object
18
19
20
21
22
23
24
25
26
|
# File 'lib/yx_sdk.rb', line 18
def http_post_without_token(url, url_params={}, = {}, 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 #{}, post_body is #{post_body[0..-1]}"
load_json(resource(post_api_url, ).post(post_body[0..-1]))
end
|
.load_json(string) ⇒ Object
34
35
36
37
38
39
40
|
# 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 ⇒ Object
46
47
48
|
# File 'lib/yx_sdk.rb', line 46
def plain_endpoint
"#{api_endpoint}/nimserver"
end
|
.resource(url, header) ⇒ Object
29
30
31
|
# File 'lib/yx_sdk.rb', line 29
def resource(url, )
RestClient::Resource.new(url, :headers => )
end
|
.rest_client_options ⇒ Object
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
|