Sha256: aab3ca392c867bf7f132bcd1af6ce7d51a58df0a34a8b5d4489a0bdee71489f6

Contents?: true

Size: 1.13 KB

Versions: 12

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'zip'

module Lt
  module Lcms
    module Lesson
      module Downloader
        class Gspreadsheet < Lt::Lcms::Lesson::Downloader::Base
          MIME_TYPE = 'application/vnd.google-apps.spreadsheet'
          MIME_TYPE_EXPORT = 'application/x-vnd.oasis.opendocument.spreadsheet'

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

          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
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
lt-lcms-0.6.0 lib/lt/lcms/lesson/downloader/gspreadsheet.rb
lt-lcms-0.5.0 lib/lt/lcms/lesson/downloader/gspreadsheet.rb
lt-lcms-0.4.4 lib/lt/lcms/lesson/downloader/gspreadsheet.rb
lt-lcms-0.4.3 lib/lt/lcms/lesson/downloader/gspreadsheet.rb
lt-lcms-0.4.2 lib/lt/lcms/lesson/downloader/gspreadsheet.rb
lt-lcms-0.4.1 lib/lt/lcms/lesson/downloader/gspreadsheet.rb
lt-lcms-0.4.0 lib/lt/lcms/lesson/downloader/gspreadsheet.rb
lt-lcms-0.3.1 lib/lt/lcms/lesson/downloader/gspreadsheet.rb
lt-lcms-0.3.0 lib/lt/lcms/lesson/downloader/gspreadsheet.rb
lt-lcms-0.2.0 lib/lt/lcms/lesson/downloader/gspreadsheet.rb
lt-lcms-0.1.1 lib/lt/lcms/lesson/downloader/gspreadsheet.rb
lt-lcms-0.1.0 lib/lt/lcms/lesson/downloader/gspreadsheet.rb