Module: SimpleTwitterOAuth

Defined in:
lib/simple_twitter_oauth.rb,
lib/simple_twitter_oauth/version.rb,
lib/simple_twitter_oauth/access_token.rb,
lib/simple_twitter_oauth/request_token.rb

Defined Under Namespace

Classes: AccessToken, RequestToken

Constant Summary collapse

SITE =
'https://twitter.com'
VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.get_access_token(consumer_key:, consumer_secret:, token:, token_secret:, oauth_verifier:) ⇒ SimpleTwitterOAuth::AccessToken?

This method is used after the user has authenticated with Twitter.


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/simple_twitter_oauth.rb', line 35

def self.get_access_token(consumer_key:, consumer_secret:, token:, token_secret:, oauth_verifier:)
  consumer = OAuth::Consumer.new(consumer_key, consumer_secret, site: SITE)
  request_token = OAuth::RequestToken.from_hash(consumer,
    oauth_token: token,
    oauth_token_secret: token_secret,
  )

  begin
    access_token = request_token.get_access_token(oauth_verifier: oauth_verifier)

    AccessToken.new(
      screen_name: access_token.params[:screen_name],
      token: access_token.token,
      secret: access_token.secret,
    )
  rescue OAuth::Unauthorized
  end
end

.get_request_token(consumer_key:, consumer_secret:, callback_url:) ⇒ SimpleTwitterOAuth::RequestToken

This method is used to before sending the user to Twitter for authentication.


16
17
18
19
20
21
22
23
24
25
# File 'lib/simple_twitter_oauth.rb', line 16

def self.get_request_token(consumer_key:, consumer_secret:, callback_url:)
  consumer = OAuth::Consumer.new(consumer_key, consumer_secret, site: SITE)
  request_token = consumer.get_request_token(oauth_callback: callback_url)

  RequestToken.new(
    token: request_token.token,
    secret: request_token.secret,
    authorize_url: request_token.authorize_url(oauth_callback: callback_url),
  )
end