From ceeed993b16f95582c648e93de03738362ba1d7b Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Sun, 16 Jan 2011 15:05:13 -0800 Subject: [PATCH] Don't set cached screen_name when creating a new API client Closes #136. --- lib/twitter/client/utils.rb | 2 +- lib/twitter/configuration.rb | 56 ++++++++++++++++++++---------------- spec/twitter/api_spec.rb | 1 - spec/twitter/search_spec.rb | 1 - 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/lib/twitter/client/utils.rb b/lib/twitter/client/utils.rb index 5fa066189..72c4bd817 100644 --- a/lib/twitter/client/utils.rb +++ b/lib/twitter/client/utils.rb @@ -9,7 +9,7 @@ module Utils # # @return [String] def get_screen_name - Twitter.screen_name ||= self.verify_credentials.screen_name + @screen_name ||= self.verify_credentials.screen_name end # Remove @ signs from screen names diff --git a/lib/twitter/configuration.rb b/lib/twitter/configuration.rb index 0bdb5c0a5..727aa5c98 100644 --- a/lib/twitter/configuration.rb +++ b/lib/twitter/configuration.rb @@ -5,30 +5,34 @@ module Twitter # Defines constants and methods related to configuration module Configuration # An array of valid keys in the options hash when configuring a {Twitter::API} - VALID_OPTIONS_KEYS = [:consumer_key, :consumer_secret, :oauth_token, :oauth_token_secret, :adapter, :endpoint, :format, :proxy, :search_endpoint, :user_agent, :screen_name].freeze + VALID_OPTIONS_KEYS = [ + :adapter, + :consumer_key, + :consumer_secret, + :endpoint, + :format, + :oauth_token, + :oauth_token_secret, + :proxy, + :search_endpoint, + :user_agent].freeze # An array of valid request/response formats # # @note Not all methods support the XML format. VALID_FORMATS = [:json, :xml].freeze + # The adapter that will be used to connect if none is set + # + # @note The default faraday adapter is Net::HTTP. + DEFAULT_ADAPTER = Faraday.default_adapter.freeze + # By default, don't set an application key DEFAULT_CONSUMER_KEY = nil.freeze # By default, don't set an application secret DEFAULT_CONSUMER_SECRET = nil.freeze - # By default, don't set a user oauth token - DEFAULT_OAUTH_TOKEN = nil.freeze - - # By default, don't set a user oauth secret - DEFAULT_OAUTH_TOKEN_SECRET = nil.freeze - - # The faraday adapter that will be used to connect if none is set - # - # @note The default faraday adapter is Net::HTTP. - DEFAULT_ADAPTER = Faraday.default_adapter.freeze - # The endpoint that will be used to connect if none is set # # @note This is configurable in case you want to use HTTP instead of HTTPS, specify a different API version, or use a Twitter-compatible endpoint. @@ -38,26 +42,29 @@ module Configuration # @see http://developer.typepad.com/typepad-twitter-api/twitter-api.html DEFAULT_ENDPOINT = 'https://api.twitter.com/1/'.freeze - # The search endpoint that will be used to connect if none is set - # - # @note This is configurable in case you want to use HTTP instead of HTTPS or use a Twitter-compatible endpoint. - # @see http://status.net/wiki/Twitter-compatible_API - DEFAULT_SEARCH_ENDPOINT = 'https://search.twitter.com/'.freeze - # The response format appended to the path and sent in the 'Accept' header if none is set # # @note JSON is preferred over XML because it is more concise and faster to parse. DEFAULT_FORMAT = :json.freeze + # By default, don't set a user oauth token + DEFAULT_OAUTH_TOKEN = nil.freeze + + # By default, don't set a user oauth secret + DEFAULT_OAUTH_TOKEN_SECRET = nil.freeze + # By default, don't use a proxy server DEFAULT_PROXY = nil.freeze + # The search endpoint that will be used to connect if none is set + # + # @note This is configurable in case you want to use HTTP instead of HTTPS or use a Twitter-compatible endpoint. + # @see http://status.net/wiki/Twitter-compatible_API + DEFAULT_SEARCH_ENDPOINT = 'https://search.twitter.com/'.freeze + # The user agent that will be sent to the API endpoint if none is set DEFAULT_USER_AGENT = "Twitter Ruby Gem #{Twitter::VERSION}".freeze - # By default, don't set a screen name - DEFAULT_SCREEN_NAME = nil.freeze - # @private attr_accessor *VALID_OPTIONS_KEYS @@ -80,17 +87,16 @@ def options # Reset all configuration options to defaults def reset + self.adapter = DEFAULT_ADAPTER self.consumer_key = DEFAULT_CONSUMER_KEY self.consumer_secret = DEFAULT_CONSUMER_SECRET - self.oauth_token = DEFAULT_OAUTH_TOKEN - self.oauth_token_secret = DEFAULT_OAUTH_TOKEN_SECRET - self.adapter = DEFAULT_ADAPTER self.endpoint = DEFAULT_ENDPOINT self.format = DEFAULT_FORMAT + self.oauth_token = DEFAULT_OAUTH_TOKEN + self.oauth_token_secret = DEFAULT_OAUTH_TOKEN_SECRET self.proxy = DEFAULT_PROXY self.search_endpoint = DEFAULT_SEARCH_ENDPOINT self.user_agent = DEFAULT_USER_AGENT - self.screen_name = DEFAULT_SCREEN_NAME self end end diff --git a/spec/twitter/api_spec.rb b/spec/twitter/api_spec.rb index d7266905c..2cc2123e6 100644 --- a/spec/twitter/api_spec.rb +++ b/spec/twitter/api_spec.rb @@ -40,7 +40,6 @@ :proxy => 'http://erik:sekret@proxy.example.com:8080', :search_endpoint => 'http://google.com/', :user_agent => 'Custom User Agent', - :screen_name => nil } end diff --git a/spec/twitter/search_spec.rb b/spec/twitter/search_spec.rb index 1ffb7aab4..3d2802c6f 100644 --- a/spec/twitter/search_spec.rb +++ b/spec/twitter/search_spec.rb @@ -45,7 +45,6 @@ :proxy => 'http://erik:sekret@proxy.example.com:8080', :search_endpoint => 'http://google.com/', :user_agent => 'Custom User Agent', - :screen_name => nil } end