Class: GDataPlus::Authenticator::ClientLogin

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/gdata_plus/authenticator/client_login.rb

Constant Summary collapse

TYPE_GOOGLE =
"GOOGLE"
TYPE_HOSTED =
"HOSTED"
TYPE_HOSTED_OR_GOOGLE =
"HOSTED_OR_GOOGLE"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#client

Constructor Details

#initialize(options = {}) ⇒ ClientLogin

Options

:service

(required) Name of service to which you are authenticating. Click here for a list of possible values.

:source

(required) Short string identifying your application, for logging purposes. This string should take the form: “companyName-applicationName-versionID”.

:account_type

Account type to login. Defaults to TYPE_HOSTED_OR_GOOGLE. Click here for details.



27
28
29
30
31
32
33
34
# File 'lib/gdata_plus/authenticator/client_login.rb', line 27

def initialize(options = {})
  options = Util.prepare_options(options, [:service, :source], [:account_type])
  options[:account_type] ||= TYPE_HOSTED_OR_GOOGLE

  @service = options[:service]
  @source = options[:source]
  @account_type = options[:account_type]
end

Instance Attribute Details

#auth_tokenObject

Returns the value of attribute auth_token.



15
16
17
# File 'lib/gdata_plus/authenticator/client_login.rb', line 15

def auth_token
  @auth_token
end

Instance Method Details

#authenticate(email, password, hydra = Typhoeus::Hydra.new) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gdata_plus/authenticator/client_login.rb', line 36

def authenticate(email, password, hydra = Typhoeus::Hydra.new)
  request = Typhoeus::Request.new("https://www.google.com/accounts/ClientLogin", :method => :post, :params => {
    :accountType => @accountType,
    :Email => email,
    :Passwd => password,
    :service => @service,
    :source => @source
  })

  hydra.queue request
  hydra.run
  response = request.response

  Util.raise_if_error(response)
  @auth_token = /Auth=(.+)$/.match(response.body)[1]
end

#sign_request(request) ⇒ Object

Raises:

  • (ArgumentError)


53
54
55
56
57
# File 'lib/gdata_plus/authenticator/client_login.rb', line 53

def sign_request(request)
  raise ArgumentError, "request must be a Typeoeus::Request" unless request.is_a? ::Typhoeus::Request
  request.headers["Authorization"] = "GoogleLogin auth=#{@auth_token}"
  request
end