/
twitter_auth.rb
73 lines (60 loc) · 1.93 KB
/
twitter_auth.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
module TwitterAuth
class Error < StandardError; end
def self.config(environment=RAILS_ENV)
@config ||= {}
@config[environment] ||= YAML.load(File.open(RAILS_ROOT + '/config/twitter_auth.yml').read)[environment]
end
def self.base_url
config['base_url'] || 'https://twitter.com'
end
def self.api_timeout
config['api_timeout'] || 10
end
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
def self.oauth_callback?
config.key?('oauth_callback')
end
def self.oauth_callback
config['oauth_callback']
end
# The authentication strategy employed by this
# application. Set in +config/twitter.yml+ as
# strategy; valid options are oauth or basic.
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
def self.oauth?
strategy == :oauth
end
def self.basic?
strategy == :basic
end
# The OAuth consumer used by TwitterAuth for authentication. The consumer key and secret are set in your application's +config/twitter.yml+
def self.consumer
OAuth::Consumer.new(
config['oauth_consumer_key'],
config['oauth_consumer_secret'],
:site => TwitterAuth.base_url
)
end
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
end
require 'twitter_auth/controller_extensions'
require 'twitter_auth/cryptify'
require 'twitter_auth/dispatcher/oauth'
require 'twitter_auth/dispatcher/basic'
require 'twitter_auth/dispatcher/shared'
class TwitterAuth::Dispatcher::Error < StandardError; end