class GDataPlus::Authenticator::ClientLogin

Constants

TYPE_GOOGLE

Account type GOOGLE

TYPE_HOSTED

Account type HOSTED

TYPE_HOSTED_OR_GOOGLE

Account type HOSTED_OR_GOOGLE

Attributes

auth_token[RW]

Public Class Methods

new(options = {}) click to toggle source

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.

# 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

Public Instance Methods

authenticate(email, password, hydra = Typhoeus::Hydra.new) click to toggle source
# 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) click to toggle source
# 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