Module: Twitter::Config

Included in:
Twitter
Defined in:
lib/twitter/config.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

DEFAULT_ADAPTER =

The HTTP connection adapter that will be used to connect if none is set

:net_http
DEFAULT_CONNECTION_OPTIONS =

The Faraday connection options if none is set

{}
DEFAULT_CONSUMER_KEY =

The consumer key if none is set

nil
DEFAULT_CONSUMER_SECRET =

The consumer secret if none is set

nil
DEFAULT_ENDPOINT =
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.

The endpoint that will be used to connect if none is set

'https://api.twitter.com'
DEFAULT_GATEWAY =

The gateway server if none is set

nil
DEFAULT_MEDIA_ENDPOINT =

This endpoint will be used by default when updating statuses with media

'https://upload.twitter.com'
DEFAULT_OAUTH_TOKEN =

The oauth token if none is set

nil
DEFAULT_OAUTH_TOKEN_SECRET =

The oauth token secret if none is set

nil
DEFAULT_PROXY =

The proxy server if none is set

nil
DEFAULT_SEARCH_ENDPOINT =
Note:

This is configurable in case you want to use HTTP instead of HTTPS or use a Twitter-compatible endpoint.

The search endpoint that will be used to connect if none is set

'https://search.twitter.com'
DEFAULT_USER_AGENT =

The value sent in the 'User-Agent' header if none is set

"Twitter Ruby Gem #{Twitter::Version}"
VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring a Twitter::Client

[
  :adapter,
  :connection_options,
  :consumer_key,
  :consumer_secret,
  :endpoint,
  :gateway,
  :oauth_token,
  :oauth_token_secret,
  :proxy,
  :search_endpoint,
  :user_agent,
  :media_endpoint
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

When this module is extended, set all configuration options to their default values



71
72
73
# File 'lib/twitter/config.rb', line 71

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:



76
77
78
79
# File 'lib/twitter/config.rb', line 76

def configure
  yield self
  self
end

#optionsObject

Create a hash of options and their values



82
83
84
85
86
# File 'lib/twitter/config.rb', line 82

def options
  options = {}
  VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
  options
end

#resetObject

Reset all configuration options to defaults



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/twitter/config.rb', line 89

def reset
  self.adapter            = DEFAULT_ADAPTER
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
  self.consumer_key       = DEFAULT_CONSUMER_KEY
  self.consumer_secret    = DEFAULT_CONSUMER_SECRET
  self.endpoint           = DEFAULT_ENDPOINT
  self.gateway            = DEFAULT_GATEWAY
  self.media_endpoint     = DEFAULT_MEDIA_ENDPOINT
  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
end