Module: TweetStream::Configuration

Included in:
TweetStream
Defined in:
lib/tweetstream/configuration.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring TweetStream.

[
:parser,
:username,
:password,
:user_agent,
:auth_method,
:proxy,
:consumer_key,
:consumer_secret,
:oauth_token,
:oauth_token_secret].freeze
OAUTH_OPTIONS_KEYS =
[
:consumer_key,
:consumer_secret,
:oauth_token,
:oauth_token_secret].freeze
DEFAULT_USERNAME =

By default, don't set a username

nil
DEFAULT_PASSWORD =

By default, don't set a password

nil
DEFAULT_USER_AGENT =

The user agent that will be sent to the API endpoint if none is set

"TweetStream Ruby Gem #{TweetStream::VERSION}".freeze
DEFAULT_AUTH_METHOD =

The default authentication method

:oauth
DEFAULT_PROXY =
nil
VALID_FORMATS =
[
:basic,
:oauth].freeze
DEFAULT_CONSUMER_KEY =

By default, don't set an application key

nil
DEFAULT_CONSUMER_SECRET =

By default, don't set an application secret

nil
DEFAULT_OAUTH_TOKEN =

By default, don't set a user oauth token

nil
DEFAULT_OAUTH_TOKEN_SECRET =

By default, don't set a user oauth secret

nil

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



59
60
61
# File 'lib/tweetstream/configuration.rb', line 59

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:



64
65
66
# File 'lib/tweetstream/configuration.rb', line 64

def configure
  yield self
end

#oauth_optionsObject

Create a hash of options and their values



74
75
76
# File 'lib/tweetstream/configuration.rb', line 74

def oauth_options
  Hash[*OAUTH_OPTIONS_KEYS.collect { |key| [key, send(key)] }.flatten]
end

#optionsObject

Create a hash of options and their values



69
70
71
# File 'lib/tweetstream/configuration.rb', line 69

def options
  Hash[*VALID_OPTIONS_KEYS.collect { |key| [key, send(key)] }.flatten]
end

#resetObject

Reset all configuration options to defaults



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/tweetstream/configuration.rb', line 79

def reset
  self.username           = DEFAULT_USERNAME
  self.password           = DEFAULT_PASSWORD
  self.user_agent         = DEFAULT_USER_AGENT
  self.auth_method        = DEFAULT_AUTH_METHOD
  self.proxy              = DEFAULT_PROXY
  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
end