class SheetsAPI::Document

Attributes

id[R]

Public Class Methods

new(documentId: nil, documentName: 'unnamed') click to toggle source
# File lib/sheetsAPI.rb, line 98
def initialize(documentId: nil, documentName: 'unnamed')
  if !documentId
    file = DriveService.create_file(Google::Apis::DriveV3::File.new(mime_type: 'application/vnd.google-apps.spreadsheet', name: documentName))
    documentId = file.id
    a = Google::Apis::DriveV3::Permission.new(type: 'user', role: 'owner', email_address: 'goffert@phusion.nl')
    puts a.inspect
    DriveService.create_permission(documentId, a, transfer_ownership: true)
  end
  @id = documentId
  @document = SheetService.get_spreadsheet(documentId)
end

Public Instance Methods

sheet(sheetName) click to toggle source
# File lib/sheetsAPI.rb, line 111
def sheet(sheetName)
  @sheetName = sheetName

  sheet = @document.sheets.find{|sheet| sheet.properties.title.downcase == sheetName.downcase}
  if !sheet
    createSheet(sheetName)
  end

  return Sheet.new(self, sheetName)
end

Private Instance Methods

createSheet(sheetName) click to toggle source
# File lib/sheetsAPI.rb, line 124
def createSheet(sheetName)
  batch_update_request = {requests: [{
    add_sheet: {
      properties: {
        title: sheetName
      }
    }
  }]}
  SheetService.batch_update_spreadsheet(@id, batch_update_request, {})
end