Class: Google::Spreadsheet
- Inherits:
-
Object
- Object
- Google::Spreadsheet
- Defined in:
- lib/google/spreadsheet.rb
Instance Method Summary collapse
- #add_row(xml, worksheet_id = 1) ⇒ Object
-
#initialize(key) ⇒ Spreadsheet
constructor
A new instance of Spreadsheet.
- #row_data(field, value, worksheet_id = 1) ⇒ Object
- #update_row(xml, worksheet_id = 1) ⇒ Object
- #worksheet_id_for(name) ⇒ Object
Constructor Details
#initialize(key) ⇒ Spreadsheet
Returns a new instance of Spreadsheet.
15 16 17 |
# File 'lib/google/spreadsheet.rb', line 15 def initialize(key) @key = key end |
Instance Method Details
#add_row(xml, worksheet_id = 1) ⇒ Object
30 31 32 |
# File 'lib/google/spreadsheet.rb', line 30 def add_row(xml, worksheet_id = 1) request_with_error_handling :post, :list, "#{LIST_BASE_URL}/#{@key}/#{worksheet_id}/private/full", xml.to_xml end |
#row_data(field, value, worksheet_id = 1) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/google/spreadsheet.rb', line 19 def row_data(field, value, worksheet_id = 1) request_with_error_handling(:get, :list, "#{LIST_BASE_URL}/#{@key}/#{worksheet_id}/private/full?sq=#{CGI.escape(field)}=#{CGI.escape(value)}") do |response| xml = Nokogiri::XML.parse(response.body) xml.css('entry').first end end |
#update_row(xml, worksheet_id = 1) ⇒ Object
26 27 28 |
# File 'lib/google/spreadsheet.rb', line 26 def update_row(xml, worksheet_id = 1) request_with_error_handling :put, :list, xml.css("link[rel = edit]").first["href"], xml.to_xml end |
#worksheet_id_for(name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/google/spreadsheet.rb', line 34 def worksheet_id_for(name) request_with_error_handling(:get, :worksheet, "#{WORKSHEET_BASE_URL}/#{@key}/private/full") do |response| xml = Nokogiri::XML.parse(response.body) # translate converts the attribute's content to lower case, # therefore allowing us to match case-insensitive xml.xpath(".//atom:entry[translate( atom:title, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz' ) = '#{name.downcase}']/atom:id", "atom" => "http://www.w3.org/2005/Atom" ).text.split("/").last end end |