Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass raw options to faraday #189

Merged
merged 1 commit into from
Sep 15, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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