Class: DropboxServerBackupApp
- Inherits:
-
Object
- Object
- DropboxServerBackupApp
- Defined in:
- lib/dropbox_server_backup_app.rb
Instance Attribute Summary collapse
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(session) ⇒ DropboxServerBackupApp
constructor
A new instance of DropboxServerBackupApp.
- #log(message, error = false) ⇒ Object
- #upload(filename) ⇒ Object
Constructor Details
#initialize(session) ⇒ DropboxServerBackupApp
Returns a new instance of DropboxServerBackupApp.
5 6 7 8 9 |
# File 'lib/dropbox_server_backup_app.rb', line 5 def initialize(session) @access_type = :app_folder @session = session @client = DropboxClient.new(session, @access_type) end |
Instance Attribute Details
#session ⇒ Object (readonly)
Returns the value of attribute session.
3 4 5 |
# File 'lib/dropbox_server_backup_app.rb', line 3 def session @session end |
Class Method Details
.create(options) {|session.get_authorize_url| ... } ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/dropbox_server_backup_app.rb', line 11 def self.create() session = DropboxSession.new([:app_key], [:app_secret]) session.get_request_token yield(session.) session.get_access_token self.new(session) end |
Instance Method Details
#log(message, error = false) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/dropbox_server_backup_app.rb', line 42 def log(, error=false) = "" += "ERROR: " if error += puts end |
#upload(filename) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dropbox_server_backup_app.rb', line 19 def upload(filename) dropbox_filename = File.basename(filename) begin = @client.(dropbox_filename) unless [:is_deleted] log "deleting existing file #{dropbox_filename} from Dropbox" @client.file_delete(dropbox_filename) end rescue DropboxError end begin @client.put_file(dropbox_filename, open(filename)) log "uploading file #{filename} from Dropbox" rescue DropboxAuthError log("can't authenticate with dropbox.", :error) rescue Errno::ENOENT log("file #{filename} doesn't exist.", :error) rescue Errno::EACCES log("no access to file #{filename}.", :error) end end |