Class: Flagit::TwitterOAuth
- Inherits:
-
Object
- Object
- Flagit::TwitterOAuth
- Defined in:
- lib/flagit/twitter_oauth.rb
Instance Method Summary collapse
- #authentication_request_token(options = {}) ⇒ Object
- #authorize(token, secret, options = {}) ⇒ Object
- #authorized? ⇒ Boolean
-
#initialize ⇒ TwitterOAuth
constructor
A new instance of TwitterOAuth.
- #request_token(options = {}) ⇒ Object
- #run_auth_process ⇒ Object
Constructor Details
#initialize ⇒ TwitterOAuth
Returns a new instance of TwitterOAuth.
6 7 8 9 10 11 12 13 |
# File 'lib/flagit/twitter_oauth.rb', line 6 def initialize @consumer_key = Flagit.configuration.consumer_key @consumer_secret = Flagit.configuration.consumer_secret @token = Flagit.configuration.access_token @secret = Flagit.configuration.access_token_secret @api_version = '1.1' @api_host = 'api.twitter.com' end |
Instance Method Details
#authentication_request_token(options = {}) ⇒ Object
45 46 47 48 |
# File 'lib/flagit/twitter_oauth.rb', line 45 def authentication_request_token(={}) consumer.[:authorize_path] = '/oauth/authenticate' request_token() end |
#authorize(token, secret, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/flagit/twitter_oauth.rb', line 30 def (token, secret, = {}) request_token = OAuth::RequestToken.new( consumer, token, secret ) @access_token = request_token.get_access_token() @token = @access_token.token @secret = @access_token.secret Flagit.configure do |config| config.access_token = @token config.access_token_secret = @secret end Flagit.save! @access_token end |
#authorized? ⇒ Boolean
54 55 56 57 |
# File 'lib/flagit/twitter_oauth.rb', line 54 def oauth_response = access_token.get("/#{@api_version}/account/verify_credentials.json") return oauth_response.class == Net::HTTPOK end |
#request_token(options = {}) ⇒ Object
50 51 52 |
# File 'lib/flagit/twitter_oauth.rb', line 50 def request_token(={}) consumer.get_request_token() end |
#run_auth_process ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/flagit/twitter_oauth.rb', line 15 def run_auth_process get_consumer_info if (@consumer_key.nil? || @consumer_secret.nil?) return true if request_token = authentication_request_token(oauth_callback: 'oob') open_using_browser request_token. puts 'Enter the supplied PIN:' pin = STDIN.gets.chomp access_token = ( request_token.token, request_token.secret, oauth_verifier: pin ) puts "#{ ? 'Authorization successful.' : 'Authorization failed.'}" end |