lib/google_cells/spreadsheet.rb in google-cells-0.3.0 vs lib/google_cells/spreadsheet.rb in google-cells-0.4.0

- old
+ new

@@ -97,10 +97,14 @@ %w( subscribe share ).each do |m| define_method(m){|args| self.class.send(m, self.key, args) } end + %w( worksheets_uri revisions_uri ).each do |m| + define_method(m){ self.class.send(m, self.key) } + end + def unsubscribe(params) self.class.unsubscribe(params) end def delete @@ -108,11 +112,11 @@ end def copy(opts={}) self.class.copy(self.key, opts) end - + def enfold(folder_key) return true if @folders && @folders.select{|f| f.key == folder_key}.first body = {'id' => self.key}.to_json res = self.class.request(:post, self.class.folder_uri(folder_key), :body => body, :headers => {'Content-Type' => 'application/json'}) @@ -157,23 +161,29 @@ @worksheets << Worksheet.new(args) end return @worksheets end + def revisions + @revisions ||= Revision.list(self.key).map do |r| + r.instance_variable_set(:@spreadsheet, self) + r + end + end + private def self.parse_from_entry(entry, key=nil) - key ||= entry.css("link").select{|el| el['rel'] == 'alternate'}. - first['href'][/key=.+/][4..-1] + url ||= entry.css("link").select{|el| el['rel'] == 'alternate'}. + first['href'] + key = url[/key=.+/] ? url[/key=.+/][4..-1] : url[/[^\/]{44}/] { title: entry.css("title").first.text, key: key, updated_at: entry.css("updated").first.text, author: Author.new( name: entry.css("author/name").first.text, email: entry.css("author/email").first.text ) } end - - def worksheets_uri; self.class.worksheets_uri(key); end end end