Class: Lt::Lcms::Lesson::Downloader::Gspreadsheet

Inherits:
Base
  • Object
show all
Defined in:
lib/lt/lcms/lesson/downloader/gspreadsheet.rb

Constant Summary collapse

MIME_TYPE =
'application/vnd.google-apps.spreadsheet'
MIME_TYPE_EXPORT =
'application/x-vnd.oasis.opendocument.spreadsheet'

Constants inherited from Base

Base::MAX_RETRY_COUNT, Base::RETRY_DELAYES

Instance Attribute Summary

Attributes inherited from Base

#content

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#download, #file, #file_id, file_id_for, #initialize

Constructor Details

This class inherits a constructor from Lt::Lcms::Lesson::Downloader::Base

Class Method Details

.gdoc_file_url(id) ⇒ Object



13
14
15
# File 'lib/lt/lcms/lesson/downloader/gspreadsheet.rb', line 13

def self.gdoc_file_url(id)
  "https://docs.google.com/spreadsheets/d/#{id}"
end

Instance Method Details

#download_sheet(sheet_name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lt/lcms/lesson/downloader/gspreadsheet.rb', line 17

def download_sheet(sheet_name)
  result = StringIO.new
  tempfile = Tempfile.new
  tempfile.binmode
  download(mime_type: 'application/zip') do |raw_zip|
    tempfile.write raw_zip
    # NOTE: It's impossible to use ::Zip::InputStream due to `General Purpose Flag Bit 3`
    ::Zip::File.open(tempfile.path) do |zip|
      if (entry = zip.find_entry "#{sheet_name}.html")
        result.write entry.get_input_stream.read
      end
    end
    result.string
  end
ensure
  tempfile.close
  tempfile.unlink
end