gimite-google-spreadsheet-ruby 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.txt +26 -1
  2. data/lib/google_spreadsheet.rb +29 -8
  3. metadata +2 -1
data/README.txt CHANGED
@@ -3,7 +3,8 @@ This is a library to read/write Google Spreadsheet.
3
3
 
4
4
  = How to install
5
5
 
6
- TBD
6
+ $ gem sources -a http://gems.github.com
7
+ $ sudo gem install gimite-google-spreadsheet-ruby
7
8
 
8
9
 
9
10
  = How to use
@@ -27,5 +28,29 @@ Example:
27
28
  ws[2, 2] = "bar"
28
29
  ws.save()
29
30
 
31
+ # Dumps all cells.
32
+ for row in 1..ws.num_rows
33
+ for col in 1..ws.num_cols
34
+ p ws[row, col]
35
+ end
36
+ end
37
+
38
+ # Yet another way to do so.
39
+ p ws.rows #==> [["fuga", ""], ["foo", "bar]]
40
+
30
41
  # Reloads the worksheet to get changes by other clients.
31
42
  ws.reload()
43
+
44
+ API document: http://gimite.net/gimite/rubymess/google-spreadsheet-ruby/
45
+
46
+
47
+ = Source code
48
+
49
+ http://github.com/gimite/google-spreadsheet-ruby/tree/master
50
+
51
+ The license of this source is "New BSD Licence"
52
+
53
+
54
+ = Author
55
+
56
+ Hiroshi Ichikawa - http://gimite.net/en/index.php?Contact
@@ -119,7 +119,12 @@ module GoogleSpreadsheet
119
119
  attr_reader(:auth_token)
120
120
 
121
121
  def get(url) #:nodoc:
122
- response = open(url, self.http_header){ |f| f.read() }
122
+ begin
123
+ response = open(url, self.http_header){ |f| f.read() }
124
+ rescue OpenURI::HTTPError => ex
125
+ raise(GoogleSpreadsheet::Error, "Error #{ex.message} for GET #{url}: " +
126
+ ex.io.read())
127
+ end
123
128
  return Hpricot.XML(response)
124
129
  end
125
130
 
@@ -302,6 +307,17 @@ module GoogleSpreadsheet
302
307
  return @cells
303
308
  end
304
309
 
310
+ # An array of spreadsheet rows. Each row contains an array of
311
+ # columns. Note that resulting array is 0-origin so
312
+ # worksheet.rows[0][0] == worksheet[1, 1].
313
+ def rows
314
+ nc = self.num_cols
315
+ result = (1..self.num_rows).map() do |row|
316
+ (1..nc).map(){ |col| self[row, col] }.freeze()
317
+ end
318
+ return result.freeze()
319
+ end
320
+
305
321
  # Reloads content of the worksheets from the server.
306
322
  # Note that changes you made by []= is discarded if you haven't called save().
307
323
  def reload()
@@ -337,9 +353,9 @@ module GoogleSpreadsheet
337
353
 
338
354
  # Updates cell values using batch operation.
339
355
  xml = <<-"EOS"
340
- <feed xmlns='http://www.w3.org/2005/Atom'
341
- xmlns:batch='http://schemas.google.com/gdata/batch'
342
- xmlns:gs='http://schemas.google.com/spreadsheets/2006'>
356
+ <feed xmlns="http://www.w3.org/2005/Atom"
357
+ xmlns:batch="http://schemas.google.com/gdata/batch"
358
+ xmlns:gs="http://schemas.google.com/spreadsheets/2006">
343
359
  <id>#{h(@cells_feed_url)}</id>
344
360
  EOS
345
361
  for row, col in @modified
@@ -350,11 +366,11 @@ module GoogleSpreadsheet
350
366
  xml << <<-"EOS"
351
367
  <entry>
352
368
  <batch:id>#{h(row)},#{h(col)}</batch:id>
353
- <batch:operation type='update'/>
369
+ <batch:operation type="update"/>
354
370
  <id>#{h(id)}</id>
355
- <link rel='edit' type='application/atom+xml'
356
- href='#{h(edit_url)}'/>
357
- <gs:cell row='#{h(row)}' col='#{h(col)}' inputValue='#{h(value)}'/>
371
+ <link rel="edit" type="application/atom+xml"
372
+ href="#{h(edit_url)}"/>
373
+ <gs:cell row="#{h(row)}" col="#{h(col)}" inputValue="#{h(value)}"/>
358
374
  </entry>
359
375
  EOS
360
376
  end
@@ -363,6 +379,11 @@ module GoogleSpreadsheet
363
379
  EOS
364
380
  result = @session.post("#{@cells_feed_url}/batch", xml)
365
381
  for entry in result.search("atom:entry")
382
+ interrupted = entry.search("batch:interrupted")[0]
383
+ if interrupted
384
+ raise(GoogleSpreadsheet::Error, "Update has failed: %s" %
385
+ interrupted["reason"])
386
+ end
366
387
  if !(entry.search("batch:status")[0]["code"] =~ /^2/)
367
388
  raise(GoogleSpreadsheet::Error, "Updating cell %s has failed: %s" %
368
389
  [entry.search("atom:id").text, entry.search("batch:status")[0]["reason"]])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gimite-google-spreadsheet-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Ichikawa
@@ -14,6 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hpricot
17
+ type: :development
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements: