Skip to content

Commit

Permalink
Merge pull request sferik#189 from icambron/master
Browse files Browse the repository at this point in the history
pass raw options to faraday
  • Loading branch information
sferik committed Sep 15, 2011
2 parents 22a7f38 + 4cc4697 commit 66c8e19
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
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
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
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
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 66c8e19

Please sign in to comment.