12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/pocketbeuter/get_access_token_and_username.rb', line 12
def get_access_token_and_username
get_request_token
auth_url = AUTH_URL + "?request_token=#{Conf.config[:request_token]}&redirect_uri=#{Conf.config[:redirect_uri]}"
Launchy.open(auth_url)
puts "Go to: #{auth_url}\nPress any key after authorization ..."
STDIN.getc
uri = URI.parse(OAUTH_AUTH_URL)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data("consumer_key" => Conf.config[:consumer_key], "code" => Conf.config[:request_token])
http.use_ssl = true
res = http.request(request)
Conf.config[:access_token] = URI.decode_www_form(res.body)[0][1]
Conf.config[:username] = URI.decode_www_form(res.body)[1][1]
end
|