Class: Flickr::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/flickr/authenticator.rb

Class Method Summary collapse

Class Method Details

.authenticate(should_retry = true) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/flickr/authenticator.rb', line 6

def authenticate(should_retry = true)
  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.
  rescue StandardError => e
    raise unless should_retry

    oauth(flickr)
    # retry
    authenticate(false)
  end

  flickr
end