Class: Gdata::Backup

Inherits:
Object
  • Object
show all
Defined in:
lib/gdata/backup.rb,
lib/gdata/backup/version.rb

Constant Summary collapse

MAJOR =
0
MINOR =
0
REVISION =
2
VERSION =
[MAJOR, MINOR, REVISION].map(&:to_s).join('.')

Instance Method Summary collapse

Constructor Details

#initialize(account_username, path) ⇒ Backup

Returns a new instance of Backup.



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

def initialize(, path)
  @path      = path
  store      = Imap::Backup::Configuration::Store.new
  @account   = store.accounts.find { |a| a[:username] ==  }
  raise 'account unknown' if @account.nil?
  @log       = Logger.new(STDOUT)
  @log.level = Logger::INFO
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gdata/backup.rb', line 19

def run
  raise "The supplied path '#{@path}' does not exist" unless File.directory?(@path) 
  documents.each do |document|
    @log.info document[:file_name]
    begin
      response = spreadsheet_client.get(document[:url])
    rescue => e
      @log.error "Download of #{document[:file_name]} failed: #{e}"
      next
    end
    File.open(File.join(@path, document[:file_name]), 'wb' ) do |file|
      file.write response.body
    end
  end
end