Class: Restforce::Bulk::Zipper

Inherits:
Object
  • Object
show all
Defined in:
lib/restforce/bulk/zipper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files_mapping, content_type = :zip_xml) ⇒ Zipper

Returns a new instance of Zipper.



6
7
8
9
# File 'lib/restforce/bulk/zipper.rb', line 6

def initialize(files_mapping, content_type=:zip_xml)
  self.files_mapping = files_mapping
  self.content_type  = content_type
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



4
5
6
# File 'lib/restforce/bulk/zipper.rb', line 4

def content_type
  @content_type
end

#files_mappingObject

Returns the value of attribute files_mapping.



4
5
6
# File 'lib/restforce/bulk/zipper.rb', line 4

def files_mapping
  @files_mapping
end

Instance Method Details

#zipObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/restforce/bulk/zipper.rb', line 11

def zip
  ::Zip::File.open(output_filename, ::Zip::File::CREATE) do |zip_file|
    zip_file.get_output_stream('request.txt') do |io|
      io.write builder.create_request_txt(files_mapping)
    end

    files_mapping.each do |mapping|
      zip_file.add(mapping[:filename], mapping[:full_filename])
    end
  end

  output_filename
end