Class: GData4Ruby::Service
Overview
The service class is the main handler for all direct interactions with the Google Data API.
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Convenience attribute contains the currently authenticated account name.
-
#auth_token ⇒ Object
readonly
The token returned by the Google servers, used to authorize all subsequent messages.
Attributes inherited from Base
#debug, #gdata_version, #proxy_info
Instance Method Summary collapse
-
#authenticate(username, password, service) ⇒ Object
The authenticate method passes the username and password to google servers.
-
#initialize(attributes = {}) ⇒ Service
constructor
Accepts an optional attributes hash for initialization values, most likely :gdata_version.
Methods inherited from Base
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
#account ⇒ Object (readonly)
Convenience attribute contains the currently authenticated account name
26 27 28 |
# File 'lib/gdata4ruby/service.rb', line 26 def account @account end |
#auth_token ⇒ Object (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. Thanks to David King and Scott Taylor for Ruby 1.9 fix.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gdata4ruby/service.rb', line 42 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 body = ret.read_body lines = body.send(body.respond_to?(:lines) ? :lines : :to_s).to_a @auth_token = lines.to_a[2].gsub("Auth=", "").strip @account = username @password = password return true else raise AuthenticationFailed end end |