Class: Flickr::FileTokenCache

Inherits:
BaseTokenCache show all
Defined in:
lib/flickr/token_cache.rb

Instance Attribute Summary

Attributes inherited from APIBase

#flickr

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ FileTokenCache

Returns a new instance of FileTokenCache.



17
18
19
# File 'lib/flickr/token_cache.rb', line 17

def initialize(filename)
  @cache_file = filename
end

Instance Method Details

#cache_token(token) ⇒ Object



29
30
31
# File 'lib/flickr/token_cache.rb', line 29

def cache_token(token)
  File.open(@cache_file,'w'){ |f| f.write token.to_xml } if token
end

#load_tokenObject



21
22
23
24
25
26
27
# File 'lib/flickr/token_cache.rb', line 21

def load_token
  token = nil
  File.open(@cache_file,'r'){ |f| token = f.read }
  @token = Flickr::Token.from_xml(REXML::Document.new(token))
rescue Errno::ENOENT
  nil
end