Class: Lt::Lcms::Lesson::Uploader::Gdoc

Inherits:
Object
  • Object
show all
Defined in:
lib/lt/lcms/lesson/uploader/gdoc.rb

Instance Method Summary collapse

Constructor Details

#initialize(credentials) ⇒ Gdoc

Returns a new instance of Gdoc.



8
9
10
# File 'lib/lt/lcms/lesson/uploader/gdoc.rb', line 8

def initialize(credentials)
  @credentials = credentials
end

Instance Method Details

#upload(name, content, content_type, parent_folder_id = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lt/lcms/lesson/uploader/gdoc.rb', line 12

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