Class: Rlyeh::DeepOnes::Auth::OAuth

Inherits:
Base
  • Object
show all
Defined in:
lib/rlyeh/deep_ones/auth/oauth.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#host, #nick, #pass, #real, #user

Instance Method Summary collapse

Methods inherited from Base

#authenticated?, #call, #failed, #session_id, #succeeded, #welcome

Methods included from Logger

crash, format_exception

Methods included from Rlyeh::Dispatcher

#dispatch, included, #trigger

Constructor Details

#initialize(app, consumer_key, consumer_secret, client_options = {}) ⇒ OAuth

Returns a new instance of OAuth.



12
13
14
15
16
17
18
19
20
21
# File 'lib/rlyeh/deep_ones/auth/oauth.rb', line 12

def initialize(app, consumer_key, consumer_secret, client_options = {})
  @consumer_key = consumer_key
  @consumer_secret = consumer_secret
  @client_options = client_options
  @open_timeout = nil
  @read_timeout = nil
  @authorize_params = {}
  @request_params = {}
  super app
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



10
11
12
# File 'lib/rlyeh/deep_ones/auth/oauth.rb', line 10

def access_token
  @access_token
end

#authorize_paramsObject

Returns the value of attribute authorize_params.



9
10
11
# File 'lib/rlyeh/deep_ones/auth/oauth.rb', line 9

def authorize_params
  @authorize_params
end

#client_optionsObject

Returns the value of attribute client_options.



7
8
9
# File 'lib/rlyeh/deep_ones/auth/oauth.rb', line 7

def client_options
  @client_options
end

#consumer_keyObject

Returns the value of attribute consumer_key.



7
8
9
# File 'lib/rlyeh/deep_ones/auth/oauth.rb', line 7

def consumer_key
  @consumer_key
end

#consumer_secretObject

Returns the value of attribute consumer_secret.



7
8
9
# File 'lib/rlyeh/deep_ones/auth/oauth.rb', line 7

def consumer_secret
  @consumer_secret
end

#open_timeoutObject

Returns the value of attribute open_timeout.



8
9
10
# File 'lib/rlyeh/deep_ones/auth/oauth.rb', line 8

def open_timeout
  @open_timeout
end

#read_timeoutObject

Returns the value of attribute read_timeout.



8
9
10
# File 'lib/rlyeh/deep_ones/auth/oauth.rb', line 8

def read_timeout
  @read_timeout
end

#request_paramsObject

Returns the value of attribute request_params.



9
10
11
# File 'lib/rlyeh/deep_ones/auth/oauth.rb', line 9

def request_params
  @request_params
end

Instance Method Details

#consumerObject



23
24
25
26
27
28
# File 'lib/rlyeh/deep_ones/auth/oauth.rb', line 23

def consumer
  consumer = ::OAuth::Consumer.new @consumer_key, @consumer_secret, @client_options
  consumer.http.open_timeout = @open_timeout if @open_timeout
  consumer.http.read_timeout = @read_timeout if @read_timeout
  consumer
end

#request_phase(env) ⇒ Object



35
36
37
38
39
40
# File 'lib/rlyeh/deep_ones/auth/oauth.rb', line 35

def request_phase(env)
  request_token = consumer.get_request_token @request_params

  talk env, 'Access this URL get the PIN and paste it here.'
  talk env, request_token.authorize_url(@authorize_params)
end

#try(env) ⇒ Object



30
31
32
33
# File 'lib/rlyeh/deep_ones/auth/oauth.rb', line 30

def try(env)
  welcome env
  request_phase env
end