lib/roo/google.rb in roo-0.5.0 vs lib/roo/google.rb in roo-0.5.1

- old
+ new

@@ -1,113 +1,125 @@ -require 'net/http' -require 'net/https' -require 'uri' +#require 'net/http' +#require 'net/https' +#require 'uri' require 'rubygems' -require 'hpricot' +#require 'hpricot' require 'timeout' +#require 'GData' +require 'gdata' - # Make it easy to use some of the convenience methods using https # -module Net class HTTPS < HTTP - def initialize(address, port = nil) - super(address, port) - self.use_ssl = true - end - end -end +#module Net class HTTPS < HTTP +# def initialize(address, port = nil) +# super(address, port) +# self.use_ssl = true +# end +# end +#end +# +#class GoogleSpreadSheet +# GOOGLE_LOGIN_URL = URI.parse('https://www.google.com/accounts/ClientLogin') +# +# def initialize(spreadsheet_key) +# @spreadsheet_key = spreadsheet_key +# @headers = nil +# @default_sheet = nil +# end +# +# def default_sheet=(numberofsheet) +# @default_sheet = numberofsheet +# end +# +# def authenticate(email, password) +# $VERBOSE = nil +# response = Net::HTTPS.post_form(GOOGLE_LOGIN_URL, +# {'Email' => email, +# 'Passwd' => password, +# 'source' => "formula", +# 'service' => 'wise' }) +# @headers = { 'Authorization' => "GoogleLogin auth=#{response.body.split(/=/).last}", +# 'Content-Type' => 'application/atom+xml' +# } +# end +# +# def evaluate_cell(cell) +# path = "/feeds/cells/#{@spreadsheet_key}/#{@default_sheet}/#{@headers ? "private" : "public"}/basic/#{cell}" +# +# doc = Hpricot(request(path)) +# result = (doc/"content[@type='text']").inner_html +# end +# +# def set_entry(entry) +# path = "/feeds/cells/#{@spreadsheet_key}/#{@default_sheet}/#{@headers ? 'private' : 'public'}/full" +# +# post(path, entry) +# end +# +# def entry(formula, row=1, col=1) +# <<XML +#<?xml version='1.0' ?> +#<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006'> +# <gs:cell row='#{row}' col='#{col}' inputValue='=#{formula}' /> +#</entry> +#XML +# end +# +# def add_to_cell(formula) #puts entry(formula) +# set_entry(entry(formula)) +# end +# +# private +# def request(path) +# response, data = get_http.get(path, @headers) +# data +# end +# +# def post(path, entry) +# get_http.post(path, entry, @headers) +# end +# +# def get_http +# http = Net::HTTP.new('spreadsheets.google.com', 80) +# #http.set_debug_output $stderr +# http +# end +#end -class GoogleSpreadSheet - GOOGLE_LOGIN_URL = URI.parse('https://www.google.com/accounts/ClientLogin') - - def initialize(spreadsheet_key) - @spreadsheet_key = spreadsheet_key - @headers = nil - @default_sheet = nil - end - - def default_sheet=(numberofsheet) - @default_sheet = numberofsheet - end - - def authenticate(email, password) - $VERBOSE = nil - response = Net::HTTPS.post_form(GOOGLE_LOGIN_URL, - {'Email' => email, - 'Passwd' => password, - 'source' => "formula", - 'service' => 'wise' }) - @headers = { 'Authorization' => "GoogleLogin auth=#{response.body.split(/=/).last}", - 'Content-Type' => 'application/atom+xml' - } - end - - def evaluate_cell(cell) - path = "/feeds/cells/#{@spreadsheet_key}/#{@default_sheet}/#{@headers ? "private" : "public"}/basic/#{cell}" - - doc = Hpricot(request(path)) - result = (doc/"content[@type='text']").inner_html - end - - def set_entry(entry) - path = "/feeds/cells/#{@spreadsheet_key}/#{@default_sheet}/#{@headers ? 'private' : 'public'}/full" - - post(path, entry) - end - - def entry(formula, row=1, col=1) - <<XML -<?xml version='1.0' ?> -<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006'> - <gs:cell row='#{row}' col='#{col}' inputValue='=#{formula}' /> -</entry> -XML - end - - def add_to_cell(formula) #puts entry(formula) - set_entry(entry(formula)) - end - - private - def request(path) - response, data = get_http.get(path, @headers) - data - end - - def post(path, entry) - get_http.post(path, entry, @headers) - end - - def get_http - http = Net::HTTP.new('spreadsheets.google.com', 80) - #http.set_debug_output $stderr - http - end -end - class Google < Openoffice TIMEOUT_IN_SECONDS = 2 - def initialize(user, password, spreadsheetkey) + def initialize(user, password, spreadsheetkey, spreadsheetname) @cells_read = false @cell = Hash.new @cell_type = Hash.new - Timeout.timeout(TIMEOUT_IN_SECONDS) { - @gs = GoogleSpreadSheet.new(spreadsheetkey) - @gs.authenticate(user, password) - @default_sheet = nil - } + #Timeout.timeout(TIMEOUT_IN_SECONDS) { + # @gs = GoogleSpreadSheet.new(spreadsheetkey) + # @gs.authenticate(user, password) + # @default_sheet = nil + #} + # alle eigenen Spreadsheets bei Google + # @spreadsheets= GData::Spreadsheet.spreadsheets("emmanuel.pirsch@gmail.com", "secret") # funktioniert anscheinend noch nicht!!!!!!!!! + # ein einzelnes Spreadsheet bei Google + # @spreadsheet= spreadsheet[spreadsheetname] + + #gb = GData::Base.new + #gb.authenticate("thopre@gmail.com","nora3033") + + g = GData::Spreadsheet.new("ttt") + @default_sheet = nil end def sheets -# http://spreadsheets.google.com/feeds/worksheets/ptu6bbahNZpYrdGHwteUNCw/private/full - if DateTime.now < Date.new(2007,6,15) - return ["Sheet eins","Sheet zwei","Sheet drei"] - else - return [] - end + # http://spreadsheets.google.com/feeds/worksheets/ptu6bbahNZpYrdGHwteUNCw/private/full + #if DateTime.now < Date.new(2007,6,15) + # return ["Sheet eins","Sheet zwei","Sheet drei"] + #else + # return [] + #end + @spreadsheet end def default_sheet=(numberofsheet) @gs.default_sheet = numberofsheet end