Skip to content

Instantly share code, notes, and snippets.

@gdeest
Created October 1, 2012 08:38
Show Gist options
  • Save gdeest/3810356 to your computer and use it in GitHub Desktop.
Save gdeest/3810356 to your computer and use it in GitHub Desktop.
Ical Filter
require 'icalendar'
require 'camping'
require 'net/http'
require 'uri'
Camping.goes :IcalFilter
module IcalFilter::Controllers
class Index < R '/'
def url
"http://plannings.univ-rennes1.fr/ade/custom/modules/plannings/direct_cal.jsp?resources=1127,1623,1034&calType=ical&firstDate=2012-09-01&lastDate=2013-07-15&login=cal&password=visu&projectId=31"
end
def modules
["MF", "ADM", "ISI", "PEV"]
end
def get
@headers['Content-Type'] = 'text/calendar; charset=utf-8'
@headers['Content-Disposition'] = 'attachment; filename="filtered-ical.ics"'
resp = Net::HTTP.get(URI(url))
cal = Icalendar.parse(resp)
cal.each do |c|
c.events.delete_if {|e| modules.member? e.summary}
end
cal.to_ical
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment