Class: SimpleGdrive::Uploader

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_gdrive/uploader.rb

Overview

Uploads file

Constant Summary collapse

FOLDER_MIME_TYPE =
'application/vnd.google-apps.folder'.freeze
OPTIONS =
{retries: 5}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(base_folder_id:) ⇒ Uploader

Returns a new instance of Uploader.



7
8
9
# File 'lib/simple_gdrive/uploader.rb', line 7

def initialize(base_folder_id:)
  @base_folder_id = base_folder_id
end

Instance Method Details

#call(full_filename, upload_source, content_type:, mime_type: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/simple_gdrive/uploader.rb', line 11

def call(full_filename, upload_source, content_type:, mime_type: nil)
  names = full_filename.split('/')
  filename = names.pop
  parent_id = find_folder(names)

  meta = {name: filename, parents: [parent_id]}
  meta[:mime_type] = mime_type if mime_type

  file = service.create_file(
    meta,
    upload_source: upload_source,
    content_type: content_type,
    options: OPTIONS
  )

  {id: file.id, parent_id: parent_id}
end