Module: GoogleSpreadsheet
- Defined in:
- lib/google_spreadsheet.rb
Defined Under Namespace
Modules: Util Classes: AuthenticationError, Error, Session, Spreadsheet, Worksheet
Class Method Summary collapse
-
.login(mail, password) ⇒ Object
Authenticates with given
mailandpassword, and returns GoogleSpreadsheet::Session if succeeds. -
.saved_session(path = ENV["HOME"] + "/.ruby_google_spreadsheet.token") ⇒ Object
Restores GoogleSpreadsheet::Session from
pathand returns it.
Class Method Details
.login(mail, password) ⇒ Object
Authenticates with given mail and password, and returns GoogleSpreadsheet::Session if succeeds. Raises GoogleSpreadsheet::AuthenticationError if fails. Google Apps account is supported.
18 19 20 |
# File 'lib/google_spreadsheet.rb', line 18 def self.login(mail, password) return Session.login(mail, password) end |
.saved_session(path = ENV["HOME"] + "/.ruby_google_spreadsheet.token") ⇒ Object
Restores GoogleSpreadsheet::Session from path and returns it. If path doesn’t exist or authentication has failed, prompts mail and password on console, authenticates with them, stores the session to path and returns it.
This method requires Ruby/Password library: www.caliban.org/ruby/ruby-password.shtml
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/google_spreadsheet.rb', line 27 def self.saved_session(path = ENV["HOME"] + "/.ruby_google_spreadsheet.token") session = Session.new(File.exist?(path) ? File.read(path) : nil) session.on_auth_fail = proc() do require "password" $stderr.print("Mail: ") mail = $stdin.gets().chomp() password = Password.get() session.login(mail, password) open(path, "w", 0600){ |f| f.write(session.auth_token) } true end if !session.auth_token session.on_auth_fail.call() end return session end |