Skip to content

Commit

Permalink
Deprecate Twitter::REST::Client#middleware= and #connection_options
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Mar 19, 2014
1 parent f1d5d1f commit 2ec17d8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ParameterLists:
CountKeywordArgs: true

ClassLength:
Max: 85
Max: 90

LineLength:
Enabled: false
Expand Down
16 changes: 15 additions & 1 deletion lib/twitter/rest/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ module REST
class Client < Twitter::Client
include Twitter::REST::API
attr_accessor :bearer_token
attr_writer :connection_options, :middleware
ENDPOINT = 'https://api.twitter.com'

# @param connection_options [Hash]
# @return [Hash]
def connection_options=(connection_options)
warn "#{Kernel.caller.first}: [DEPRECATION] Twitter::REST::Client#connection_options= is deprecated and will be removed in version 6.0.0."
@connection_options = connection_options
end

# @return [Hash]
def connection_options
@connection_options ||= {
:builder => middleware,
Expand All @@ -36,6 +43,13 @@ def connection_options
}
end

# @params middleware [Faraday::RackBuilder]
# @return [Faraday::RackBuilder]
def middleware=(middleware)
warn "#{Kernel.caller.first}: [DEPRECATION] Twitter::REST::Client#middleware= is deprecated and will be removed in version 6.0.0."
@middleware = middleware
end

# @note Faraday's middleware stack implementation is comparable to that of Rack middleware. The order of middleware is important: the first middleware on the list wraps all others, while the last middleware is the innermost one.
# @see https://github.com/technoweenie/faraday#advanced-middleware-usage
# @see http://mislav.uniqpath.com/2011/07/faraday-advanced-http/
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class User < Twitter::BasicUser
alias_method :tweeted?, :status?

class << self

private

# Dynamically define a method for entity URIs
Expand Down
12 changes: 12 additions & 0 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@ def fixture_path
def fixture(file)
File.new(fixture_path + '/' + file)
end

def capture_warning
begin
old_stderr = $stderr
$stderr = StringIO.new
yield
result = $stderr.string
ensure
$stderr = old_stderr
end
result
end
30 changes: 30 additions & 0 deletions spec/twitter/rest/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,36 @@
end
end

describe '#connection_options=' do
it 'sets connection options' do
capture_warning do
@client.connection_options = 'connection options'
end
expect(@client.connection_options).to eq('connection options')
end
it 'outputs a warning' do
warning = capture_warning do
@client.connection_options = nil
end
expect(warning).to match(/\[DEPRECATION\] Twitter::REST::Client#connection_options= is deprecated and will be removed in version 6\.0\.0\.$/)
end
end

describe '#middleware=' do
it 'sets middleware' do
capture_warning do
@client.middleware = 'middleware'
end
expect(@client.middleware).to eq 'middleware'
end
it 'outputs a warning' do
warning = capture_warning do
@client.middleware = nil
end
expect(warning).to match(/\[DEPRECATION\] Twitter::REST::Client#middleware= is deprecated and will be removed in version 6\.0\.0\.$/)
end
end

describe '#credentials?' do
it 'returns true if all credentials are present' do
client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS')
Expand Down

0 comments on commit 2ec17d8

Please sign in to comment.