<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mission Data Blog &#187; google</title>
	<atom:link href="http://www.missiondata.com/blog/tag/google/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.missiondata.com/blog</link>
	<description>Louisville-based Web Development &#38; Software Engineering</description>
	<lastBuildDate>Tue, 24 Jan 2012 14:58:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Building a better world with Google Spreadsheets</title>
		<link>http://www.missiondata.com/blog/web-development/65/building-a-better-world-with-google-spreadsheets/</link>
		<comments>http://www.missiondata.com/blog/web-development/65/building-a-better-world-with-google-spreadsheets/#comments</comments>
		<pubDate>Wed, 06 Dec 2006 15:51:04 +0000</pubDate>
		<dc:creator>steveny</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blogs.missiondata.com/uncategorized/65/building-a-better-world-with-google-spreadsheets/</guid>
		<description><![CDATA[I was tickled when I ran across the GoogleLookup and GoogleFinance functions in Google Spreadsheets. I was very tickled when I found there was a REST API for interacting with the spreadsheets. So not only can you lookup the current volume of Google stock in a spreadsheet (=GoogleFinance(&#8220;GOOG&#8221;, &#8220;volume&#8221;)) or find out Roger Clemens&#8217;s ERA [...]]]></description>
			<content:encoded><![CDATA[<p>I was tickled when I ran across the <a href="http://docs.google.com/support/spreadsheets/bin/answer.py?answer=54199&#038;ctx=sibling">GoogleLookup</a> and <a href="http://docs.google.com/support/spreadsheets/bin/answer.py?answer=54198&#038;ctx=sibling">GoogleFinance</a> functions in <a href="">Google Spreadsheets</a>.  I was <b>very</b> tickled when I found there was a <a href="http://code.google.com/apis/gdata/spreadsheets.html">REST API</a> for interacting with the spreadsheets.</p>
<p>So not only can you lookup the current volume of Google stock in a spreadsheet (=GoogleFinance(&#8220;GOOG&#8221;, &#8220;volume&#8221;)) or find out Roger Clemens&#8217;s ERA (=GoogleLookup(&#8220;Roger Clemens&#8221;,&#8221;earned run average&#8221;)) you can access those values real time using an open API.  I cobbled together a quick ruby program that can retrieve values from a private or public (published) Google spreadsheet.  </p>
<p><span id="more-65"></span></p>
<p>The public sample should work for everyone since I published that spreadsheet for the world to see.  You will need to provide your own credentials and spreadsheet key to use the authenticated example.  I will caution that this is just a proof of concept that has limited functionality, weak parsing, and no error checking.</p>
<pre>
<code>#!/usr/bin/env ruby

require 'net/http'
require 'net/https'
require 'uri'
require 'rubygems'
require 'hpricot'

#
# Make it east to use some of the convenience methods using https
#
module Net
  class HTTPS &lt; HTTP
    def initialize(address, port = nil)
      super(address, port)
      self.use_ssl = true
    end
  end
end

class GoogleSpreadSheet
  def initialize(spreadsheet_key)
    @spreadsheet_key = spreadsheet_key
    @headers = nil
  end

  def authenticate(email, password)
    url = URI.parse('https://www.google.com/accounts/ClientLogin')
    response = Net::HTTPS.post_form(url,
      {'Email'=&gt;email,
       'Passwd'=&gt;password,
       'source'=&gt;"ruby-ss-example-1",
       'service'=&gt;'wise' })
    @headers = {
     'Authorization' =&gt; "GoogleLogin auth=#{response.body.split(/=/).last}",
     'Content-Type'  =&gt; 'application/atom+xml'
    }
  end

  def evaluate_cell(cell)
    path = "/feeds/cells/#{@spreadsheet_key}/1/#{@headers ? "private" : "public"}/basic/#{cell}"
    doc = Hpricot(request(path))
    result = (doc/"content[@type='text']").inner_html
  end

  private
  def request(path)
    http = Net::HTTP.new('spreadsheets.google.com', 80)
    response,data = http.get(path, @headers)
    data
  end
end

gs = GoogleSpreadSheet.new('p39irgfu5fsFokTPyPCG8Lg')
puts gs.evaluate_cell("A1")
puts gs.evaluate_cell("A2")
puts gs.evaluate_cell("B1")

gs = GoogleSpreadSheet.new(&lt;your spreadsheet key&gt;)
gs.authenticate(&lt;your email&gt;, &lt;your password&gt;)
puts gs.evaluate_cell("E132")</code>
</pre>
<p>The fun really just starts here.  You can edit existing spreadsheets too (although you can &#8216;t create or delete them yet).  As <a href='http://blogs.missiondata.com/author/richier/'>Rich</a> pointed out to me a few days ago, it won&#8217;t be too long before we are adding &#8216;export to Google spreadsheet&#8217; functions to our web applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/web-development/65/building-a-better-world-with-google-spreadsheets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

