Module: Earthquake::GetAccessToken

Included in:
Earthquake
Defined in:
lib/earthquake/get_access_token.rb

Instance Method Summary collapse

Instance Method Details

#get_access_tokenObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/earthquake/get_access_token.rb', line 3

def get_access_token
  consumer = OAuth::Consumer.new(
    self.config[:consumer_key],
    self.config[:consumer_secret],
    :site => 'https://api.twitter.com',
    :proxy => ENV['http_proxy']
  )
  request_token = consumer.get_request_token

  puts "1) open: #{request_token.authorize_url}"
  browse(request_token.authorize_url) rescue nil

  print "2) Enter the PIN: "
  pin = STDIN.gets.strip

  access_token = request_token.get_access_token(:oauth_verifier => pin)
  config[:token] = access_token.token
  config[:secret] = access_token.secret

  puts "Saving 'token' and 'secret' to '#{config[:file]}'"
  File.open(config[:file], 'a') do |f|
    f << "\n"
    f << "Earthquake.config[:token] = '#{config[:token]}'"
    f << "\n"
    f << "Earthquake.config[:secret] = '#{config[:secret]}'"
  end
end