Class: Flickr::Authenticator
- Inherits:
-
Object
- Object
- Flickr::Authenticator
- Defined in:
- lib/flickr/authenticator.rb
Instance Method Summary collapse
Instance Method Details
#authenticate ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/flickr/authenticator.rb', line 28 def authenticate token = flickr.get_request_token auth_url = flickr.(token['oauth_token'], :perms => 'delete') puts "Open this url in your browser to complete the authentication process : #{auth_url}" puts "Copy here the number given when you complete the process." verify = gets.strip begin flickr.get_access_token(token['oauth_token'], token['oauth_token_secret'], verify) login = flickr.test.login puts "You are now authenticated as #{login.username} with token #{flickr.access_token} and secret #{flickr.access_secret}" File.write('authkey.json', { access_token: flickr.access_token, secret: flickr.access_secret }.to_json) flickr rescue FlickRaw::FailedResponse => e puts "Authentication failed : #{e.msg}" end end |
#flickr ⇒ Object
4 5 6 |
# File 'lib/flickr/authenticator.rb', line 4 def flickr @flickr ||= get_tokens end |
#get_tokens ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/flickr/authenticator.rb', line 8 def get_tokens flickr = FlickRaw::Flickr.new(api_key: ENV['FLICKR_API_KEY'], shared_secret: ENV['FLICKR_SHARED_SECRET']) if File.exist? 'authkey.json' auth_key = JSON.parse(File.read('authkey.json')) flickr.access_token = auth_key['access_token'] flickr.access_secret = auth_key['secret'] end begin flickr.test.login flickr rescue FlickRaw::FailedResponse => e authenticate # retry get_tokens end end |