From fac016bcd559a5b57999a3538cc8f1a45ff8a0a8 Mon Sep 17 00:00:00 2001 From: Paul Sadauskas Date: Thu, 27 Sep 2012 11:46:28 -0600 Subject: [PATCH] Expose faraday config in Octokit.configure --- lib/octokit/configuration.rb | 5 +++++ lib/octokit/connection.rb | 6 ++++++ spec/octokit/client_spec.rb | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/lib/octokit/configuration.rb b/lib/octokit/configuration.rb index bc6d18b3a..a16fda6e7 100644 --- a/lib/octokit/configuration.rb +++ b/lib/octokit/configuration.rb @@ -5,6 +5,7 @@ module Octokit module Configuration VALID_OPTIONS_KEYS = [ :adapter, + :faraday_config_block, :api_version, :api_endpoint, :web_endpoint, @@ -48,6 +49,10 @@ def web_endpoint=(value) @web_endpoint = File.join(value, "") end + def faraday_config(&block) + @faraday_config_block = block + end + def reset self.adapter = DEFAULT_ADAPTER self.api_version = DEFAULT_API_VERSION diff --git a/lib/octokit/connection.rb b/lib/octokit/connection.rb index facde6459..81f592e58 100644 --- a/lib/octokit/connection.rb +++ b/lib/octokit/connection.rb @@ -28,13 +28,19 @@ def connection(authenticate=true, raw=false, version=3, force_urlencoded=false) else builder.request :url_encoded end + builder.use Faraday::Response::RaiseOctokitError + unless raw builder.use FaradayMiddleware::Mashify builder.use FaradayMiddleware::ParseJson end + + faraday_config_block.call(builder) if faraday_config_block + builder.adapter *adapter end + connection.basic_auth authentication[:login], authentication[:password] if authenticate and authenticated? connection end diff --git a/spec/octokit/client_spec.rb b/spec/octokit/client_spec.rb index 87ce570cd..560d7a1f4 100644 --- a/spec/octokit/client_spec.rb +++ b/spec/octokit/client_spec.rb @@ -10,6 +10,19 @@ }.should_not raise_exception end + it 'should configure faraday from faraday_config_block' do + mw_evaluated = false + Octokit.configure do |c| + c.faraday_config { |f| mw_evaluated = true } + end + stub_request(:get, "https://api.github.com/rate_limit"). + to_return(:status => 200, :body => '', :headers => + { 'X-RateLimit-Limit' => 5000, 'X-RateLimit-Remaining' => 5000}) + client = Octokit::Client.new() + client.rate_limit + mw_evaluated.should be_true + end + describe "auto_traversal" do