|
| 1 | +# Smoke: GData gem — Google Data API client (legacy, 2007-era) |
| 2 | +# Exercises: GData::Spreadsheet#entry (XML generation), attribute readers from GData::Base |
| 3 | + |
| 4 | +# Stub unavailable external gems so CRuby can load this gem. |
| 5 | +# Under Spinel, plain `require` to other gems is silently ignored anyway. |
| 6 | +$LOADED_FEATURES << 'hpricot' unless $LOADED_FEATURES.include?('hpricot') |
| 7 | +$LOADED_FEATURES << 'builder' unless $LOADED_FEATURES.include?('builder') |
| 8 | +module Hpricot; end unless defined?(Hpricot) |
| 9 | +module Builder; |
| 10 | + class XmlMarkup; end |
| 11 | +end unless defined?(Builder) |
| 12 | + |
| 13 | +# Pre-declare GData as a module so that gdata/base.rb can reopen it. |
| 14 | +# (The top-level gdata.rb declares it as a class, causing a TypeError when |
| 15 | +# gdata/base.rb tries to reopen it as a module. The bin scripts bypass this |
| 16 | +# by requiring gdata/spreadsheet or gdata/blogger directly.) |
| 17 | +module GData |
| 18 | + VERSION = '0.0.4' |
| 19 | +end unless defined?(GData) && GData.is_a?(Module) && !GData.is_a?(Class) |
| 20 | + |
| 21 | +require 'gdata/base' |
| 22 | +require 'gdata/spreadsheet' |
| 23 | + |
| 24 | +# --- GData::Spreadsheet attribute readers (from GData::Base) --- |
| 25 | +gs = GData::Spreadsheet.new('spreadsheet_abc123') |
| 26 | +puts gs.service # => wise |
| 27 | +puts gs.source # => gdata-ruby |
| 28 | +puts gs.url # => spreadsheets.google.com |
| 29 | + |
| 30 | +# --- GData::Spreadsheet#entry generates an Atom+GS XML fragment --- |
| 31 | +# Default row=1, col=1 |
| 32 | +xml1 = gs.entry('SQRT(16)', 1, 1) |
| 33 | +puts xml1.include?("xmlns:gs='http://schemas.google.com/spreadsheets/2006'") # => true |
| 34 | +puts xml1.include?("inputValue='=SQRT(16)'") # => true |
| 35 | +puts xml1.include?("row='1'") # => true |
| 36 | +puts xml1.include?("col='1'") # => true |
| 37 | + |
| 38 | +# Custom row/col |
| 39 | +xml2 = gs.entry('SUM(B2:B10)', 4, 2) |
| 40 | +puts xml2.include?("inputValue='=SUM(B2:B10)'") # => true |
| 41 | +puts xml2.include?("row='4'") # => true |
| 42 | +puts xml2.include?("col='2'") # => true |
| 43 | + |
| 44 | +# --- @headers nil => public path in evaluate_cell (test the path string logic) --- |
| 45 | +# We can't call the network, but the path computation logic uses @headers truthiness. |
| 46 | +# Construct what the path would be (no-auth => 'public') |
| 47 | +expected_path_fragment = gs.instance_variable_get(:@headers) ? "private" : "public" |
| 48 | +puts expected_path_fragment # => public |
0 commit comments