Skip to content

Commit

Permalink
option for passing options directly to faraday
Browse files Browse the repository at this point in the history
  • Loading branch information
icambron committed Sep 14, 2011
1 parent 22a7f38 commit 4cc4697
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/twitter/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/twitter/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ module Connection
private

def connection(options={})
Faraday.new(
merged_options = faraday_options.merge({
:headers => {
'Accept' => "application/#{format}",
'User-Agent' => user_agent
},
: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?
Expand Down
1 change: 1 addition & 0 deletions spec/twitter/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions spec/twitter/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4cc4697

Please sign in to comment.