Class: DropboxServerBackupApp

Inherits:
Object
  • Object
show all
Defined in:
lib/dropbox_server_backup_app.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#sessionObject (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

Yields:



11
12
13
14
15
16
17
# File 'lib/dropbox_server_backup_app.rb', line 11

def self.create(options)
  session = DropboxSession.new(options[:app_key], options[:app_secret])
  session.get_request_token
  yield(session.get_authorize_url)
  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(message, error=false)
  full_message = ""
  full_message += "ERROR: " if error
  full_message += message
  puts full_message
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