Class: Google::ClientLogin

Inherits:
Object
  • Object
show all
Defined in:
lib/google/client_login.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, password, options = {}) ⇒ ClientLogin

Returns a new instance of ClientLogin.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/google/client_login.rb', line 9

def initialize(email, password, options = {})
  @email           = email
  @options         = options
  http             = Net::HTTP.new("www.google.com", 443)
  http.use_ssl     = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request          = Net::HTTP::Post.new("/accounts/ClientLogin")
  request.set_form_data({
    "accountType" => @options[:type]    ||= "HOSTED_OR_GOOGLE",
    "service"     => @options[:service] ||= "cp",
    "Email"       => email,
    "Passwd"      => password
  })

  @response = http.start { |conn| conn.request(request) }
  @token    = response.body.match(/Auth=(.*)/)[1] if response.code == "200"
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



7
8
9
# File 'lib/google/client_login.rb', line 7

def email
  @email
end

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/google/client_login.rb', line 7

def response
  @response
end

#tokenObject (readonly)

Returns the value of attribute token.



7
8
9
# File 'lib/google/client_login.rb', line 7

def token
  @token
end

Instance Method Details

#family_nameObject



50
51
52
# File 'lib/google/client_login.rb', line 50

def family_name
  profile.match(/<gd:familyName>(.+)<\/gd:familyName>/)[1] if profile
end

#given_nameObject



46
47
48
# File 'lib/google/client_login.rb', line 46

def given_name
  profile.match(/<gd:givenName>(.+)<\/gd:givenName>/)[1] if profile
end

#logged_in?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/google/client_login.rb', line 27

def logged_in?
  @token ? true : false
end

#profileObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/google/client_login.rb', line 33

def profile
  if logged_in? && @options[:service] == "cp"
    user, domain = @email.split("@")
    http         = Net::HTTP.new("www.google.com")
    response     = http.get(
      "/m8/feeds/profiles/domain/#{domain}/full/#{user}",
      "GData-Version" => "3.0",
      "Authorization" => "GoogleLogin auth=#{@token}"
    )
    response.body if response.code == "200"
  end
end