Module: OAuth::CLI::Twitter
Constant Summary collapse
- CONSUMER_TOKEN =
'UWhf189fDdtCZz6rq8Q5gA'
- CONSUMER_SECRET =
'QQHee9yFJqWeztLvGRj5A552gCGIJ7N0yLtpsJPZeU'
Instance Attribute Summary collapse
-
#extender ⇒ Object
Returns the value of attribute extender.
-
#includer ⇒ Object
Returns the value of attribute includer.
Class Method Summary collapse
Instance Method Summary collapse
- #authorize ⇒ Object
- #consumer ⇒ Object
- #execute ⇒ Object
- #get_access_token(*args) ⇒ Object
- #load_config ⇒ Object
- #prompt_pin ⇒ Object
- #request_token ⇒ Object
- #save_config(access_token) ⇒ Object
Instance Attribute Details
#extender ⇒ Object
Returns the value of attribute extender.
24 25 26 |
# File 'lib/oauth/cli/twitter.rb', line 24 def extender @extender end |
#includer ⇒ Object
Returns the value of attribute includer.
24 25 26 |
# File 'lib/oauth/cli/twitter.rb', line 24 def includer @includer end |
Class Method Details
.extended(extender) ⇒ Object
20 21 22 |
# File 'lib/oauth/cli/twitter.rb', line 20 def self.extended(extender) @extender = extender end |
.included(includer) ⇒ Object
16 17 18 |
# File 'lib/oauth/cli/twitter.rb', line 16 def self.included(includer) @includer = includer end |
Instance Method Details
#authorize ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/oauth/cli/twitter.rb', line 94 def if @options[:browser] Kernel.send(:open_browser, request_token.) else STDOUT.puts 'Visit URL below to allow this application.' STDOUT.puts request_token. end request_token.get_access_token(:oauth_verifier => prompt_pin) end |
#consumer ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/oauth/cli/twitter.rb', line 108 def consumer @consumer ||= OAuth::Consumer.new( @consumer_token, @consumer_secret, :site => 'http://api.twitter.com', :proxy => ENV['http_proxy'] ) end |
#execute ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/oauth/cli/twitter.rb', line 56 def execute config = load_config if config && config['oauth_token'] && config['oauth_token_secret'] @access_token = OAuth::AccessToken.new( consumer, config['oauth_token'], config['oauth_token_secret'] ) @access_token.params = config else @access_token = save_config(@access_token) end @access_token end |
#get_access_token(*args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/oauth/cli/twitter.rb', line 26 def get_access_token(*args) case args.size when 1 @options = args[0] if Twitter.extender && Twitter.extender.const_defined?(:CONSUMER_TOKEN) && Twitter.extender.const_defined?(:CONSUMER_SECRET) @consumer_token = Twitter.extender::CONSUMER_TOKEN @consumer_secret = Twitter.extender::CONSUMER_SECRET elsif Twitter.includer && Twitter.includer.const_defined?(:CONSUMER_TOKEN) && Twitter.includer.const_defined?(:CONSUMER_SECRET) @consumer_token = Twitter.includer::CONSUMER_TOKEN @consumer_secret = Twitter.includer::CONSUMER_SECRET elsif Object.const_defined?(:CONSUMER_TOKEN) && Object.const_defined?(:CONSUMER_SECRET) @consumer_token = Object::CONSUMER_TOKEN @consumer_secret = Object::CONSUMER_SECRET else @consumer_token = CONSUMER_TOKEN @consumer_secret = CONSUMER_SECRET end when 2, 3 @consumer_token, @consumer_secret, @options = args else raise ArgumentError end execute end |
#load_config ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/oauth/cli/twitter.rb', line 72 def load_config if @options[:pit] Pit.get(@options[:pit]) elsif @options[:file] && File.exist?(@options[:file]) YAML.load(File.read(@options[:file])) end end |
#prompt_pin ⇒ Object
117 118 119 120 121 |
# File 'lib/oauth/cli/twitter.rb', line 117 def prompt_pin while pin = Readline.readline('Enter pin > ') break pin if pin =~ /^\d+$/ end end |
#request_token ⇒ Object
104 105 106 |
# File 'lib/oauth/cli/twitter.rb', line 104 def request_token @request_token ||= consumer.get_request_token end |
#save_config(access_token) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/oauth/cli/twitter.rb', line 80 def save_config(access_token) config = {} access_token.params.each do |k, v| config[k] = v if k.is_a?(String) end if @options[:pit] Pit.set(@options[:pit], :data => config) elsif @options[:file] File.open(@options[:file], 'w') do |f| f.write(config.to_yaml) end end end |