Commit 46c2f71b by lanrion

add more rest_client options config

parent 7c07e087
......@@ -31,13 +31,17 @@ module WeixinAuthorize
def http_get_without_token(url, headers={}, endpoint="plain")
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
def http_post_without_token(url, payload={}, headers={}, endpoint="plain")
post_api_url = endpoint_url(endpoint, url)
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
# return hash
......
......@@ -9,12 +9,18 @@ module WeixinAuthorize
end
def weixin_redis
return nil if WeixinAuthorize.config.nil?
@redis ||= WeixinAuthorize.config.redis
return nil if config.nil?
@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
class Config
attr_accessor :redis
attr_accessor :redis, :rest_client_options
end
end
......@@ -55,6 +55,7 @@ redis_with_ns = Redis::Namespace.new("#{namespace}", :redis => redis)
WeixinAuthorize.configure do |config|
config.redis = redis_with_ns
config.rest_client_options = {timeout: 1, open_timeout: 1, verify_ssl: true}
end
$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