Class: SifttterRedux::DropboxUploader

Inherits:
Object
  • Object
show all
Defined in:
lib/sifttter-redux/dropbox-uploader.rb

Overview

DropboxUploader Class Wrapper class for the Dropbox Uploader project

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dbu_path, logger = nil) ⇒ void

Loads the location of dropbox_uploader.sh.

Parameters:

  • dbu_path (String)

    The local filepath to the script

  • A (Logger)

    Logger to use



25
26
27
28
# File 'lib/sifttter-redux/dropbox-uploader.rb', line 25

def initialize(dbu_path, logger = nil)
  @dbu = dbu_path
  @logger = logger
end

Instance Attribute Details

#local_targetString

Stores the local filepath.

Returns:

  • (String)


7
8
9
# File 'lib/sifttter-redux/dropbox-uploader.rb', line 7

def local_target
  @local_target
end

#messageString

Stores the message to display.

Returns:

  • (String)


15
16
17
# File 'lib/sifttter-redux/dropbox-uploader.rb', line 15

def message
  @message
end

#remote_targetString

Stores the remote filepath.

Returns:

  • (String)


11
12
13
# File 'lib/sifttter-redux/dropbox-uploader.rb', line 11

def remote_target
  @remote_target
end

#verboseBoolean

Stores the verbosity level.

Returns:

  • (Boolean)


19
20
21
# File 'lib/sifttter-redux/dropbox-uploader.rb', line 19

def verbose
  @verbose
end

Instance Method Details

#downloadvoid

This method returns an undefined value.

Downloads files from Dropbox (assumes that both local_target and remote_target have been set).



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sifttter-redux/dropbox-uploader.rb', line 33

def download
  if !@local_target.nil? && !@remote_target.nil?
    if @verbose
      system "#{ @dbu } download #{ @remote_target } #{ @local_target }"
    else
      exec = `#{ @dbu } download #{ @remote_target } #{ @local_target }`
    end
  else
    error_msg = 'Local and remote targets cannot be nil'
    @logger.error(error_msg) if @logger
    fail StandardError, error_msg
  end
end

#uploadvoid

This method returns an undefined value.

Uploads files tro Dropbox (assumes that both local_target and remote_target have been set).



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sifttter-redux/dropbox-uploader.rb', line 50

def upload
  if !@local_target.nil? && !@remote_target.nil?
    if @verbose
      system "#{ @dbu } upload #{ @local_target } #{ @remote_target }"
    else
      exec = `#{ @dbu } upload #{ @local_target } #{ @remote_target }`
    end
  else
    error_msg = 'Local and remote targets cannot be nil'
    @logger.error(error_msg) if @logger
    fail StandardError, error_msg
  end
end