Class | GoogleCalendar::Service |
In: |
lib/googlecalendar/service.rb
|
Parent: | ServiceBase |
This class interacts with google calendar service. If you want to use ClientLogin for authentication, use this class. If you want to use AuthSub, use ServiceAuthSub.
AUTH_PATH | = | "/accounts/ClientLogin" | Server Path to authenticate | |
CALENDAR_LIST_PATH | = | "http://www.google.com/calendar/feeds/" | URL to get calendar list |
# File lib/googlecalendar/service.rb, line 31 31: def initialize(email, pass) 32: @email = email 33: @pass = pass 34: @session = nil 35: @cookie = nil 36: @auth = nil 37: end
get the list of user‘s calendars and returns http response object
# File lib/googlecalendar/service.rb, line 20 20: def calendar_list 21: logger.info("-- calendar list st --") if logger 22: auth unless @auth 23: uri = URI.parse(CALENDAR_LIST_PATH + @email) 24: res = do_get(uri, {}) 25: logger.info("-- calendar list en(#{res.message}) --") if logger 26: res 27: end
# File lib/googlecalendar/service.rb, line 62 62: def add_authorize_header(header) 63: header["Authorization"] = "GoogleLogin auth=#{@auth}" 64: end
# File lib/googlecalendar/service.rb, line 40 40: def auth 41: https = Net::HTTP.new(AUTH_SERVER, 443, @@proxy_addr, @@proxy_port, @@proxy_user, @@proxy_pass) 42: https.use_ssl = true 43: https.verify_mode = OpenSSL::SSL::VERIFY_NONE 44: head = {'Content-Type' => 'application/x-www-form-urlencoded'} 45: logger.info "-- auth st --" if logger 46: https.start do |w| 47: res = w.post(AUTH_PATH, "Email=#{@email}&Passwd=#{@pass}&source=company-app-1&service=cl", head) 48: logger.debug res if logger 49: if res.body =~ /Auth=(.+)/ 50: @auth = $1 51: else 52: if logger 53: logger.fatal(res) 54: logger.fatal(res.body) 55: end 56: raise AuthenticationFailed 57: end 58: end 59: logger.info "-- auth en --" if logger 60: end