Class: Bricolage::SpreadsheetDataSource::SpreadsheetTask::S3ExportAction

Inherits:
Action
  • Object
show all
Defined in:
lib/bricolage/spreadsheetdatasource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sheet_id, range, format, value_render_option, dest_ds, dest_file, gzip) ⇒ S3ExportAction

Returns a new instance of S3ExportAction.



76
77
78
79
80
81
82
83
84
# File 'lib/bricolage/spreadsheetdatasource.rb', line 76

def initialize(sheet_id, range, format, value_render_option, dest_ds, dest_file, gzip)
  @sheet_id = sheet_id
  @range = range
  @format = format
  @value_render_option = value_render_option
  @dest_ds = dest_ds
  @dest_file = dest_file
  @gzip = gzip
end

Instance Attribute Details

#dest_dsObject (readonly)

Returns the value of attribute dest_ds.



86
87
88
# File 'lib/bricolage/spreadsheetdatasource.rb', line 86

def dest_ds
  @dest_ds
end

#dest_fileObject (readonly)

Returns the value of attribute dest_file.



86
87
88
# File 'lib/bricolage/spreadsheetdatasource.rb', line 86

def dest_file
  @dest_file
end

#gzipObject (readonly)

Returns the value of attribute gzip.



86
87
88
# File 'lib/bricolage/spreadsheetdatasource.rb', line 86

def gzip
  @gzip
end

#rangeObject (readonly)

Returns the value of attribute range.



86
87
88
# File 'lib/bricolage/spreadsheetdatasource.rb', line 86

def range
  @range
end

#sheet_idObject (readonly)

Returns the value of attribute sheet_id.



86
87
88
# File 'lib/bricolage/spreadsheetdatasource.rb', line 86

def sheet_id
  @sheet_id
end

Instance Method Details

#formatObject



96
97
98
# File 'lib/bricolage/spreadsheetdatasource.rb', line 96

def format
  @format.downcase
end

#runObject



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/bricolage/spreadsheetdatasource.rb', line 107

def run
  ds.logger.info source
  rows = ds.formatted_rows(sheet_id, range, format, value_render_option: value_render_option)
  Tempfile.open do |f|
    f = Zlib::GzipWriter.wrap(f) if gzip
    f.write rows.to_a.join("\n")
    f.close # flush
    dest_ds.object(dest_file).upload_file(f.path)
  end
  nil
end

#sourceObject



100
101
102
103
104
105
# File 'lib/bricolage/spreadsheetdatasource.rb', line 100

def source
  <<~SOURCE
    "GET https://sheets.googleapis.com/v4/spreadsheets/#{sheet_id}/values/#{url_encoded_range}"
    "PUT s3://#{dest_ds.bucket_name}/#{dest_ds.prefix}/#{dest_file}"
  SOURCE
end

#url_encoded_rangeObject



88
89
90
# File 'lib/bricolage/spreadsheetdatasource.rb', line 88

def url_encoded_range
  @url_encoded_range ||= URI.encode(range)
end

#value_render_optionObject



92
93
94
# File 'lib/bricolage/spreadsheetdatasource.rb', line 92

def value_render_option
  @value_render_option&.upcase
end