Module: Stocktwits
- Defined in:
- lib/stocktwits.rb,
lib/stocktwits.rb,
lib/stocktwits/cryptify.rb,
lib/stocktwits/dispatcher/basic.rb,
lib/stocktwits/dispatcher/oauth.rb,
lib/stocktwits/dispatcher/plain.rb,
lib/stocktwits/dispatcher/shared.rb,
lib/stocktwits/controller_extensions.rb
Defined Under Namespace
Modules: ControllerExtensions, Cryptify, Dispatcher
Classes: Error
Class Method Summary
collapse
Class Method Details
.api_timeout ⇒ Object
17
18
19
|
# File 'lib/stocktwits.rb', line 17
def self.api_timeout
config['api_timeout'] || 10
end
|
.authorize_path ⇒ Object
85
86
87
|
# File 'lib/stocktwits.rb', line 85
def self.authorize_path
config['authorize_path'] || '/oauth/authorize'
end
|
.base_url ⇒ Object
9
10
11
|
# File 'lib/stocktwits.rb', line 9
def self.base_url
config['base_url'] || 'https://api.stocktwits.com'
end
|
.basic? ⇒ Boolean
52
53
54
|
# File 'lib/stocktwits.rb', line 52
def self.basic?
strategy == :basic
end
|
.config(environment = Rails.env) ⇒ Object
4
5
6
7
|
# File 'lib/stocktwits.rb', line 4
def self.config(environment=Rails.env)
@config ||= {}
@config[environment] ||= YAML.load(File.open(Rails.root.to_s + '/config/stocktwits.yml').read)[environment]
end
|
.consumer ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/stocktwits.rb', line 60
def self.consumer
options = {:site => Stocktwits.base_url}
[ :authorize_path,
:request_token_path,
:access_token_path,
:scheme,
:signature_method ].each do |oauth_option|
options[oauth_option] = Stocktwits.config[oauth_option.to_s] if Stocktwits.config[oauth_option.to_s]
end
OAuth::Consumer.new(
config['oauth_consumer_key'],
config['oauth_consumer_secret'],
options
)
end
|
.encryption_key ⇒ Object
21
22
23
24
25
26
|
# File 'lib/stocktwits.rb', line 21
def self.encryption_key
if strategy != :plain
raise Stocktwits::Cryptify::Error, 'You must specify an encryption_key in config/stocktwits.yml' if config['encryption_key'].blank?
end
config['encryption_key']
end
|
.net ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/stocktwits.rb', line 77
def self.net
uri = URI.parse(Stocktwits.base_url)
net = Net::HTTP.new(uri.host, uri.port)
net.use_ssl = uri.scheme == 'https'
net.read_timeout = Stocktwits.api_timeout
net
end
|
.oauth? ⇒ Boolean
48
49
50
|
# File 'lib/stocktwits.rb', line 48
def self.oauth?
strategy == :oauth
end
|
.oauth_callback ⇒ Object
32
33
34
|
# File 'lib/stocktwits.rb', line 32
def self.oauth_callback
config['oauth_callback']
end
|
.oauth_callback? ⇒ Boolean
28
29
30
|
# File 'lib/stocktwits.rb', line 28
def self.oauth_callback?
config.key?('oauth_callback')
end
|
.path_prefix ⇒ Object
13
14
15
|
# File 'lib/stocktwits.rb', line 13
def self.path_prefix
URI.parse(base_url).path
end
|
.plain? ⇒ Boolean
56
57
58
|
# File 'lib/stocktwits.rb', line 56
def self.plain?
strategy == :plain
end
|
.remember_for ⇒ Object
36
37
38
|
# File 'lib/stocktwits.rb', line 36
def self.remember_for
(config['remember_for'] || 14).to_i
end
|
.strategy ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/stocktwits.rb', line 40
def self.strategy
strat = config['strategy']
raise ArgumentError, 'Invalid StockTwits Strategy: Valid strategies are oauth and basic.' unless %w(oauth basic plain).include?(strat)
strat.to_sym
rescue Errno::ENOENT
:basic
end
|