Sha256: cf9a287abb90b07d8b3229d048df4f31878c1fd3bb5fc9f8e5f1d39630022e3c

Contents?: true

Size: 948 Bytes

Versions: 1

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

module Lt
  module Lcms
    module Lesson
      module Uploader
        class Gdoc
          def initialize(credentials)
            @credentials = credentials
          end

          def upload(name, content, content_type, parent_folder_id = nil)
            file_metadata = {
              name: name,
              mime_type: Lt::Google::Api::Drive::MIME_FILE
            }
            file_metadata[:parents] = Array.wrap(parent_folder_id) unless parent_folder_id.nil?
            file = service.create_file(
              file_metadata,
              fields: 'id',
              upload_source: StringIO.new(content),
              content_type: content_type,
              supports_all_drives: true
            )
            file.id
          end

          private

          def service
            @service ||= Lt::Google::Api::Drive.build(@credentials)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lt-lcms-0.6.0 lib/lt/lcms/lesson/uploader/gdoc.rb