google-spreadsheet-ruby 0.1.3 → 0.1.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 +46 -6
  2. metadata +4 -4
@@ -370,20 +370,41 @@ module GoogleSpreadsheet
370
370
  # URL of worksheet-based feed of the spreadsheet.
371
371
  attr_reader(:worksheets_feed_url)
372
372
 
373
- # Title of the spreadsheet. So far only available if you get this object by
374
- # GoogleSpreadsheet::Session#spreadsheets.
375
- attr_reader(:title)
373
+ # Title of the spreadsheet.
374
+ #
375
+ # Set params[:reload] to true to force reloading the title.
376
+ def title(params = {})
377
+ if !@title || params[:reload]
378
+ @title = spreadsheet_feed_entry(params).css("title").text
379
+ end
380
+ return @title
381
+ end
376
382
 
377
383
  # Key of the spreadsheet.
378
384
  def key
379
385
  if !(@worksheets_feed_url =~
380
- %r{^https?://spreadsheets.google.com/feeds/worksheets/(.*)/private/full$})
386
+ %r{^https?://spreadsheets.google.com/feeds/worksheets/(.*)/private/.*$})
381
387
  raise(GoogleSpreadsheet::Error,
382
388
  "worksheets feed URL is in unknown format: #{@worksheets_feed_url}")
383
389
  end
384
390
  return $1
385
391
  end
392
+
393
+ # Spreadsheet feed URL of the spreadsheet.
394
+ def spreadsheet_feed_url
395
+ return "https://spreadsheets.google.com/feeds/spreadsheets/private/full/#{self.key}"
396
+ end
397
+
398
+ # URL which you can open the spreadsheet in a Web browser with.
399
+ #
400
+ # e.g. "http://spreadsheets.google.com/ccc?key=pz7XtlQC-PYx-jrVMJErTcg"
401
+ def human_url
402
+ return self.spreadsheet_feed_entry.css("link[@rel='alternate']").first["href"]
403
+ end
386
404
 
405
+ # DEPRECATED: Table and Record feeds are deprecated and they will not be available after
406
+ # March 2012.
407
+ #
387
408
  # Tables feed URL of the spreadsheet.
388
409
  def tables_feed_url
389
410
  return "https://spreadsheets.google.com/feeds/#{self.key}/tables"
@@ -394,6 +415,16 @@ module GoogleSpreadsheet
394
415
  return "https://docs.google.com/feeds/documents/private/full/spreadsheet%3A#{self.key}"
395
416
  end
396
417
 
418
+ # <entry> element of spreadsheet feed as Nokogiri::XML::Element.
419
+ #
420
+ # Set params[:reload] to true to force reloading the feed.
421
+ def spreadsheet_feed_entry(params = {})
422
+ if !@spreadsheet_feed_entry || params[:reload]
423
+ @spreadsheet_feed_entry = @session.request(:get, self.spreadsheet_feed_url).css("entry").first
424
+ end
425
+ return @spreadsheet_feed_entry
426
+ end
427
+
397
428
  # Creates copy of this spreadsheet with the given name.
398
429
  def duplicate(new_name = nil)
399
430
  new_name ||= (@title ? "Copy of " + @title : "Untitled")
@@ -407,7 +438,7 @@ module GoogleSpreadsheet
407
438
  }
408
439
  doc = @session.request(:post, url, :data => ods, :auth => :writely, :header => header)
409
440
  ss_url = doc.css(
410
- "link[@rel='http://schemas.google.com/spreadsheets/2006#worksheetsfeed']").first['href']
441
+ "link[@rel='http://schemas.google.com/spreadsheets/2006#worksheetsfeed']").first["href"]
411
442
  return Spreadsheet.new(@session, ss_url, title)
412
443
  end
413
444
 
@@ -422,7 +453,7 @@ module GoogleSpreadsheet
422
453
  # Renames title of the spreadsheet.
423
454
  def rename(title)
424
455
  doc = @session.request(:get, self.document_feed_url)
425
- edit_url = doc.css("link[@rel='edit']").first['href']
456
+ edit_url = doc.css("link[@rel='edit']").first["href"]
426
457
  xml = <<-"EOS"
427
458
  <atom:entry
428
459
  xmlns:atom="http://www.w3.org/2005/Atom"
@@ -466,6 +497,9 @@ module GoogleSpreadsheet
466
497
  return Worksheet.new(@session, self, url, title)
467
498
  end
468
499
 
500
+ # DEPRECATED: Table and Record feeds are deprecated and they will not be available after
501
+ # March 2012.
502
+ #
469
503
  # Returns list of tables in the spreadsheet.
470
504
  def tables
471
505
  doc = @session.request(:get, self.tables_feed_url)
@@ -474,6 +508,9 @@ module GoogleSpreadsheet
474
508
 
475
509
  end
476
510
 
511
+ # DEPRECATED: Table and Record feeds are deprecated and they will not be available after
512
+ # March 2012.
513
+ #
477
514
  # Use GoogleSpreadsheet::Worksheet#add_table to create table.
478
515
  # Use GoogleSpreadsheet::Worksheet#tables to get GoogleSpreadsheet::Table objects.
479
516
  class Table
@@ -520,6 +557,9 @@ module GoogleSpreadsheet
520
557
 
521
558
  end
522
559
 
560
+ # DEPRECATED: Table and Record feeds are deprecated and they will not be available after
561
+ # March 2012.
562
+ #
523
563
  # Use GoogleSpreadsheet::Table#records to get GoogleSpreadsheet::Record objects.
524
564
  class Record < Hash
525
565
  include(Util)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-spreadsheet-ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Hiroshi Ichikawa
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-06 00:00:00 +09:00
18
+ date: 2011-05-12 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency