require 'net/http'
require 'net/https'
require 'cgi'
require 'rubygems'
require 'xmlsimple'
require 'pp'
def get_feed(uri, headers=nil)
uri = URI.parse(uri)
Net::HTTP.start(uri.host, uri.port) do |http|
return http.get(uri.path, headers)
end
end
email = '[email protected]'
password = CGI::escape('pa$$word')
service = 'writely'
source = 'MyCompany-MyApp-0.1'
path = '/accounts/ClientLogin'
data = ["accountType=HOSTED_OR_GOOGLE",
"Email=#{email}",
"Passwd=#{password}",
"service=#{service}",
"source=#{source}"].join('&')
http = Net::HTTP.new(host='www.google.com', port=443)
http.use_ssl = true
http.start
headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
resp, data = http.post(path, data, headers)
token = data[/Auth=(.*)/, 1] # parse out the Auth token
headers['Authorization'] = "GoogleLogin auth=#{token}"
resp = get_feed('http://docs.google.com/feeds/documents/private/full', headers)
doc = XmlSimple.xml_in(resp.body, 'KeyAttr' => 'name')
pp doc
Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts
Accessing a feed using ClientLogin & Ruby
Posted by
Eric (Google)
on
Friday, November 14, 2008
Example of accessing the DocList API using ClientLogin in Ruby:
Labels:
ClientLogin,
DocList,
ruby
Signed AuthSub in Ruby
Posted by
Jeff Fisher
on
Thursday, July 03, 2008
Example code for signing an AuthSub request in Ruby.
Contributed by an awesome guy named Immad. Watch out for the groups linebreak in his line that starts with header =, though.
Subscribe to:
Comments (Atom)