Commit 46c2f71b by lanrion

add more rest_client options config

parent 7c07e087
...@@ -31,13 +31,17 @@ module WeixinAuthorize ...@@ -31,13 +31,17 @@ module WeixinAuthorize
def http_get_without_token(url, headers={}, endpoint="plain") def http_get_without_token(url, headers={}, endpoint="plain")
get_api_url = endpoint_url(endpoint, url) get_api_url = endpoint_url(endpoint, url)
load_json(RestClient.get(get_api_url, :params => headers)) load_json(resource(get_api_url).get(params: headers))
end end
def http_post_without_token(url, payload={}, headers={}, endpoint="plain") def http_post_without_token(url, payload={}, headers={}, endpoint="plain")
post_api_url = endpoint_url(endpoint, url) post_api_url = endpoint_url(endpoint, url)
payload = JSON.dump(payload) if endpoint == "plain" # to json if invoke "plain" payload = JSON.dump(payload) if endpoint == "plain" # to json if invoke "plain"
load_json(RestClient.post(post_api_url, payload, :params => headers)) load_json(resource(post_api_url).post(payload, params: headers))
end
def resource(url)
RestClient::Resource.new(url, rest_client_options)
end end
# return hash # return hash
......
...@@ -9,12 +9,18 @@ module WeixinAuthorize ...@@ -9,12 +9,18 @@ module WeixinAuthorize
end end
def weixin_redis def weixin_redis
return nil if WeixinAuthorize.config.nil? return nil if config.nil?
@redis ||= WeixinAuthorize.config.redis @redis ||= config.redis
end
# 可选配置: RestClient timeout, etc.
# key 必须是符号
def rest_client_options
config.rest_client_options || {timeout: 2, open_timeout: 3, verify_ssl: true}
end end
end end
class Config class Config
attr_accessor :redis attr_accessor :redis, :rest_client_options
end end
end end
...@@ -55,6 +55,7 @@ redis_with_ns = Redis::Namespace.new("#{namespace}", :redis => redis) ...@@ -55,6 +55,7 @@ redis_with_ns = Redis::Namespace.new("#{namespace}", :redis => redis)
WeixinAuthorize.configure do |config| WeixinAuthorize.configure do |config|
config.redis = redis_with_ns config.redis = redis_with_ns
config.rest_client_options = {timeout: 1, open_timeout: 1, verify_ssl: true}
end end
$client = WeixinAuthorize::Client.new(ENV["APPID"], ENV["APPSECRET"]) $client = WeixinAuthorize::Client.new(ENV["APPID"], ENV["APPSECRET"])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment