Class: FlickrAuthentication

Inherits:
Object
  • Object
show all
Defined in:
lib/flickr_authentication.rb,
lib/flickr_authentication/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FlickrAuthentication

Returns a new instance of FlickrAuthentication.



10
11
12
13
14
# File 'lib/flickr_authentication.rb', line 10

def initialize(options = {})
  @key           = options[:key]
  @shared_secret = options[:shared_secret]
  @auth_file     = options[:auth_file]
end

Instance Attribute Details

#auth_fileObject

Returns the value of attribute auth_file.



8
9
10
# File 'lib/flickr_authentication.rb', line 8

def auth_file
  @auth_file
end

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/flickr_authentication.rb', line 8

def key
  @key
end

#shared_secretObject

Returns the value of attribute shared_secret.



8
9
10
# File 'lib/flickr_authentication.rb', line 8

def shared_secret
  @shared_secret
end

Instance Method Details

#authenticateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/flickr_authentication.rb', line 16

def authenticate
  FlickRaw.api_key        = key
  FlickRaw.shared_secret  = shared_secret

  if File.exists?(auth_file)
    puts "authenticating with #{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
    data              = {}
    data["api_token"] = auth.token
    File.open(auth_file, "w"){|f| YAML.dump(data, f) }
  end

  flickr #return the flickr object

end