Module: Oauth::Models::Consumers::Token::ClassMethods

Defined in:
lib/oauth/models/consumers/token.rb

Instance Method Summary collapse

Instance Method Details

#build_user_from_tokenObject



56
57
# File 'lib/oauth/models/consumers/token.rb', line 56

def build_user_from_token
end

#consumerObject



24
25
26
27
# File 'lib/oauth/models/consumers/token.rb', line 24

def consumer
  options = credentials[:options] || {}
  @consumer||=OAuth::Consumer.new credentials[:key],credentials[:secret],options
end

#credentialsObject



59
60
61
# File 'lib/oauth/models/consumers/token.rb', line 59

def credentials
  @credentials||=OAUTH_CREDENTIALS[service_name]
end

#find_or_create_from_access_token(user, access_token) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/oauth/models/consumers/token.rb', line 41

def find_or_create_from_access_token(user,access_token)
  secret = access_token.respond_to?(:secret) ? access_token.secret : nil
  if user
    token = self.find_or_initialize_by_user_id_and_token(user.id, access_token.token)
  else
    token = self.find_or_initialize_by_token(access_token.token)
  end

  # set or update the secret
  token.secret = secret
  token.save! if token.new_record? or token.changed?

  token
end

#find_or_create_from_request_token(user, token, secret, oauth_verifier) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/oauth/models/consumers/token.rb', line 33

def find_or_create_from_request_token(user,token,secret,oauth_verifier)
  request_token=OAuth::RequestToken.new consumer,token,secret
  options={}
  options[:oauth_verifier]=oauth_verifier if oauth_verifier
  access_token=request_token.get_access_token options
  find_or_create_from_access_token user, access_token
end

#get_request_token(callback_url) ⇒ Object



29
30
31
# File 'lib/oauth/models/consumers/token.rb', line 29

def get_request_token(callback_url)
  consumer.get_request_token(:oauth_callback=>callback_url)
end

#service_nameObject



20
21
22
# File 'lib/oauth/models/consumers/token.rb', line 20

def service_name
  @service_name||=self.to_s.underscore.scan(/^(.*?)(_token)?$/)[0][0].to_sym
end