Class: Pft::Oauth
- Inherits:
-
Object
- Object
- Pft::Oauth
- Defined in:
- lib/pft/oauth.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#secret ⇒ Object
Returns the value of attribute secret.
Instance Method Summary collapse
- #authorize ⇒ Object
- #client ⇒ Object
-
#initialize(*args) ⇒ Oauth
constructor
A new instance of Oauth.
Constructor Details
#initialize(*args) ⇒ Oauth
Returns a new instance of Oauth.
5 6 7 8 |
# File 'lib/pft/oauth.rb', line 5 def initialize(*args) @key = "Imv819Ww77451xPcQ4Jxaw" @secret = "MIcYaAqL62S2L3nLSasSu4YjMo1Mydeh46ItULi5Tc" end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
3 4 5 |
# File 'lib/pft/oauth.rb', line 3 def key @key end |
#secret ⇒ Object
Returns the value of attribute secret.
3 4 5 |
# File 'lib/pft/oauth.rb', line 3 def secret @secret end |
Instance Method Details
#authorize ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pft/oauth.rb', line 23 def puts "We are going to launch the brower, do you want to continue? [Y/n]" = Base.input.gets.chomp raise "Cannot authorize the account" if .downcase == "n" consumer = OAuth::Consumer.new(@key, @secret, {:site => 'http://twitter.com'}) request_token = consumer.get_request_token url = request_token. if RUBY_PLATFORM =~ /darwin/ system "open #{url}" elsif !system("firefox #{url}") puts "Please point your browser to: \n\n#{url}\n\n" end puts "Please enter the provided PIN:" pin = Base.input.gets.chomp access_token = request_token.get_access_token(:oauth_verifier => pin) rescue false if access_token Base.[:token] = access_token.token Base.[:secret] = access_token.secret Base. puts "Great we're done! You can now ridicolous tweet from pft!@" else raise "The PIN provided is incorrect" end end |
#client ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pft/oauth.rb', line 10 def client @client ||= begin client_token = Base.[:token] client_secret = Base.[:secret] if !client_secret || !client_token raise "Please run it with -a" end oauth = Twitter::OAuth.new(@key, @secret) oauth.(client_token, client_secret) Twitter::Base.new(oauth) end end |