Class: GData4Ruby::Service

Inherits:
Base
  • Object
show all
Defined in:
lib/gdata4ruby/service.rb

Overview

Google Data API.

Constant Summary

Constants inherited from Base

Base::AUTH_URL

Instance Attribute Summary collapse

Attributes inherited from Base

#debug, #gdata_version, #proxy_info

Instance Method Summary collapse

Methods inherited from Base

#send_request

Constructor Details

#initialize(attributes = {}) ⇒ Service

Accepts an optional attributes hash for initialization values, most likely :gdata_version



32
33
34
35
36
37
# File 'lib/gdata4ruby/service.rb', line 32

def initialize(attributes = {})
  super(attributes)
  attributes.each do |key, value|
    self.send("#{key}=", value)
  end    
end

Instance Attribute Details

#accountObject (readonly)

Convenience attribute contains the currently authenticated account name



26
27
28
# File 'lib/gdata4ruby/service.rb', line 26

def 
  @account
end

#auth_tokenObject (readonly)

The token returned by the Google servers, used to authorize all subsequent messages



29
30
31
# File 'lib/gdata4ruby/service.rb', line 29

def auth_token
  @auth_token
end

Instance Method Details

#authenticate(username, password, service) ⇒ Object

The authenticate method passes the username and password to google servers.

If authentication succeeds, returns true, otherwise raises the AuthenticationFailed error.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gdata4ruby/service.rb', line 41

def authenticate(username, password, service)
  @auth_token = nil
  ret = nil
  ret = send_request(Request.new(:post, AUTH_URL, "Email=#{username}&Passwd=#{password}&source=GCal4Ruby&service=#{service}&accountType=HOSTED_OR_GOOGLE"))
  if ret.class == Net::HTTPOK
    @auth_token = ret.read_body.to_a[2].gsub("Auth=", "").strip
    @account = username
    @password = password
    return true
  else
    raise AuthenticationFailed
  end
end