Class: GoogleLogin::ClientLogin

Inherits:
Object
  • Object
show all
Defined in:
lib/google-reader-api/google_login.rb

Overview

ClientLogin

Use this Class to get an auth-token

Constant Summary collapse

LoginError =

Base Exception class

Class.new Exception
DEFAULTS =
{ 
  :accountType => 'HOSTED_OR_GOOGLE' ,
  :source => 'companyName-applicationName-versionID',
  :service => 'service-identifier'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arghash = {}) ⇒ ClientLogin

specify the :service, :source and optionally :accountType

:service

the service identifier, check the google api documentation.

:source

the name of your application. String should be in the form “companyName-applicationName-versionID”.

:accountType

one of the following values: “GOOGLE”, “HOSTED”, “HOSTED_OR_GOOGLE” (default if none given)



47
48
49
# File 'lib/google-reader-api/google_login.rb', line 47

def initialize(arghash = {})
  @options = DEFAULTS.merge arghash
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



35
36
37
# File 'lib/google-reader-api/google_login.rb', line 35

def auth
  @auth
end

#captcha_urlObject

Returns the value of attribute captcha_url.



35
36
37
# File 'lib/google-reader-api/google_login.rb', line 35

def captcha_url
  @captcha_url
end

#lsidObject (readonly)

Returns the value of attribute lsid.



35
36
37
# File 'lib/google-reader-api/google_login.rb', line 35

def lsid
  @lsid
end

#sidObject (readonly)

Returns the value of attribute sid.



35
36
37
# File 'lib/google-reader-api/google_login.rb', line 35

def sid
  @sid
end

Instance Method Details

#authenticate(username, password, captcha_response = nil) ⇒ Object

authenticate a user, which sets the auth, sid and lsid instance_variables if you provide a block, it will be called with a captcha url if google forces you to answer the captcha. Make sure you return the anwer in the block.

if no block is given, this will raise a CaptchaRequired error. you can rescue them and show the url via the captcha_url method.

you can then call authenticate and as 3rd parameter you provide the captcha answer.

all Exceptions this raises are subclasses of ClientLogin::LoginError. so make sure you handle them.

This is a list of all the possible errors and their meaning Error code:: Description

BadAuthentication

The login request used a username or password that is not recognized.

NotVerified

The account email address has not been verified. The user will need to access their Google account directly to resolve the issue before logging in using a non-Google application.

TermsNotAgreed

The user has not agreed to terms. The user will need to access their Google account directly to resolve the issue before logging in using a non-Google application.

CaptchaRequired

A CAPTCHA is required. (A response with this error code will also contain an image URL and a CAPTCHA token.)

Unknown

The error is unknown or unspecified; the request contained invalid input or was malformed.

AccountDeleted

The user account has been deleted.

AccountDisabled

The user account has been disabled.

ServiceDisabled

The user’s access to the specified service has been disabled. (The user account may still be valid.)

ServiceUnavailable

The service is not available; try again later.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/google-reader-api/google_login.rb', line 75

def authenticate(username, password, captcha_response = nil)
  @options[:Email], @options[:Passwd] = username, password
  # set logincaptcha, captchatoken will already be set
  @options[:logincaptcha] = captcha_response if captcha_response

  parse_response perform_request
  
rescue CaptchaRequired
  if block_given?
    @options[:logincaptcha] = yield captcha_url
    retry
  else
    raise CaptchaRequired
  end
end