Class: Heirloom::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/heirloom/downloader/s3.rb,
lib/heirloom/archive/downloader.rb

Defined Under Namespace

Classes: S3

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Downloader

Returns a new instance of Downloader.



5
6
7
8
9
10
# File 'lib/heirloom/archive/downloader.rb', line 5

def initialize(args)
  @config = args[:config]
  @name   = args[:name]
  @id     = args[:id]
  @logger = @config.logger
end

Instance Method Details

#download(args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/heirloom/archive/downloader.rb', line 12

def download(args)
  @region        = args[:region]
  @bucket_prefix = args[:bucket_prefix]
  @secret        = args[:secret]
  extract        = args[:extract]
  output         = args[:output] ||= './'

  @logger.info "Downloading s3://#{bucket}/#{key} from #{@region}."

  s3_downloader = Downloader::S3.new :config => @config,
                                     :logger => @logger,
                                     :region => @region

  raw_archive = s3_downloader.download_file :bucket => bucket,
                                            :key    => key
  
  return false unless raw_archive

  archive = cipher_data.decrypt_data :data   => raw_archive,
                                     :secret => @secret

  return false unless archive

  return false unless writer.save_archive :archive => archive, 
                                          :output  => output,
                                          :file    => file,
                                          :extract => extract

  @logger.info "Download complete."

  output
end