From 4cc469761ea9e663abaf761e061a89e848ce9beb Mon Sep 17 00:00:00 2001 From: Isaac Date: Wed, 14 Sep 2011 19:17:06 -0400 Subject: [PATCH] option for passing options directly to faraday --- lib/twitter/configuration.rb | 6 +++++- lib/twitter/connection.rb | 6 ++++-- spec/twitter/api_spec.rb | 1 + spec/twitter/search_spec.rb | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/twitter/configuration.rb b/lib/twitter/configuration.rb index 74d58373a..a7032dad8 100644 --- a/lib/twitter/configuration.rb +++ b/lib/twitter/configuration.rb @@ -16,7 +16,8 @@ module Configuration :proxy, :search_endpoint, :user_agent, - :media_endpoint].freeze + :media_endpoint, + :faraday_options].freeze # The adapter that will be used to connect if none is set DEFAULT_ADAPTER = :net_http @@ -64,6 +65,8 @@ module Configuration # This endpoint will be used by default when updating statuses with media DEFAULT_MEDIA_ENDPOINT = 'https://upload.twitter.com/'.freeze + DEFAULT_FARADAY_OPTIONS = {}.freeze + # @private attr_accessor *VALID_OPTIONS_KEYS @@ -98,6 +101,7 @@ def reset self.user_agent = DEFAULT_USER_AGENT self.gateway = DEFAULT_GATEWAY self.media_endpoint = DEFAULT_MEDIA_ENDPOINT + self.faraday_options = DEFAULT_FARADAY_OPTIONS self end end diff --git a/lib/twitter/connection.rb b/lib/twitter/connection.rb index 752ed59f9..fbfcd063b 100644 --- a/lib/twitter/connection.rb +++ b/lib/twitter/connection.rb @@ -12,7 +12,7 @@ module Connection private def connection(options={}) - Faraday.new( + merged_options = faraday_options.merge({ :headers => { 'Accept' => "application/#{format}", 'User-Agent' => user_agent @@ -20,7 +20,9 @@ def connection(options={}) :proxy => proxy, :ssl => {:verify => false}, :url => options.fetch(:endpoint, api_endpoint) - ) do |builder| + }) + + Faraday.new(merged_options) do |builder| builder.use Faraday::Request::Phoenix if options[:phoenix] builder.use Faraday::Request::MultipartWithFile builder.use Faraday::Request::TwitterOAuth, authentication if authenticated? diff --git a/spec/twitter/api_spec.rb b/spec/twitter/api_spec.rb index 1c561ab16..ca14439e0 100644 --- a/spec/twitter/api_spec.rb +++ b/spec/twitter/api_spec.rb @@ -42,6 +42,7 @@ :search_endpoint => 'http://google.com/', :media_endpoint => 'https://upload.twitter.com/', :user_agent => 'Custom User Agent', + :faraday_options => {:timeout => 10} } end diff --git a/spec/twitter/search_spec.rb b/spec/twitter/search_spec.rb index 82e7b2976..2bda0e051 100644 --- a/spec/twitter/search_spec.rb +++ b/spec/twitter/search_spec.rb @@ -49,6 +49,7 @@ :search_endpoint => 'http://google.com/', :media_endpoint => 'https://upload.twitter.com/', :user_agent => 'Custom User Agent', + :faraday_options => {:timeout => 10} } end