9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/imgur/tasks/rake.rb', line 9
def authorize(client_id, client_secret)
connection = Faraday.new(HOST)
puts "\nVisit this URL: #{HOST}#{AUTHORIZE_ENDPOINT}?client_id=#{client_id}&response_type=pin"
print 'And after you approved the authorization please enter your verification code: '
pin = STDIN.gets.strip
begin
response = JSON.parse connection.post(TOKEN_ENDPOINT, pin: pin, client_id: client_id, client_secret: client_secret, grant_type: 'pin').body
rescue
puts "Authorization failed.\nPlease try again."
exit
end
puts "\nAuthorization was successful. Use these credentials to initialize the library:\n\naccess_token: \#{response['access_token']}\nrefresh_secret: \#{response['refresh_token']}\n\n MESSAGE\nend\n"
|