lib/google_cells/worksheet.rb in google-cells-0.3.0 vs lib/google_cells/worksheet.rb in google-cells-0.4.0

- old
+ new

@@ -11,29 +11,18 @@ def rows GoogleCells::CellSelector::RowSelector.new(self) end - class UpdateError < StandardError ; end - def save! return if @changed_cells.nil? || @changed_cells.empty? batch_url = concat_url(cells_uri, "/batch") response = request(:post, batch_url, body: to_xml, headers:{ "Content-Type" => "application/atom+xml", "If-Match" => "*"}) doc = Nokogiri.parse(response.body) - for entry in doc.css("atom|entry") - interrupted = entry.css("batch|interrupted")[0] - if interrupted - raise(UpdateError, "Update failed: %s" % interrupted["reason"]) - end - if !(entry.css("batch|status").first["code"] =~ /^2/) - raise(UpdateError, "Update failed for cell %s: %s" % - [entry.css("atom|id").text, entry.css("batch|status")[0]["reason"]]) - end - end + doc.css("atom|entry").each{|entry| check_entry_for_errors!(entry) } @changed_cells = {} true end def track_changes(cell) @@ -41,9 +30,27 @@ @changed_cells[cell.title] = cell # track only most recent change nil end private + + class UpdateError < StandardError ; end + + def check_entry_for_errors!(entry) + check_for_batch_error!(entry) + check_for_cell_error!(entry) + end + + def check_for_batch_error!(entry) + return unless entry.css("batch|interrupted")[0] + raise UpdateError, "Update failed: #{interrupted["reason"]}" + end + + def check_for_cell_error!(entry) + return if (entry.css("batch|status").first["code"] =~ /^2/) + raise UpdateError, "Update failed for cell #{entry.css("atom|id").text + }: #{entry.css("batch|status").first["reason"]}" + end def to_xml xml = <<-EOS <feed xmlns="http://www.w3.org/2005/Atom" xmlns:batch="http://schemas.google.com/gdata/batch"