schedules_controller.rb 671 Bytes
Newer Older
1 2 3 4 5
require 'icalendar'
require 'time'

# Contains functionality for generating schedules.
class SchedulesController < ApplicationController
Zac Wood's avatar
Zac Wood committed
6 7 8
  resource_description do
    short 'Endpoints for generating iCal files'
  end
Zac Wood's avatar
Zac Wood committed
9
  # Render an iCal file containing the schedules of all the
10
  # course sections with the given CRNs.
Zac Wood's avatar
Zac Wood committed
11
  api :GET, '/schedules', 'Generate an iCal file with events for the given CRNs'
Zac Wood's avatar
Zac Wood committed
12
  param :crns, String, desc: 'Comma separated list of CRNs to include as events in the calendar', required: true
13 14 15 16 17 18
  def index
    crns = params["crns"].split ','
    @schedule = Schedule.new crns
    render plain: @schedule.to_ical # render a plaintext iCal file
  end
end