Class: Commands::UploadTemplate
- Includes:
- Mime
- Defined in:
- lib/gdsh/upload_template.rb
Overview
Uploads a template to the Drive.
Class Method Summary collapse
Instance Method Summary collapse
-
#execute ⇒ Object
Writes a template file to drive.
- #insert_file(filename, file, mimetype) ⇒ Object
- #insert_schema(title, description, mimetype) ⇒ Object
Methods included from Mime
#docx, #html, #jpeg, #ods, #odt, #pdf, #png, #pptx, #rtf, #svg, #txt, #xlsx
Methods inherited from Command
Methods included from DriveError
Methods included from CommandMixin
Constructor Details
This class inherits a constructor from Commands::Command
Class Method Details
.command_name ⇒ Object
11 12 13 |
# File 'lib/gdsh/upload_template.rb', line 11 def self.command_name 'upload_template' end |
.function ⇒ Object
15 16 17 |
# File 'lib/gdsh/upload_template.rb', line 15 def self.function 'Uploads a template to the Drive.' end |
Instance Method Details
#execute ⇒ Object
Writes a template file to drive.
43 44 45 46 47 48 49 50 |
# File 'lib/gdsh/upload_template.rb', line 43 def execute filename = 'document.txt' return unless @client && File.exist?(filename) puts 'Writing template to drive.'.colorize(:green) file = insert_schema('My Document', 'A test document', txt) insert_file(filename, file, txt) end |
#insert_file(filename, file, mimetype) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gdsh/upload_template.rb', line 27 def insert_file(filename, file, mimetype) drive = @client.discovered_api('drive', 'v2') media = Google::APIClient::UploadIO.new(filename, mimetype) @client.execute( api_method: drive.files.insert, body_object: file, media: media, parameters: { uploadType: 'multipart', convert: 'true', alt: 'json' }) end |
#insert_schema(title, description, mimetype) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/gdsh/upload_template.rb', line 19 def insert_schema(title, description, mimetype) drive = @client.discovered_api('drive', 'v2') drive.files.insert.request_schema.new( title: title, description: description, mimeType: mimetype) end |