app/models/google_apps/sheets_manager.rb
# An alternative implementation of GoogleDrive::Spreadsheet#save without the expensive XML parsing.
An alternative implementation of GoogleDrive::Spreadsheet#save without the expensive XML parsing.
An alternative implementation of GoogleDrive :: Spreadsheet#save without the expensive XML parsing .
def update_worksheet(worksheet, updates)
      raise Errors::ProxyError, "File #{worksheet.id} is not a Google Sheets worksheet" unless worksheet.is_a? GoogleDrive::Worksheet
      cells_feed_url = CGI.escapeHTML worksheet.cells_feed_url.to_s
      cells_feed_url_base = cells_feed_url.gsub(/\/private\/full\Z/, '')
      xml = <<-EOS
            <feed xmlns="http://www.w3.org/2005/Atom"
                  xmlns:batch="http://schemas.google.com/gdata/batch"
                  xmlns:gs="http://schemas.google.com/spreadsheets/2006">
              <id>#{cells_feed_url}</id>
      EOS
      updates.each do |coordinates, value|
        row, col = coordinates
        safe_value = value ? CGI.escapeHTML(value).gsub("\n", '&#x0a;') : nil
        xml << <<-EOS
              <entry>
                <batch:id>#{row},#{col}</batch:id>
                <batch:operation type="update"/>
                <id>#{cells_feed_url_base}/R#{row}C#{col}</id>
                <link rel="edit" type="application/atom+xml" href="#{cells_feed_url}/R#{row}C#{col}"/>
                <gs:cell row="#{row}" col="#{col}" inputValue="#{safe_value}"/>
              </entry>
        EOS
      end
      xml << <<-EOS
            </feed>
      EOS
      batch_url = "#{cells_feed_url}/batch"
      begin
        result = @session.execute!(
          http_method: :post,
          uri: batch_url,
          body: xml,
          headers: {
            'Content-Type' => 'application/atom+xml;charset=utf-8',
            'If-Match' => '*'
          }
        )
        log_response result
        raise Errors::ProxyError, "update_worksheet failed at URL #{batch_url}. Error: #{result.data['error']}" if result.error?
        raise Errors::ProxyError, "update_worksheet failed at URL #{batch_url}. Error: interrupted" if result.body.include? 'batch:interrupted'
        result.body
      rescue Google::APIClient::TransmissionError => e
        log_transmission_error(e, "update_worksheet failed failed at URL #{batch_url}")
        raise e
      end
    end
def update_worksheet ( worksheet , updates ) raise Errors :: ProxyError , "File #{worksheet.id} is not a Google Sheets worksheet" unless worksheet . is_a? GoogleDrive :: Worksheet cells_feed_url = CGI . escapeHTML worksheet . cells_feed_url . to_s cells_feed_url_base = cells_feed_url . gsub ( / \/ private \/ full \Z / , '' ) xml = <<-EOS 
            <feed xmlns="http://www.w3.org/2005/Atom"
                  xmlns:batch="http://schemas.google.com/gdata/batch"
                  xmlns:gs="http://schemas.google.com/spreadsheets/2006">
              <id> #{ cells_feed_url } </id>
       EOS updates . each do | coordinates , value | row , col = coordinates safe_value = value ? CGI . escapeHTML ( value ) . gsub ( "\n" , '&#x0a;' ) : nil xml << <<-EOS 
              <entry>
                <batch:id> #{ row } , #{ col } </batch:id>
                <batch:operation type="update"/>
                <id> #{ cells_feed_url_base } /R #{ row } C #{ col } </id>
                <link rel="edit" type="application/atom+xml" href=" #{ cells_feed_url } /R #{ row } C #{ col } "/>
                <gs:cell row=" #{ row } " col=" #{ col } " inputValue=" #{ safe_value } "/>
              </entry>
         EOS end xml << <<-EOS 
            </feed>
       EOS batch_url = "#{cells_feed_url}/batch" begin result = @session . execute! ( http_method : :post , uri : batch_url , body : xml , headers : { 'Content-Type' => 'application/atom+xml;charset=utf-8' , 'If-Match' => '*' } ) log_response result raise Errors :: ProxyError , "update_worksheet failed at URL #{batch_url}. Error: #{result.data['error']}" if result . error? raise Errors :: ProxyError , "update_worksheet failed at URL #{batch_url}. Error: interrupted" if result . body . include? 'batch:interrupted' result . body rescue Google :: APIClient :: TransmissionError => e log_transmission_error ( e , "update_worksheet failed failed at URL #{batch_url}" ) raise e end end
An alternative implementation of GoogleDrive::Spreadsheet#save without the expensive XML parsing.
An alternative implementation of GoogleDrive :: Spreadsheet#save without the expensive XML parsing .
worksheet
<not_specific>
updates
<not_specific>