Class: Flickr::Auth
Instance Attribute Summary collapse
-
#cache_file ⇒ Object
Returns the value of attribute cache_file.
-
#token ⇒ Object
Returns the value of attribute token.
Attributes inherited from APIBase
Instance Method Summary collapse
- #cache_token ⇒ Object
- #checkToken(token = nil) ⇒ Object
- #clear_cache ⇒ Object
- #frob ⇒ Object
- #frob=(frob) ⇒ Object
- #getFrob ⇒ Object
- #getFullToken(mini_token) ⇒ Object
- #getToken(frob = nil) ⇒ Object
-
#initialize(flickr, cache_file = nil) ⇒ Auth
constructor
A new instance of Auth.
- #load_token ⇒ Object
- #login_link(perms = 'delete') ⇒ Object
Constructor Details
#initialize(flickr, cache_file = nil) ⇒ Auth
Returns a new instance of Auth.
13 14 15 16 17 18 19 20 21 |
# File 'lib/flickr/auth.rb', line 13 def initialize(flickr,cache_file=nil) super(flickr) @frob = nil @token = nil @cache_file = cache_file if @cache_file && File.exists?(@cache_file) load_token end end |
Instance Attribute Details
#cache_file ⇒ Object
Returns the value of attribute cache_file.
6 7 8 |
# File 'lib/flickr/auth.rb', line 6 def cache_file @cache_file end |
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/flickr/auth.rb', line 6 def token @token end |
Instance Method Details
#cache_token ⇒ Object
34 35 36 |
# File 'lib/flickr/auth.rb', line 34 def cache_token File.open(@cache_file,'w'){ |f| f.write @token.to_xml } if token end |
#checkToken(token = nil) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/flickr/auth.rb', line 69 def checkToken(token=nil) token ||= @token token = token.token if token.class == Flickr::Token res = @flickr.call_unauth_method('flickr.auth.checkToken', 'auth_token' => token) @token = Flickr::Token.from_xml(res) end |
#clear_cache ⇒ Object
8 9 10 11 |
# File 'lib/flickr/auth.rb', line 8 def clear_cache @token = nil @frob = nil end |
#frob ⇒ Object
32 |
# File 'lib/flickr/auth.rb', line 32 def frob() return @frob || getFrob end |
#frob=(frob) ⇒ Object
31 |
# File 'lib/flickr/auth.rb', line 31 def frob=(frob) @frob = frob end |
#getFrob ⇒ Object
63 64 65 66 67 |
# File 'lib/flickr/auth.rb', line 63 def getFrob doc = @flickr.call_unauth_method('flickr.auth.getFrob') @frob = doc.elements['/frob'].text return @frob end |
#getFullToken(mini_token) ⇒ Object
57 58 59 60 61 |
# File 'lib/flickr/auth.rb', line 57 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
50 51 52 53 54 55 |
# File 'lib/flickr/auth.rb', line 50 def getToken(frob=nil) frob ||= @frob res=@flickr.call_unauth_method('flickr.auth.getToken', 'frob'=>frob) @token = Flickr::Token.from_xml(res) end |
#load_token ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/flickr/auth.rb', line 38 def load_token token = nil File.open(@cache_file,'r'){ |f| token = f.read } # Dirt stupid check to see if it's probably XML or # not. If it is, then we don't call checkToken. # # Backwwards compatible with old token storage. @token = token.include?('<') ? Flickr::Token.from_xml(REXML::Document.new(token)) : @token = checkToken(token) end |
#login_link(perms = 'delete') ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/flickr/auth.rb', line 23 def login_link(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 |