Accessing a feed using ClientLogin & Ruby


Example of accessing the DocList API using ClientLogin in Ruby:
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 = 'user@gmail.com'
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

8 comments:

Anonymous said...
This comment has been removed by a blog administrator.
jbum said...

If you are attempting to use the analytics service, you will need to use SSL. Modify the line that says

Net::HTTP.start(uri.host, uri.port) do |http|

to this:

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start do |http|

ashkira said...
This comment has been removed by the author.
ashkira said...

I lost authencation token after this step.
# resp, data = http.post(path, data, headers)
Now when I started from the beginning, terminal is giving error at above step can you tell how to this.

thank you

thanh tung said...

Girl Xinh | Hot Girl | Cute Girl | Sexy Girl | Hot Girl Asian
Hot Girl | Lexi Belle | Sexy Girl | Cute Girl | Hot Asian Girl | Leah Dizon | Hot Girl Asian | Girl Xinh
socks proxy | socks5 | proxy free |proxy list

Unknown said...

Sip cyntia
harga mesin sablon kaos
harga mesin las listrik
harga mesin bubut
harga mesin jahit
harga mesin cuci
harga mesin bordir
harga mesin cuci samsung
harga mesin jahit
harga mesin fotocopy
harga mesin cuci front loading
harga mesin cuci terbaru
harga mesin cuci
harga mesin jahit singer
cara menghilangkan jerawat
cara menghilangkan bekas jerawat
cara menghilangkan jerawat secara alami
cara menghilangkan jerawat batu
cara menghilangkan jerawat dengan cepat
cara menghilangkan bekas jerawat secara alami
cara alami menghilangkan jerawat
cara menghilangkan jerawat dan bekasnya
cara alami menghilangkan bekas jerawat
cara menghilangkan bekas jerawat dengan cepat
cara menghilangkan bopeng bekas jerawat
cara cepat menghilangkan jerawat
cara menghilangkan noda bekas jerawat

dorcassmith said...

Among other courses, nursing healthcare coursework writing services have become popular since students seek Healthcare Research Writing Services and healthcare essay writing services.

Printer Repair City said...

Amazing, learn how to resolve Canon Printer Error u052 and solve canon printer error 6a81 Also canon printer error 5200 and this is good Canon Printer Error Code 1007 find out canon printer error e04 as well as canon printer error code p22