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.
31 32 33 34 35 36 37 38 39 |
# File 'lib/flickr/auth.rb', line 31 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.
24 25 26 |
# File 'lib/flickr/auth.rb', line 24 def cache_file @cache_file end |
#token ⇒ Object
Returns the value of attribute token.
24 25 26 |
# File 'lib/flickr/auth.rb', line 24 def token @token end |
Instance Method Details
#cache_token ⇒ Object
52 53 54 |
# File 'lib/flickr/auth.rb', line 52 def cache_token File.open(@cache_file,'w'){ |f| f.write @token.to_xml } if token end |
#checkToken(token = nil) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/flickr/auth.rb', line 87 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
26 27 28 29 |
# File 'lib/flickr/auth.rb', line 26 def clear_cache @token = nil @frob = nil end |
#frob ⇒ Object
50 |
# File 'lib/flickr/auth.rb', line 50 def frob() return @frob || getFrob end |
#frob=(frob) ⇒ Object
49 |
# File 'lib/flickr/auth.rb', line 49 def frob=(frob) @frob = frob end |
#getFrob ⇒ Object
81 82 83 84 85 |
# File 'lib/flickr/auth.rb', line 81 def getFrob doc = @flickr.call_unauth_method('flickr.auth.getFrob') @frob = doc.elements['/frob'].text return @frob end |
#getFullToken(mini_token) ⇒ Object
75 76 77 78 79 |
# File 'lib/flickr/auth.rb', line 75 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
68 69 70 71 72 73 |
# File 'lib/flickr/auth.rb', line 68 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
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/flickr/auth.rb', line 56 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
41 42 43 44 45 46 47 |
# File 'lib/flickr/auth.rb', line 41 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 |