Permalink
Browse files

Don't create a new Faraday instance on every request

  • Loading branch information...
1 parent 5956ebf commit b1092481c1d050e6abf8cc70a242a43d809e61f6 @oliverbarnes committed Jan 12, 2012
Showing with 3 additions and 2 deletions.
  1. +2 −1 lib/twitter/connection.rb
  2. +1 −1 lib/twitter/request.rb
@@ -26,7 +26,7 @@ def connection(options={})
:ssl => {:verify => false},
:url => options.fetch(:endpoint, endpoint),
}
- Faraday.new(default_options.deep_merge(connection_options)) do |builder|
+ connection ||=Faraday.new(default_options.deep_merge(connection_options)) do |builder|
builder.use Twitter::Request::Phoenix if options[:phoenix]
builder.use Twitter::Request::MultipartWithFile
builder.use Twitter::Request::TwitterOAuth, credentials if credentials?
@@ -38,6 +38,7 @@ def connection(options={})
builder.use Twitter::Response::RaiseServerError
builder.adapter(adapter)
end
+ connection
end
end
View
@@ -20,7 +20,7 @@ def post(path, params={}, options={})
# Perform an HTTP request
def request(method, path, params, options)
- response = connection(options).send(method) do |request|
+ response = connection(options).run_request(method, nil, nil, nil) do |request|
case method.to_sym
when :delete, :get
request.url(path, params)

2 comments on commit b109248

I believe connection would have to be @connection.

Owner

oliverbarnes replied Jan 12, 2012

good point, changing it

Please sign in to comment.