lib/yao/client.rb in yao-0.0.2.rc3 vs lib/yao/client.rb in yao-0.0.2
- old
+ new
@@ -31,40 +31,57 @@
end
class << self
attr_accessor :default_client
- def gen_client(endpoint, token: nil)
- Faraday.new( endpoint ) do |f|
+ def client_generator_hook
+ lambda do |f, token|
f.request :url_encoded
f.request :json
if token
f.request :os_token, token
end
+ f.response :os_error_detector
f.response :json, :content_type => /\bjson$/
- f.response :logger
+ if Yao.config.debug
+ f.response :logger
+ f.response :os_dumper
+ end
+
+ if Yao.config.debug_record_response
+ f.response :os_response_recorder
+ end
+
f.adapter Faraday.default_adapter
end
end
+ def gen_client(endpoint, token: nil)
+ Faraday.new( endpoint ) do |f|
+ client_generator_hook.call(f, token)
+ end
+ end
+
def reset_client(new_endpoint=nil)
set = ClientSet.new
set.register_endpoints("default" => (new_endpoint || Yao.config.endpoint))
self.default_client = set
end
end
Yao.config.param :auth_url, nil do |endpoint|
if endpoint
Yao::Client.reset_client(endpoint)
- Yao::Auth.try_new
end
end
end
def self.default_client
Yao::Client.default_client
end
+
+ Yao.config.param :debug, false
+ Yao.config.param :debug_record_response, false
end