lib/yao/client.rb in yao-0.1.1 vs lib/yao/client.rb in yao-0.2.0.rc1
- old
+ new
@@ -1,10 +1,9 @@
require 'yao'
require 'yao/config'
require 'faraday'
-require 'faraday_middleware'
-require 'yao/faraday_middlewares'
+require 'yao/plugins/default_client_generator'
module Yao
module Client
class ClientSet
def initialize
@@ -40,37 +39,16 @@
end
class << self
attr_accessor :default_client
- 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$/
-
- 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
+ def client_generator
+ Plugins::Registry.instance[:client_generator][Yao.config.client_generator].new
end
def gen_client(endpoint, token: nil)
Faraday.new( endpoint ) do |f|
- client_generator_hook.call(f, token)
+ client_generator.call(f, token)
end
end
def reset_client(new_endpoint=nil)
set = ClientSet.new