Module Rufus::Google
In: lib/rufus/ahttp.rb
lib/rufus/gcal.rb
lib/rufus/google.rb
lib/rufus/gversion.rb

Methods

Classes and Modules

Module Rufus::Google::CollectionMixin
Module Rufus::Google::EntryMixin
Class Rufus::Google::Calendar
Class Rufus::Google::Event
Class Rufus::Google::Http

Constants

GDATA_VERSION = '2'
VERSION = '0.0.1'

Public Class methods

A small method for getting an atom-tools Feed instance. The options hash is a get_auth_token() hash.

[Source]

     # File lib/rufus/google.rb, line 109
109:   def self.feed_for (feed_uri, options)
110: 
111:     token = get_auth_token(options)
112: 
113:     Atom::Feed.new(feed_uri, Rufus::Google::Http.new(token))
114:   end

Returns the auth token for a google account.

[Source]

     # File lib/rufus/google.rb, line 98
 98:   def self.get_auth_token (options)
 99: 
100:     return options if options.is_a?(String)
101: 
102:     options[:auth] || get_auth_tokens(options)[:auth]
103:   end

Gets an auth token via the Google ClientLogin facility

[Source]

    # File lib/rufus/google.rb, line 52
52:   def self.get_auth_tokens (options)
53: 
54:     account = options[:account]
55:     account_type = options[:account_type] || 'GOOGLE'
56:     password = options[:password]
57:     service = options[:service] || :cl
58:     source = options[:source] || "rufus.rubyforge.org-rufus_google-#{VERSION}"
59: 
60:     account = "#{account}@gmail.com" unless account.index('@')
61: 
62:     password = CGI.escape(password)
63: 
64:     data = ''
65:     data << "accountType=#{account_type}&"
66:     data << "Email=#{account}&"
67:     data << "Passwd=#{password}&"
68:     data << "service=#{service}&"
69:     data << "source=#{source}"
70: 
71:     headers = { 'Content-type' => 'application/x-www-form-urlencoded' }
72:     headers['GData-Version'] = GDATA_VERSION
73: 
74:     r = Rufus::Verbs.post(
75:       'https://www.google.com/accounts/ClientLogin',
76:       :headers => headers,
77:       :data => data)
78: 
79:     code = r.code.to_i
80: 
81:     raise r.body if code == 403
82:     raise "not a 200 OK reply : #{code} : #{r.body}" unless code == 200
83: 
84:     tokens = r.body.split.inject({}) { |h, l|
85:       md = l.match(/^(.*)=(.*$)/)
86:       h[md[1].downcase.to_sym] = md[2]
87:       h
88:     }
89: 
90:     options.merge!(tokens)
91: 
92:     tokens
93:   end

[Validate]