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
.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
43
44
45
|
# File 'lib/yx_sdk.rb', line 43
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
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={}, = {}, 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, ).post(post_body, params: url_params))
end
|
.load_json(string) ⇒ Object
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_endpoint ⇒ Object
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, )
RestClient::Resource.new(url, )
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
|