Method: GData4Ruby::Service#authenticate

Defined in:
lib/gdata4ruby/service.rb

#authenticate(username, password, service) ⇒ Object

The authenticate method passes the username and password to google servers.

If authentication succeeds, returns true, otherwise raises the AuthenticationFailed error. Thanks to David King and Scott Taylor for Ruby 1.9 fix.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gdata4ruby/service.rb', line 42

def authenticate(username, password, service)
  @auth_token = nil
  ret = nil
  ret = send_request(Request.new(:post, AUTH_URL, "Email=#{username}&Passwd=#{password}&source=GCal4Ruby&service=#{service}&accountType=HOSTED_OR_GOOGLE"))
  if ret.class == Net::HTTPOK
    body = ret.read_body
    lines = body.send(body.respond_to?(:lines) ? :lines : :to_s).to_a
    @auth_token = lines.to_a[2].gsub("Auth=", "").strip
    @account = username
    @password = password
    return true
  else
    raise AuthenticationFailed
  end
end