Class: GoogleCells::Worksheet

Inherits:
GoogleObject show all
Includes:
Fetcher, Util
Defined in:
lib/google_cells/worksheet.rb

Defined Under Namespace

Classes: UpdateError

Constant Summary

Constants included from Fetcher

Fetcher::BASE_URL

Instance Method Summary collapse

Methods included from Util

#concat_url, #e

Methods included from Fetcher

#raw, #request

Methods inherited from GoogleObject

define_accessors, #initialize

Constructor Details

This class inherits a constructor from GoogleCells::GoogleObject

Instance Method Details

#rowsObject



12
13
14
# File 'lib/google_cells/worksheet.rb', line 12

def rows
  GoogleCells::CellSelector::RowSelector.new(self)
end

#save!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/google_cells/worksheet.rb', line 18

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
  @changed_cells = {}
  true
end

#track_changes(cell) ⇒ Object



39
40
41
42
43
# File 'lib/google_cells/worksheet.rb', line 39

def track_changes(cell)
  @changed_cells ||= {}
  @changed_cells[cell.title] = cell # track only most recent change
  nil
end