Question

I am trying to parse a webcal link

webcal://www.facebook.com/ical/b.php?uid=13301632&key=asdgagaweg

in a Ruby on Rails app so I can customize the event entries. I have looked into both RiCal and icalendar but neither show any support for reading a calendar feed (webcal://).

Are there any Rails libraries that support parsing webcal addresses? If not, how should I go about creating my own parser?

Was it helpful?

Solution

webcal is just an unofficial URI scheme for accessing icalendar documents. You can get the calendar using http and parse it using one of several icalendar plugins:

require 'net/http'
uri = URI('http://www.facebook.com/ical/b.php?uid=13301632&key=asdgagaweg')
calendar = Net::HTTP.get(uri)

For alternative ways to perform the http get request: How make a HTTP request using Ruby on Rails?

Then parse the response using your favourite plug-in:

icalendar:

cal = icalendar.parse(calendar).first

vPim:

cal = Vpim::Icalendar.decode(calendar).first  

ri_cal:

cal = RiCal.parse_string(calendar).first
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top