Module: Twitter::Default

Defined in:
lib/twitter/default.rb

Constant Summary collapse

ENDPOINT =
'https://api.twitter.com'
CONNECTION_OPTIONS =
{
  :headers => {
    :accept => 'application/json',
    :user_agent => "Twitter Ruby Gem #{Twitter::Version}"
  },
  :open_timeout => 5,
  :raw => true,
  :ssl => {:verify => false},
  :timeout => 10,
}
IDENTITY_MAP =
false
MIDDLEWARE =
Faraday::Builder.new(
  &Proc.new do |builder|
    # Convert file uploads to Faraday::UploadIO objects
    builder.use Twitter::Request::MultipartWithFile
    # Checks for files in the payload
    builder.use Faraday::Request::Multipart
    # Convert request params to "www-form-urlencoded"
    builder.use Faraday::Request::UrlEncoded
    # Handle 4xx server responses
    builder.use Twitter::Response::RaiseError, Twitter::Error::ClientError
    # Parse JSON response bodies using MultiJson
    builder.use Twitter::Response::ParseJson
    # Handle 5xx server responses
    builder.use Twitter::Response::RaiseError, Twitter::Error::ServerError
    # Set Faraday's HTTP adapter
    builder.adapter Faraday.default_adapter
  end
)

Class Method Summary collapse

Class Method Details

.connection_optionsHash

Returns:



82
83
84
# File 'lib/twitter/default.rb', line 82

def connection_options
  CONNECTION_OPTIONS
end

.consumer_keyString

Returns:



52
53
54
# File 'lib/twitter/default.rb', line 52

def consumer_key
  ENV['TWITTER_CONSUMER_KEY']
end

.consumer_secretString

Returns:



57
58
59
# File 'lib/twitter/default.rb', line 57

def consumer_secret
  ENV['TWITTER_CONSUMER_SECRET']
end

.endpointString

Note:

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



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

def endpoint
  ENDPOINT
end

.identity_mapTwitter::IdentityMap



87
88
89
# File 'lib/twitter/default.rb', line 87

def identity_map
  IDENTITY_MAP
end

.middlewareFaraday::Builder

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.



95
96
97
# File 'lib/twitter/default.rb', line 95

def middleware
  MIDDLEWARE
end

.oauth_tokenString

Returns:



62
63
64
# File 'lib/twitter/default.rb', line 62

def oauth_token
  ENV['TWITTER_OAUTH_TOKEN']
end

.oauth_token_secretString

Returns:



67
68
69
# File 'lib/twitter/default.rb', line 67

def oauth_token_secret
  ENV['TWITTER_OAUTH_TOKEN_SECRET']
end

.optionsHash

Returns:



47
48
49
# File 'lib/twitter/default.rb', line 47

def options
  Hash[Twitter::Configurable.keys.map{|key| [key, send(key)]}]
end