Class: Flickr::Auth

Inherits:
APIBase show all
Defined in:
lib/flickr/auth.rb

Instance Attribute Summary collapse

Attributes inherited from APIBase

#flickr

Instance Method Summary collapse

Constructor Details

#initialize(flickr, token_cache = nil) ⇒ Auth

Returns a new instance of Auth.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/flickr/auth.rb', line 14

def initialize(flickr, token_cache=nil)
	super(flickr)
	@frob = nil
	@token = nil
	@token_cache = case token_cache
	when String
		Flickr::FileTokenCache.new token_cache
	else
		token_cache
	end
	@token = @token_cache.load_token if @token_cache
end

Instance Attribute Details

#tokenObject

Returns the value of attribute token.



7
8
9
# File 'lib/flickr/auth.rb', line 7

def token
  @token
end

#token_cacheObject

Returns the value of attribute token_cache.



7
8
9
# File 'lib/flickr/auth.rb', line 7

def token_cache
  @token_cache
end

Instance Method Details

#cache_tokenObject



45
46
47
# File 'lib/flickr/auth.rb', line 45

def cache_token
	@token_cache.cache_token(@token) if @token_cache
end

#clear_cacheObject



9
10
11
12
# File 'lib/flickr/auth.rb', line 9

def clear_cache
	@token = nil
	@frob = nil
end

#frobObject



36
# File 'lib/flickr/auth.rb', line 36

def frob() return @frob || getFrob end

#frob=(frob) ⇒ Object



35
# File 'lib/flickr/auth.rb', line 35

def frob=(frob) @frob = frob end

#getFrobObject



55
56
57
58
59
# File 'lib/flickr/auth.rb', line 55

def getFrob
	doc = @flickr.call_unauth_method('flickr.auth.getFrob')
	@frob = doc.elements['/frob'].text
	return @frob
end

#getFullToken(mini_token) ⇒ Object



49
50
51
52
53
# File 'lib/flickr/auth.rb', line 49

def getFullToken(mini_token)
	res = flickr.call_unauth_method('flickr.auth.getFullToken',
			'mini_token' => mini_token)
	@token = Flickr::Token.from_xml(res)
end

#getToken(frob = nil) ⇒ Object



38
39
40
41
42
43
# File 'lib/flickr/auth.rb', line 38

def getToken(frob=nil)
	frob ||= @frob
	res=@flickr.call_unauth_method('flickr.auth.getToken',
			'frob'=>frob)
	@token = Flickr::Token.from_xml(res)
end


27
28
29
30
31
32
33
# File 'lib/flickr/auth.rb', line 27

def (perms='delete')
	args={ 'api_key' => @flickr.api_key, 'perms' => perms}
	args['frob'] = self.frob
	args['api_sig'] = @flickr.sign(args)
	return "http://flickr.com/services/auth/?"+
		args.to_a.map{|arr| arr.join('=')}.join('&')
end