Class: GoogleSpreadsheets::Connection

Inherits:
ActiveResource::Connection
  • Object
show all
Defined in:
lib/google_spreadsheets/connection.rb

Constant Summary collapse

DEBUG =
false

Instance Method Summary collapse

Instance Method Details

#authorization_header(http_method, uri) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/google_spreadsheets/connection.rb', line 4

def authorization_header(http_method, uri)
  if @user && @password && !@token
    email            = CGI.escape(@user)
    password         = CGI.escape(@password)
    http             = Net::HTTP.new('www.google.com', 443)
    http.use_ssl     = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    resp, data = http.post('/accounts/ClientLogin',
                           "accountType=HOSTED_OR_GOOGLE&Email=#{email}&Passwd=#{password}&service=wise",
                           { 'Content-Type' => 'application/x-www-form-urlencoded' })
    handle_response(resp)
    @token = (data || resp.body)[/Auth=(.*)/n, 1]
  end
  @token ? { 'Authorization' => "GoogleLogin auth=#{@token}" } : {}
end

#http ⇒ Object



19
# File 'lib/google_spreadsheets/connection.rb', line 19

def http() http = super; http.set_debug_output($stderr) if DEBUG; http end