Class: Google::ClientLogin
- Inherits:
-
Object
- Object
- Google::ClientLogin
- Defined in:
- lib/google/client_login.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #family_name ⇒ Object
- #given_name ⇒ Object
-
#initialize(email, password, options = {}) ⇒ ClientLogin
constructor
A new instance of ClientLogin.
- #logged_in? ⇒ Boolean
-
#profile ⇒ Object
XML profile for the logged in user code.google.com/apis/apps/profiles/developers_guide_protocol.html.
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, = {}) @email = email @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
#email ⇒ Object (readonly)
Returns the value of attribute email.
7 8 9 |
# File 'lib/google/client_login.rb', line 7 def email @email end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/google/client_login.rb', line 7 def response @response end |
#token ⇒ Object (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_name ⇒ Object
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_name ⇒ Object
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
27 28 29 |
# File 'lib/google/client_login.rb', line 27 def logged_in? @token ? true : false end |
#profile ⇒ Object
XML profile for the logged in user code.google.com/apis/apps/profiles/developers_guide_protocol.html
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 |