lib/github_api/connection.rb in github_api-0.12.0 vs lib/github_api/connection.rb in github_api-0.12.1

- old
+ new

@@ -1,14 +1,7 @@ # encoding: utf-8 -require 'faraday' -require 'github_api/response' -require 'github_api/response/mashify' -require 'github_api/response/jsonize' -require 'github_api/response/raise_error' -require 'github_api/response/header' - module Github # Specifies Http connection options module Connection extend self include Github::Constants @@ -34,36 +27,10 @@ ssl: options[:ssl], url: options[:endpoint] } end - # Default middleware stack that uses default adapter as specified at - # configuration stage. - # - def default_middleware(options = {}) - api = options[:api] - proc do |builder| - builder.use Github::Request::Jsonize - builder.use Faraday::Request::Multipart - builder.use Faraday::Request::UrlEncoded - builder.use Github::Request::OAuth2, api.oauth_token if api.oauth_token? - builder.use Github::Request::BasicAuth, api.authentication if api.basic_authed? - - builder.use Faraday::Response::Logger if ENV['DEBUG'] - unless options[:raw] - builder.use Github::Response::Mashify - builder.use Github::Response::Jsonize - end - builder.use Github::Response::RaiseError - builder.adapter options[:adapter] - end - end - - @connection = nil - - @stack = nil - def clear_cache @connection = nil end def caching? @@ -71,28 +38,25 @@ end # Exposes middleware builder to facilitate custom stacks and easy # addition of new extensions such as cache adapter. # - def stack(options = {}, &block) + # @api public + def stack(options = {}) @stack ||= begin builder_class = defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder - - if block_given? - builder_class.new(&block) - else - builder_class.new(&default_middleware(options)) - end + builder_class.new(&Github.default_middleware(options)) end end # Creates http connection # # Returns a Fraday::Connection object def connection(api, options = {}) connection_options = default_options(options) clear_cache unless options.empty? - connection_options.merge!(builder: stack(options.merge!(api: api))) + builder = api.stack ? api.stack : stack(options.merge!(api: api)) + connection_options.merge!(builder: builder) if ENV['DEBUG'] p "Connection options : \n" pp connection_options end @connection ||= Faraday.new(connection_options)