Class: TwitterBackup::TBConfig
- Inherits:
-
Object
- Object
- TwitterBackup::TBConfig
- Defined in:
- lib/twitter_backup/config.rb
Class Method Summary collapse
- .check_backup_file ⇒ Object
- .config_file ⇒ Object
- .configure ⇒ Object
- .configure_database ⇒ Object
- .configure_twitter_gem ⇒ Object
- .credentials_missing? ⇒ Boolean
- .empty_credentials ⇒ Object
- .load ⇒ Object
- .options ⇒ Object
- .passed_opts ⇒ Object
- .path_to_backup_defined? ⇒ Boolean
- .save(options) ⇒ Object
- .save_backup_file(file) ⇒ Object
- .save_credentials(new_credentials) ⇒ Object
- .user ⇒ Object
- .verify_credentials ⇒ Object
Class Method Details
.check_backup_file ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/twitter_backup/config.rb', line 93 def check_backup_file begin backup_file = File.([:backup_file]) TwitterBackup.prepare_file( backup_file ) unless File.exist?( backup_file ) rescue Exception => e raise Error::InvalidBackupFile, e. end end |
.config_file ⇒ Object
123 124 125 |
# File 'lib/twitter_backup/config.rb', line 123 def config_file passed_opts[:config] || CONFIG_FILE end |
.configure ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/twitter_backup/config.rb', line 102 def configure say ".... configuring database" if passed_opts.verbose? configure_database say ".... configuring twitter gem" if passed_opts.verbose? configure_twitter_gem say ".... checking backup file: #{[:backup_file]}" if passed_opts.verbose? check_backup_file end |
.configure_database ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/twitter_backup/config.rb', line 70 def configure_database ActiveRecord::Base.establish_connection([:db]) unless ActiveRecord::Base.connection.tables.include?("tweets") ActiveRecord::Migration.create_table :tweets do |t| t.text :status t.integer :status_id t. :created_at t.text :raw end end end |
.configure_twitter_gem ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/twitter_backup/config.rb', line 82 def configure_twitter_gem raise MissingCredentials if credentials_missing? Twitter.configure do |config| config.consumer_key = [:credentials][:consumer_key] config.consumer_secret = [:credentials][:consumer_secret] config.oauth_token = [:credentials][:oauth_token] config.oauth_token_secret = [:credentials][:oauth_token_secret] end @@twitter_gem_configured = true end |
.credentials_missing? ⇒ Boolean
44 45 46 |
# File 'lib/twitter_backup/config.rb', line 44 def credentials_missing? [:credentials].values.map(&:strip).include? "" end |
.empty_credentials ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/twitter_backup/config.rb', line 62 def empty_credentials new_credentials = { :consumer_key => "", :consumer_secret => "", :oauth_token => "", :oauth_token_secret => ""} save_credentials new_credentials end |
.load ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/twitter_backup/config.rb', line 24 def load TwitterBackup.prepare_file config_file yaml = YAML::load_file( config_file ) @@options = if yaml.is_a? Hash CONFIG_DEFAULTS.merge(yaml) else CONFIG_DEFAULTS end end |
.options ⇒ Object
40 41 42 |
# File 'lib/twitter_backup/config.rb', line 40 def @@options ||= load end |
.passed_opts ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/twitter_backup/config.rb', line 127 def passed_opts @@opts ||= Slop.parse(:help => true) do on :v, :verbose, 'Enable verbose mode' on :f, :force, "Try to download tweets, even it seems useless" on :s, :seed, "Try to download tweets older then the oldest one you have" on :c, :config, "Config file. Default: #{CONFIG_FILE}", :argument => true end end |
.path_to_backup_defined? ⇒ Boolean
48 49 50 |
# File 'lib/twitter_backup/config.rb', line 48 def path_to_backup_defined? [:backup_file].present? end |
.save(options) ⇒ Object
34 35 36 37 38 |
# File 'lib/twitter_backup/config.rb', line 34 def save @@options = TwitterBackup.prepare_file config_file File.open( config_file, "w" ){|f| YAML::dump( , f )} end |
.save_backup_file(file) ⇒ Object
52 53 54 55 |
# File 'lib/twitter_backup/config.rb', line 52 def save_backup_file file [:backup_file] = file save end |
.save_credentials(new_credentials) ⇒ Object
57 58 59 60 |
# File 'lib/twitter_backup/config.rb', line 57 def save_credentials new_credentials [:credentials] = [:credentials].merge(new_credentials) save end |
.user ⇒ Object
119 120 121 |
# File 'lib/twitter_backup/config.rb', line 119 def user @@user ||= verify_credentials end |
.verify_credentials ⇒ Object
113 114 115 116 117 |
# File 'lib/twitter_backup/config.rb', line 113 def verify_credentials say ".... checking validity of credentials" if passed_opts.verbose? configure_twitter_gem unless @@twitter_gem_configured @@user = Twitter.verify_credentials(:skip_status => true, :include_entities => false) end |