Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't create a new Faraday instance on every request

  • Loading branch information...
commit b1092481c1d050e6abf8cc70a242a43d809e61f6 1 parent 5956ebf
@oliverbarnes authored
Showing with 3 additions and 2 deletions.
  1. +2 −1  lib/twitter/connection.rb
  2. +1 −1  lib/twitter/request.rb
View
3  lib/twitter/connection.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
2  lib/twitter/request.rb
@@ -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

@laserlemon

I believe connection would have to be @connection.

@oliverbarnes

good point, changing it

Please sign in to comment.
Something went wrong with that request. Please try again.