Class: OauthToken

Inherits:
Token
  • Object
show all
Defined in:
lib/authlogic_connect/oauth/tokens/oauth_token.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Token

client, service_name, #service_name

Class Method Details

.consumerObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/authlogic_connect/oauth/tokens/oauth_token.rb', line 42

def consumer
  unless @consumer
    if oauth_version == 1.0
      @consumer = OAuth::Consumer.new(credentials[:key], credentials[:secret], settings.merge(credentials[:options] || {}))
    else
      @consumer = OAuth2::Client.new(credentials[:key], credentials[:secret], settings)
    end
  end
  
  @consumer
end

.get_access_token(oauth_verifier) ⇒ Object



62
63
64
# File 'lib/authlogic_connect/oauth/tokens/oauth_token.rb', line 62

def get_access_token(oauth_verifier)
  request_token.get_access_token(:oauth_verifier => oauth_verifier)
end

.get_request_token(callback_url) ⇒ Object



58
59
60
# File 'lib/authlogic_connect/oauth/tokens/oauth_token.rb', line 58

def get_request_token(callback_url)
  consumer.get_request_token({:oauth_callback => callback_url}, settings)
end

.oauth_versionObject



34
35
36
# File 'lib/authlogic_connect/oauth/tokens/oauth_token.rb', line 34

def oauth_version
  1.0
end

.request_token(token, secret) ⇒ Object



54
55
56
# File 'lib/authlogic_connect/oauth/tokens/oauth_token.rb', line 54

def request_token(token, secret)
  OAuth::RequestToken.new(consumer, token, secret)
end

.settingsObject



38
39
40
# File 'lib/authlogic_connect/oauth/tokens/oauth_token.rb', line 38

def settings
  @settings ||= {}
end

Instance Method Details

#clientObject

Main client for interfacing with remote service. Override this to use preexisting library eg. Twitter gem.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/authlogic_connect/oauth/tokens/oauth_token.rb', line 4

def client
  unless @client
    if oauth_version == 1.0
      @client = OAuth::AccessToken.new(self.consumer, self.key, self.secret)
    else
      @client = OAuth2::AccessToken.new(self.consumer, self.key)
    end
  end
  
  @client
end

#consumerObject



16
17
18
# File 'lib/authlogic_connect/oauth/tokens/oauth_token.rb', line 16

def consumer
  self.class.consumer
end

#get(path, options = {}) ⇒ Object



28
29
30
# File 'lib/authlogic_connect/oauth/tokens/oauth_token.rb', line 28

def get(path, options = {})
  client.get(path)
end

#oauth_versionObject



24
25
26
# File 'lib/authlogic_connect/oauth/tokens/oauth_token.rb', line 24

def oauth_version
  self.class.oauth_version
end

#simple_clientObject



20
21
22
# File 'lib/authlogic_connect/oauth/tokens/oauth_token.rb', line 20

def simple_client
  @simple_client ||= SimpleClient.new(OAuth::AccessToken.new(self.class.consumer, token, secret))
end