gimite-google-spreadsheet-ruby 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/google_spreadsheet.rb +42 -16
  2. metadata +2 -2
@@ -53,7 +53,11 @@ module GoogleSpreadsheet
53
53
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
54
54
  http.start() do
55
55
  path = uri.path + (uri.query ? "?#{uri.query}" : "")
56
- response = http.__send__(method, path, data, header)
56
+ if method == :delete
57
+ response = http.__send__(method, path, header)
58
+ else
59
+ response = http.__send__(method, path, data, header)
60
+ end
57
61
  if !(response.code =~ /^2/)
58
62
  raise(GoogleSpreadsheet::Error, "Response code #{response.code} for POST #{url}: " +
59
63
  CGI.unescapeHTML(response.body))
@@ -164,6 +168,12 @@ module GoogleSpreadsheet
164
168
  return Hpricot.XML(response)
165
169
  end
166
170
 
171
+ def delete(url) #:nodoc:
172
+ header = self.http_header.merge({"Content-Type" => "application/atom+xml"})
173
+ response = http_request(:delete, url, nil, header)
174
+ return Hpricot.XML(response)
175
+ end
176
+
167
177
  def http_header #:nodoc:
168
178
  return {"Authorization" => "GoogleLogin auth=#{@auth_token}"}
169
179
  end
@@ -256,6 +266,7 @@ module GoogleSpreadsheet
256
266
  result = []
257
267
  for entry in doc.search("entry")
258
268
  title = entry.search("title").text
269
+
259
270
  url = entry.search(
260
271
  "link[@rel='http://schemas.google.com/spreadsheets/2006#cellsfeed']")[0]["href"]
261
272
  result.push(Worksheet.new(@session, url, title))
@@ -291,14 +302,28 @@ module GoogleSpreadsheet
291
302
  @session = session
292
303
  @cells_feed_url = cells_feed_url
293
304
  @title = title
305
+
294
306
  @cells = nil
295
307
  @input_values = nil
296
308
  @modified = Set.new()
297
309
  end
298
310
 
299
- # URL of cell-based feed of the spreadsheet.
311
+ # URL of cell-based feed of the worksheet.
300
312
  attr_reader(:cells_feed_url)
301
313
 
314
+ # URL of worksheet feed URL of the worksheet.
315
+ def worksheet_feed_url
316
+ # I don't know good way to get worksheet feed URL from cells feed URL.
317
+ # Probably it would be cleaner to keep worksheet feed URL and get cells feed URL
318
+ # from it.
319
+ if !(@cells_feed_url =~
320
+ %r{^http://spreadsheets.google.com/feeds/cells/(.*)/(.*)/private/full$})
321
+ raise(GoogleSpreadsheet::Error,
322
+ "cells feed URL is in unknown format: #{@cells_feed_url}")
323
+ end
324
+ return "http://spreadsheets.google.com/feeds/worksheets/#{$1}/private/full/#{$2}"
325
+ end
326
+
302
327
  # Returns content of the cell as String. Top-left cell is [1, 1].
303
328
  def [](row, col)
304
329
  return self.cells[[row, col]] || ""
@@ -403,6 +428,7 @@ module GoogleSpreadsheet
403
428
  @max_rows = doc.search("gs:rowCount").text.to_i()
404
429
  @max_cols = doc.search("gs:colCount").text.to_i()
405
430
  @title = doc.search("title").text
431
+
406
432
  @cells = {}
407
433
  @input_values = {}
408
434
  for entry in doc.search("entry")
@@ -417,31 +443,23 @@ module GoogleSpreadsheet
417
443
  return true
418
444
  end
419
445
 
420
- # Saves your changes made by []= to the server.
446
+ # Saves your changes made by []=, etc. to the server.
421
447
  def save()
422
448
  sent = false
423
449
 
424
450
  if @meta_modified
425
451
 
426
- # I don't know good way to get worksheet feed URL from cells feed URL.
427
- # Probably it would be cleaner to keep worksheet feed URL and get cells feed URL
428
- # from it.
429
- if !(@cells_feed_url =~
430
- %r{^http://spreadsheets.google.com/feeds/cells/(.*)/(.*)/private/full$})
431
- raise(GoogleSpreadsheet::Error,
432
- "cells feed URL is in unknown format: #{@cells_feed_url}")
433
- end
434
- ws_doc = @session.get(
435
- "http://spreadsheets.google.com/feeds/worksheets/#{$1}/private/full/#{$2}")
452
+ ws_doc = @session.get(self.worksheet_feed_url)
436
453
  edit_url = ws_doc.search("link[@rel='edit']")[0]["href"]
437
454
  xml = <<-"EOS"
438
455
  <entry xmlns='http://www.w3.org/2005/Atom'
439
456
  xmlns:gs='http://schemas.google.com/spreadsheets/2006'>
440
- <title>#{h(@title)}</title>
441
- <gs:rowCount>#{h(@max_rows)}</gs:rowCount>
442
- <gs:colCount>#{h(@max_cols)}</gs:colCount>
457
+ <title>#{h(self.title)}</title>
458
+ <gs:rowCount>#{h(self.max_rows)}</gs:rowCount>
459
+ <gs:colCount>#{h(self.max_cols)}</gs:colCount>
443
460
  </entry>
444
461
  EOS
462
+
445
463
  @session.put(edit_url, xml)
446
464
 
447
465
  @meta_modified = false
@@ -491,6 +509,7 @@ module GoogleSpreadsheet
491
509
  xml << <<-"EOS"
492
510
  </feed>
493
511
  EOS
512
+
494
513
  result = @session.post("#{@cells_feed_url}/batch", xml)
495
514
  for entry in result.search("atom:entry")
496
515
  interrupted = entry.search("batch:interrupted")[0]
@@ -517,6 +536,13 @@ module GoogleSpreadsheet
517
536
  reload()
518
537
  end
519
538
 
539
+ # Deletes this worksheet. Deletion takes effect right away without calling save().
540
+ def delete
541
+ ws_doc = @session.get(self.worksheet_feed_url)
542
+ edit_url = ws_doc.search("link[@rel='edit']")[0]["href"]
543
+ @session.delete(edit_url)
544
+ end
545
+
520
546
  # Returns true if you have changes made by []= which haven't been saved.
521
547
  def dirty?
522
548
  return !@modified.empty?
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Ichikawa
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-13 00:00:00 -07:00
12
+ date: 2009-09-05 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency