Skip to content

Commit

Permalink
define the middleware as a Faraday::Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
stve committed Jun 12, 2012
1 parent b1c4dab commit 2bd5010
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/twitter/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ module Config
DEFAULT_MEDIA_ENDPOINT = 'https://upload.twitter.com'

# The middleware stack if none is set
DEFAULT_MIDDLEWARE = Proc.new do |builder|
DEFAULT_MIDDLEWARE = Faraday::Builder.new(&Proc.new { |builder|
builder.use Twitter::Request::MultipartWithFile
builder.use Faraday::Request::Multipart
builder.use Faraday::Request::UrlEncoded
builder.use Twitter::Response::RaiseClientError
builder.use Twitter::Response::ParseJson
builder.use Twitter::Response::RaiseServerError
builder.adapter Faraday.default_adapter
end
})

# The oauth token if none is set
DEFAULT_OAUTH_TOKEN = ENV['TWITTER_OAUTH_TOKEN']
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def connection

options = default_options.deep_merge(connection_options)

@connection = Faraday.new(endpoint, options, &middleware)
@connection = Faraday.new(endpoint, options.merge(:builder => middleware))
end

# Perform an HTTP request
Expand Down
6 changes: 6 additions & 0 deletions spec/twitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
end
end

describe '.middleware' do
it "should return a Faraday::Builder" do
Twitter.middleware.should be_kind_of(Faraday::Builder)
end
end

describe ".configure" do
Twitter::Config::VALID_OPTIONS_KEYS.each do |key|
it "should set the #{key}" do
Expand Down

1 comment on commit 2bd5010

@sferik
Copy link
Owner

@sferik sferik commented on 2bd5010 Jun 13, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good but could you also please update the section of the README that talks about middleware configuration?

Please sign in to comment.