Ruby on rails 如何从指定日期删除Google日历中的所有事件?
我正在使用ruby处理Google日历 我面临的唯一问题是从谷歌日历中删除事件 我在上面提到的github中找到了一个删除事件的示例。但我们需要传递事件id。如何使用下面的代码从指定日期删除google日历中的所有事件 代码:Ruby on rails 如何从指定日期删除Google日历中的所有事件?,ruby-on-rails,ruby,google-calendar-api,Ruby On Rails,Ruby,Google Calendar Api,我正在使用ruby处理Google日历 我面临的唯一问题是从谷歌日历中删除事件 我在上面提到的github中找到了一个删除事件的示例。但我们需要传递事件id。如何使用下面的代码从指定日期删除google日历中的所有事件 代码: require File.dirname(__FILE__) + '/../shared.rb' g = GData.new puts 'login' token = g.login('REPLACE_WITH_YOUR_MAIL@gmail.com', 'REPLAC
require File.dirname(__FILE__) + '/../shared.rb'
g = GData.new
puts 'login'
token = g.login('REPLACE_WITH_YOUR_MAIL@gmail.com', 'REPLACE_WITH_YOUR_PASSWORD')
puts "token: #{token}"
event = {:title=>'title',
:content=>'content',
:author=>'pub.cog',
:email=>'pub.cog@gmail.com',
:where=>'Toulouse,France',
:startTime=>'2009-06-20T15:00:00.000Z',
:endTime=>'2009-06-20T17:00:00.000Z'}
create_response = g.new_event(event)
puts create_response.body
puts 'delete_event'
# TODO GET id from new_event response
id='http://www.google.com/calendar/feeds/default/private/full/pgvgjdnh43g3bo0emnpfg0gnr4'
response = g.delete_event(id)
puts 'done'
网址:
require File.dirname(__FILE__) + '/../shared.rb'
g = GData.new
puts 'login'
token = g.login('REPLACE_WITH_YOUR_MAIL@gmail.com', 'REPLACE_WITH_YOUR_PASSWORD')
puts "token: #{token}"
event = {:title=>'title',
:content=>'content',
:author=>'pub.cog',
:email=>'pub.cog@gmail.com',
:where=>'Toulouse,France',
:startTime=>'2009-06-20T15:00:00.000Z',
:endTime=>'2009-06-20T17:00:00.000Z'}
create_response = g.new_event(event)
puts create_response.body
puts 'delete_event'
# TODO GET id from new_event response
id='http://www.google.com/calendar/feeds/default/private/full/pgvgjdnh43g3bo0emnpfg0gnr4'
response = g.delete_event(id)
puts 'done'
请分享你的想法,如果我们可以这样做与其他插件
提前感谢:)在github上的搜索显示,这似乎是更受欢迎的宝石(如果不是标准的话)。它也有更好的文档记录和组织 这就是我想到的:
require 'google_calendar'
cal = Google::Calendar.new(:username => 'username@gmail.com',
:password => 'password',
:app_name => 'delete_events')
cal.events.each { |event|
event.delete if Time.parse(event.start_time) >= Time.new(2011,10,14)
}
parse将每个事件的开始时间转换为ruby可以理解的格式,然后将其与给定日期2011年10月14日进行比较。如果事件在事件发生时或之后,则会将其删除。要在执行之前删除事件,请执行以下操作:
if Time.parse(event.start_time) <= Time.new(2011,10,14)