Class: Flickrchive::Config
- Inherits:
-
Object
- Object
- Flickrchive::Config
- Defined in:
- lib/flickrchive/config.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
Returns the value of attribute db.
-
#db_file ⇒ Object
Returns the value of attribute db_file.
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#excludes ⇒ Object
Returns the value of attribute excludes.
-
#log_file ⇒ Object
Returns the value of attribute log_file.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#sets ⇒ Object
Returns the value of attribute sets.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #auth ⇒ Object
- #init_logger(config) ⇒ Object
-
#initialize(config_file = nil) ⇒ Config
constructor
A new instance of Config.
- #try_login ⇒ Object
Methods included from Status
Methods included from Execute
#add_to_set, #execute, #get_sets, #handle_flickr_fail, #upload_photo
Methods included from Prepare
#add_to_db, #create_file_metadata, #photo_arrays, #prepare
Constructor Details
#initialize(config_file = nil) ⇒ Config
Returns a new instance of Config.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/flickrchive/config.rb', line 14 def initialize(config_file = nil) begin config = YAML.load_file(config_file || "#{ENV['HOME']}/.flickrchive.yml") # do i need to keep my flickr api key secret? FlickRaw.api_key = config['api_key'] FlickRaw.shared_secret = config['shared_secret'] if config['access_token'].nil? || config['access_secret'].nil? config['access_token'], config['access_secret'] = auth File.open("#{ENV['HOME']}/.flickrchive.yml", 'w') { |f| YAML.dump(config, f) } end flickr.access_token = config['access_token'] flickr.access_secret = config['access_secret'] self.db_file = config['db_file'] self.directory = File.join(config['directory'], "") # ensure dir ends in trailing slash self.excludes = config['excludes'] init_logger(config) self.username = try_login self.db = Daybreak::DB.new self.db_file Flickrchive.logger.debug("Flickrchive initialized as #{self.username}.") self rescue => e # config step inits logger, just put to STDOUT until we can be sure the logger exists puts e exit end end |
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
12 13 14 |
# File 'lib/flickrchive/config.rb', line 12 def db @db end |
#db_file ⇒ Object
Returns the value of attribute db_file.
12 13 14 |
# File 'lib/flickrchive/config.rb', line 12 def db_file @db_file end |
#directory ⇒ Object
Returns the value of attribute directory.
12 13 14 |
# File 'lib/flickrchive/config.rb', line 12 def directory @directory end |
#excludes ⇒ Object
Returns the value of attribute excludes.
12 13 14 |
# File 'lib/flickrchive/config.rb', line 12 def excludes @excludes end |
#log_file ⇒ Object
Returns the value of attribute log_file.
12 13 14 |
# File 'lib/flickrchive/config.rb', line 12 def log_file @log_file end |
#log_level ⇒ Object
Returns the value of attribute log_level.
12 13 14 |
# File 'lib/flickrchive/config.rb', line 12 def log_level @log_level end |
#sets ⇒ Object
Returns the value of attribute sets.
12 13 14 |
# File 'lib/flickrchive/config.rb', line 12 def sets @sets end |
#username ⇒ Object
Returns the value of attribute username.
12 13 14 |
# File 'lib/flickrchive/config.rb', line 12 def username @username end |
Instance Method Details
#auth ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/flickrchive/config.rb', line 53 def auth token = flickr.get_request_token auth_url = flickr.(token['oauth_token'], :perms => 'delete') puts "Open this url in your process to complete the authication process : #{auth_url}" puts "Copy here the number given when you complete the process." verify = gets.strip begin flickr.get_access_token(token['oauth_token'], token['oauth_token_secret'], verify) login = flickr.test.login return flickr.access_token, flickr.access_secret #puts "You are now authenticated as #{login.username} with token #{flickr.access_token} and secret #{flickr.access_secret}" rescue FlickRaw::FailedResponse => e puts "Authentication failed : #{e.msg}" end end |
#init_logger(config) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/flickrchive/config.rb', line 41 def init_logger(config) log_level = config['log_level'] || 'debug' log_file = config['log_file'] || STDOUT Flickrchive.logger = Logger.new(log_file) Flickrchive.logger.level = Logger.const_get(log_level.upcase) end |
#try_login ⇒ Object
48 49 50 51 |
# File 'lib/flickrchive/config.rb', line 48 def try_login login = flickr.test.login return login.username end |