Skip to content

Commit

Permalink
Merge pull request #140 from paul/expose-faraday
Browse files Browse the repository at this point in the history
Expose faraday config in Octokit.configure
  • Loading branch information
pengwynn committed Sep 28, 2012
2 parents 13a3a99 + fac016b commit c1c353d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/octokit/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Octokit
module Configuration
VALID_OPTIONS_KEYS = [
:adapter,
:faraday_config_block,
:api_version,
:api_endpoint,
:web_endpoint,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/octokit/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/octokit/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c1c353d

Please sign in to comment.