Module: Sfd2

Extended by:
Sfd2
Included in:
Sfd2
Defined in:
lib/sfd2.rb,
lib/sfd2/utils.rb,
lib/sfd2/version.rb

Constant Summary collapse

HELP_MSG =
"
  Downloads all of Salesforce documents by a single command.
  Usage: 
run sfd2 in your command line:
$ sfd2 "
VERSION =
"2.0.0"

Instance Method Summary collapse

Instance Method Details

#download(folder, url) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sfd2/utils.rb', line 15

def download(folder, url)
  file_path =  "#{folder}/#{File.basename(url)}"
  pbar = nil
  begin
    File.open(file_path, "wb") do |file|
      file.write open(url,
        :content_length_proc => lambda {|t|
          if t && 0 < t
            pbar = ProgressBar.new(File.basename(url).split('_')[1], t)
            pbar.file_transfer_mode
          end
        },
        :progress_proc => lambda {|s|
          pbar.set s if pbar
        }
      ).read
    end
  rescue Exception => e
    puts e.message
  end
end