Module: FlickrCli::Authentication

Defined in:
lib/authentication.rb

Class Method Summary collapse

Class Method Details

.establish_sessionObject



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
30
31
32
33
34
35
36
# File 'lib/authentication.rb', line 3

def self.establish_session
  auth_file               = File.expand_path("~/.flick_airliftrc")
  FlickRaw.api_key        = "e8505c88feb2c0cc9d2da6bcbe18767c"
  FlickRaw.shared_secret  = "d344de362ea86f0e"

  if File.exists?(auth_file)
    puts "authenticating thought #{auth_file}"
    data = YAML.load_file(auth_file)
    auth = flickr.auth.checkToken :auth_token => data["api_token"]
  else
    frob                    = flickr.auth.getFrob
    auth_url                = FlickRaw.auth_url :frob => frob, :perms => "write"

    puts " "
    puts "opening your browser..."
    sleep 1
    puts "Come back and press Enter when you are finished"
    sleep 2
    Launchy.open(auth_url)

    STDIN.getc

    # Authentication
    auth  = flickr.auth.getToken :frob => frob
     = flickr.test.

    puts auth.token

    require 'yaml'
    data = {}
    data["api_token"] = auth.token
    File.open(auth_file, "w"){|f| YAML.dump(data, f) }
  end
end