app/models/google_apps/sheets_manager.rb
# Wrapper to avoid extra copies of large CSV tables.
Wrapper to avoid extra copies of large CSV tables.
Wrapper to avoid extra copies of large CSV tables .
def upload_to_spreadsheet(sheets_doc_title, path_or_io, parent_id, worksheet_title = nil)
      media = Google::APIClient::UploadIO.new(path_or_io, 'text/csv')
      metadata = { :title => sheets_doc_title }
      file = drive_api.files.insert.request_schema.new metadata
      file.parents = [{ :id => parent_id }]
      result = @session.execute!(
        :api_method => drive_api.files.insert,
        :body_object => file,
        :media => media,
        :parameters => { :uploadType => 'multipart', :convert => true })
      log_response result
      raise Errors::ProxyError, "upload failed with title=#{sheets_doc_title}. Error: #{result.data['error']}" if result.error?
      sheets_doc = @session.wrap_api_file result.data
      if worksheet_title.present?
        primary_worksheet = sheets_doc.worksheets.first
        primary_worksheet.title = worksheet_title
        primary_worksheet.save
      end
      sheets_doc
    rescue Google::APIClient::TransmissionError => e
      log_transmission_error(e, "upload_to_spreadsheet failed with: #{[sheets_doc_title, path_or_io, parent_id].to_s}")
      raise e
    end
def upload_to_spreadsheet ( sheets_doc_title , path_or_io , parent_id , worksheet_title = nil ) media = Google :: APIClient :: UploadIO . new ( path_or_io , 'text/csv' ) metadata = { :title => sheets_doc_title } file = drive_api . files . insert . request_schema . new metadata file . parents = [ { :id => parent_id } ] result = @session . execute! ( :api_method => drive_api . files . insert , :body_object => file , :media => media , :parameters => { :uploadType => 'multipart' , :convert => true } ) log_response result raise Errors :: ProxyError , "upload failed with title=#{sheets_doc_title}. Error: #{result.data['error']}" if result . error? sheets_doc = @session . wrap_api_file result . data if worksheet_title . present? primary_worksheet = sheets_doc . worksheets . first primary_worksheet . title = worksheet_title primary_worksheet . save end sheets_doc rescue Google :: APIClient :: TransmissionError => e log_transmission_error ( e , "upload_to_spreadsheet failed with: #{[sheets_doc_title, path_or_io, parent_id].to_s}" ) raise e end
Wrapper to avoid extra copies of large CSV tables.
Wrapper to avoid extra copies of large CSV tables .
sheets_doc_title
<not_specific>
path_or_io
<not_specific>
parent_id
<not_specific>
worksheet_title
<not_specific>