class GoogleDriver::Api
Attributes
client[RW]
drive[RW]
Public Class Methods
new(scope, issuer, p12_path)
click to toggle source
# File lib/google_driver/api.rb, line 7 def initialize(scope, issuer, p12_path) @oauth_scope = scope @issuer = issuer @p12_path = p12_path google_authorize end
Public Instance Methods
detect_mimetype(file)
click to toggle source
# File lib/google_driver/api.rb, line 33 def detect_mimetype(file) # use the unix `file` program to get the mimetype of the file %x<file --mime-type '#{file}'>.split(':')[1].strip() # check success with $?.success? (perlism) end
upload(file, title="A document", description="Words, words, words")
click to toggle source
::file path to a file you wish to upload [REQUIRED] ::title title of the document for browsing on google drive ::description description of the document for browsing on google drive
# File lib/google_driver/api.rb, line 43 def upload(file, title="A document", description="Words, words, words") # # TODO: throw warning if people don't name documents resource = @drive.files.insert.request_schema.new( 'title' => title, 'description' => description ) mimetype = detect_mimetype(file) media = Google::APIClient::UploadIO.new(file, mimetype) response = @client.execute( api_method: @drive.files.insert, body_object: resource, media: media, parameters: { 'uploadType' => 'multipart', 'convert' => true, 'alt' => 'json'}) Document.new(response, self) end
upload_files(*files)
click to toggle source
# File lib/google_driver/api.rb, line 67 def upload_files(*files) files.map do |file| upload(file) end end