Add checkin notifications for starting lectures
This commit is contained in:
parent
9e8cf93b1a
commit
04caed2783
@ -1,4 +1,16 @@
|
|||||||
class LectureController < ApplicationController
|
class LectureController < ApplicationController
|
||||||
|
# TODO: Pass the CSRF token to Pushcut
|
||||||
|
skip_before_action :verify_authenticity_token, only: [:checkin]
|
||||||
|
|
||||||
|
def checkin
|
||||||
|
lecture = Lecture.find(params[:id])
|
||||||
|
|
||||||
|
Toggl::start_time_entry(
|
||||||
|
description: lecture.title,
|
||||||
|
project_id: lecture.course.toggl_project,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
lecture = Lecture.find(params[:id])
|
lecture = Lecture.find(params[:id])
|
||||||
|
|
||||||
|
|||||||
18
app/jobs/lecture_checkin_job.rb
Normal file
18
app/jobs/lecture_checkin_job.rb
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
class LectureCheckinJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
|
||||||
|
def perform(*args)
|
||||||
|
lecture = Lecture.find_by(start_time: Time.now - 5.minutes..Time.now + 5.minutes)
|
||||||
|
return if lecture.empty?
|
||||||
|
|
||||||
|
puts(HTTParty.post(
|
||||||
|
"https://api.pushcut.io/2Kdtb5V7SoDXQOPxCJetk/notifications/Checkin",
|
||||||
|
body: {
|
||||||
|
input: lecture.id.to_s,
|
||||||
|
text: lecture.title,
|
||||||
|
title: "Checkin to #{lecture.course.title}"
|
||||||
|
}.to_json,
|
||||||
|
headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
|
||||||
|
))
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,7 +1,7 @@
|
|||||||
module Panopto
|
module Panopto
|
||||||
# @param [String] folder_id
|
# @param [String] folder_id
|
||||||
def self.list_folder(folder_id)
|
def self.list_folder(folder_id)
|
||||||
HTTParty.get("https://lectures.joshuacoles.me/list", query: {
|
HTTParty.get("https://lectures.joshuacoles.me/api/list", query: {
|
||||||
folderId: folder_id
|
folderId: folder_id
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|||||||
@ -13,6 +13,8 @@ module LectureAttendanceManager
|
|||||||
|
|
||||||
config.active_job.queue_adapter = :sidekiq
|
config.active_job.queue_adapter = :sidekiq
|
||||||
|
|
||||||
|
config.hosts << "lectures.joshuacoles.me"
|
||||||
|
|
||||||
# Configuration for the application, engines, and railties goes here.
|
# Configuration for the application, engines, and railties goes here.
|
||||||
#
|
#
|
||||||
# These settings can be overridden in specific environments using the files
|
# These settings can be overridden in specific environments using the files
|
||||||
|
|||||||
@ -13,4 +13,6 @@ Rails.application.routes.draw do
|
|||||||
post '/lectures/:id/start', to: 'lecture#start', as: :lectures_start
|
post '/lectures/:id/start', to: 'lecture#start', as: :lectures_start
|
||||||
post '/lectures/:id/start_preparation', to: 'lecture#start_preparation', as: :lecture_start_preparation
|
post '/lectures/:id/start_preparation', to: 'lecture#start_preparation', as: :lecture_start_preparation
|
||||||
post '/lectures/:id/start_review', to: 'lecture#start_review', as: :lecture_start_review
|
post '/lectures/:id/start_review', to: 'lecture#start_review', as: :lecture_start_review
|
||||||
|
|
||||||
|
post '/lectures/:id/checkin', to: 'lecture#checkin', as: :lecture_checkin
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,3 +11,7 @@ production:
|
|||||||
# These are the cron jobs
|
# These are the cron jobs
|
||||||
:scheduler:
|
:scheduler:
|
||||||
:schedule:
|
:schedule:
|
||||||
|
:lecture_checkin_job:
|
||||||
|
cron: '15 * * * 1,2,3,4,5'
|
||||||
|
class: 'LectureCheckinJob'
|
||||||
|
queue: default
|
||||||
|
|||||||
7
test/jobs/lecture_checkin_job_test.rb
Normal file
7
test/jobs/lecture_checkin_job_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class LectureCheckinJobTest < ActiveJob::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue
Block a user