def get_token(username, password, source, login_token = nil,
login_captcha = nil)
body = Hash.new
body['accountType'] = @account_type
body['Email'] = username
body['Passwd'] = password
body['service'] = @service
body['source'] = source
if login_token and login_captcha
body['logintoken'] = login_token
body['logincaptcha'] = login_captcha
end
request = GData::HTTP::Request.new(@auth_url, :body => body,
:method => :post)
service = GData::HTTP::DefaultService.new
response = service.make_request(request)
if response.status_code != 200
url = response.body[/Url=(.*)/,1]
error = response.body[/Error=(.*)/,1]
if error == "CaptchaRequired"
captcha_token = response.body[/CaptchaToken=(.*)/,1]
captcha_url = response.body[/CaptchaUrl=(.*)/,1]
raise GData::Client::CaptchaError.new(captcha_token, captcha_url),
"#{error} : #{url}"
end
raise GData::Client::AuthorizationError.new(response)
end
@token = response.body[/Auth=(.*)/,1]
return @token
end