Module: TwitterAuth

Defined in:
lib/twitter_auth.rb,
lib/twitter_auth.rb,
lib/twitter_auth/cryptify.rb,
lib/twitter_auth/dispatcher/basic.rb,
lib/twitter_auth/dispatcher/oauth.rb,
app/models/twitter_auth/basic_user.rb,
app/models/twitter_auth/oauth_user.rb,
lib/twitter_auth/dispatcher/shared.rb,
app/models/twitter_auth/generic_user.rb,
lib/twitter_auth/controller_extensions.rb

Defined Under Namespace

Modules: BasicUser, ControllerExtensions, Cryptify, Dispatcher, OauthUser Classes: Error, GenericUser

Class Method Summary collapse

Class Method Details

.api_timeoutObject



17
18
19
# File 'lib/twitter_auth.rb', line 17

def self.api_timeout
  config['api_timeout'] || 10
end

.authorize_pathObject



83
84
85
# File 'lib/twitter_auth.rb', line 83

def self.authorize_path
  config['authorize_path'] || '/oauth/authorize'
end

.base_urlObject



9
10
11
# File 'lib/twitter_auth.rb', line 9

def self.base_url
  config['base_url'] || 'https://twitter.com'    
end

.basic?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/twitter_auth.rb', line 53

def self.basic?
  strategy == :basic
end

.config(environment = RAILS_ENV) ⇒ Object



4
5
6
7
# File 'lib/twitter_auth.rb', line 4

def self.config(environment=RAILS_ENV)
  @config ||= {}
  @config[environment] ||= YAML.load(File.open(RAILS_ROOT + '/config/twitter_auth.yml').read)[environment]
end

.consumerObject

The OAuth consumer used by TwitterAuth for authentication. The consumer key and secret are set in your application’s config/twitter.yml



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/twitter_auth.rb', line 58

def self.consumer
  options = {:site => TwitterAuth.base_url}
  [ :authorize_path, 
    :request_token_path,
    :access_token_path,
    :scheme,
    :signature_method ].each do |oauth_option|
    options[oauth_option] = TwitterAuth.config[oauth_option.to_s] if TwitterAuth.config[oauth_option.to_s]
  end

  OAuth::Consumer.new(
    config['oauth_consumer_key'],          
    config['oauth_consumer_secret'],
    options 
  )
end

.encryption_keyObject



21
22
23
24
# File 'lib/twitter_auth.rb', line 21

def self.encryption_key
  raise TwitterAuth::Cryptify::Error, 'You must specify an encryption_key in config/twitter_auth.yml' if config['encryption_key'].blank?
  config['encryption_key'] 
end

.netObject



75
76
77
78
79
80
81
# File 'lib/twitter_auth.rb', line 75

def self.net
  uri = URI.parse(TwitterAuth.base_url)
  net = Net::HTTP.new(uri.host, uri.port)
  net.use_ssl = uri.scheme == 'https'
  net.read_timeout = TwitterAuth.api_timeout
  net
end

.oauth?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/twitter_auth.rb', line 49

def self.oauth?
  strategy == :oauth
end

.oauth_callbackObject



30
31
32
# File 'lib/twitter_auth.rb', line 30

def self.oauth_callback
  config['oauth_callback']
end

.oauth_callback?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/twitter_auth.rb', line 26

def self.oauth_callback?
  config.key?('oauth_callback')
end

.path_prefixObject



13
14
15
# File 'lib/twitter_auth.rb', line 13

def self.path_prefix
  URI.parse(base_url).path
end

.remember_forObject



34
35
36
# File 'lib/twitter_auth.rb', line 34

def self.remember_for
  (config['remember_for'] || 14).to_i
end

.strategyObject

The authentication strategy employed by this application. Set in config/twitter.yml as strategy; valid options are oauth or basic.



41
42
43
44
45
46
47
# File 'lib/twitter_auth.rb', line 41

def self.strategy
  strat = config['strategy']
  raise ArgumentError, 'Invalid TwitterAuth Strategy: Valid strategies are oauth and basic.' unless %w(oauth basic).include?(strat)
  strat.to_sym
rescue Errno::ENOENT
  :oauth
end