commondream-google-spreadsheet-ruby 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/google_spreadsheet.rb +46 -33
- metadata +3 -2
data/lib/google_spreadsheet.rb
CHANGED
@@ -481,42 +481,55 @@ module GoogleSpreadsheet
|
|
481
481
|
end
|
482
482
|
|
483
483
|
# Updates cell values using batch operation.
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
484
|
+
cells = @modified.size
|
485
|
+
current_cell = 0
|
486
|
+
|
487
|
+
while current_cell < cells
|
488
|
+
batch_count = 0
|
489
|
+
xml = <<-"EOS"
|
490
|
+
<feed xmlns="http://www.w3.org/2005/Atom"
|
491
|
+
xmlns:batch="http://schemas.google.com/gdata/batch"
|
492
|
+
xmlns:gs="http://schemas.google.com/spreadsheets/2006">
|
493
|
+
<id>#{h(@cells_feed_url)}</id>
|
494
|
+
EOS
|
495
|
+
|
496
|
+
while batch_count <= 500
|
497
|
+
row,col = @modified[current_cell]
|
498
|
+
value = @cells[[row, col]]
|
499
|
+
entry = cell_entries[[row, col]]
|
500
|
+
id = entry.search("id").text
|
501
|
+
edit_url = entry.search("link[@rel='edit']")[0]["href"]
|
502
|
+
xml << <<-"EOS"
|
503
|
+
<entry>
|
504
|
+
<batch:id>#{h(row)},#{h(col)}</batch:id>
|
505
|
+
<batch:operation type="update"/>
|
506
|
+
<id>#{h(id)}</id>
|
507
|
+
<link rel="edit" type="application/atom+xml"
|
508
|
+
href="#{h(edit_url)}"/>
|
509
|
+
<gs:cell row="#{h(row)}" col="#{h(col)}" inputValue="#{h(value)}"/>
|
510
|
+
</entry>
|
511
|
+
EOS
|
512
|
+
|
513
|
+
# close each batch out at 500 cells
|
514
|
+
current_cell++
|
515
|
+
batch_count++
|
516
|
+
end
|
517
|
+
|
495
518
|
xml << <<-"EOS"
|
496
|
-
|
497
|
-
<batch:id>#{h(row)},#{h(col)}</batch:id>
|
498
|
-
<batch:operation type="update"/>
|
499
|
-
<id>#{h(id)}</id>
|
500
|
-
<link rel="edit" type="application/atom+xml"
|
501
|
-
href="#{h(edit_url)}"/>
|
502
|
-
<gs:cell row="#{h(row)}" col="#{h(col)}" inputValue="#{h(value)}"/>
|
503
|
-
</entry>
|
519
|
+
</feed>
|
504
520
|
EOS
|
505
|
-
end
|
506
|
-
xml << <<-"EOS"
|
507
|
-
</feed>
|
508
|
-
EOS
|
509
521
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
522
|
+
result = @session.post("#{@cells_feed_url}/batch", xml)
|
523
|
+
for entry in result.search("atom:entry")
|
524
|
+
interrupted = entry.search("batch:interrupted")[0]
|
525
|
+
if interrupted
|
526
|
+
raise(GoogleSpreadsheet::Error, "Update has failed: %s" %
|
527
|
+
interrupted["reason"])
|
528
|
+
end
|
529
|
+
if !(entry.search("batch:status")[0]["code"] =~ /^2/)
|
530
|
+
raise(GoogleSpreadsheet::Error, "Updating cell %s has failed: %s" %
|
531
|
+
[entry.search("atom:id").text, entry.search("batch:status")[0]["reason"]])
|
532
|
+
end
|
520
533
|
end
|
521
534
|
end
|
522
535
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commondream-google-spreadsheet-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroshi Ichikawa
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/google_spreadsheet.rb
|
37
37
|
has_rdoc: true
|
38
38
|
homepage: http://github.com/gimite/google-spreadsheet-ruby/tree/master
|
39
|
+
licenses:
|
39
40
|
post_install_message:
|
40
41
|
rdoc_options:
|
41
42
|
- --main
|
@@ -57,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
58
|
requirements: []
|
58
59
|
|
59
60
|
rubyforge_project:
|
60
|
-
rubygems_version: 1.
|
61
|
+
rubygems_version: 1.3.5
|
61
62
|
signing_key:
|
62
63
|
specification_version: 2
|
63
64
|
summary: This is a library to read/write Google Spreadsheet.
|