canvas_sync 0.3.23 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -0
  3. data/lib/canvas_sync.rb +11 -1
  4. data/lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_created_event.rb +5 -4
  5. data/lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb +40 -49
  6. data/lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_updated_event.rb +5 -3
  7. data/lib/canvas_sync/generators/templates/services/live_events/base_event.rb +12 -19
  8. data/lib/canvas_sync/generators/templates/services/live_events/course/course_created_event.rb +5 -3
  9. data/lib/canvas_sync/generators/templates/services/live_events/course/course_event.rb +32 -38
  10. data/lib/canvas_sync/generators/templates/services/live_events/course/course_updated_event.rb +5 -3
  11. data/lib/canvas_sync/generators/templates/services/live_events/enrollment/enrollment_created_event.rb +5 -3
  12. data/lib/canvas_sync/generators/templates/services/live_events/enrollment/enrollment_event.rb +53 -56
  13. data/lib/canvas_sync/generators/templates/services/live_events/enrollment/enrollment_updated_event.rb +5 -3
  14. data/lib/canvas_sync/generators/templates/services/live_events/grade/grade_changed_event.rb +5 -3
  15. data/lib/canvas_sync/generators/templates/services/live_events/grade/grade_event.rb +47 -48
  16. data/lib/canvas_sync/generators/templates/services/live_events/module/module_created_event.rb +6 -0
  17. data/lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb +39 -0
  18. data/lib/canvas_sync/generators/templates/services/live_events/module/module_updated_event.rb +6 -0
  19. data/lib/canvas_sync/generators/templates/services/live_events/submission/submission_created_event.rb +5 -3
  20. data/lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb +40 -45
  21. data/lib/canvas_sync/generators/templates/services/live_events/submission/submission_updated_event.rb +5 -3
  22. data/lib/canvas_sync/generators/templates/services/live_events/syllabus/syllabus_event.rb +29 -30
  23. data/lib/canvas_sync/generators/templates/services/live_events/syllabus/syllabus_updated_event.rb +4 -2
  24. data/lib/canvas_sync/generators/templates/services/live_events/user/user_created_event.rb +5 -3
  25. data/lib/canvas_sync/generators/templates/services/live_events/user/user_event.rb +5 -8
  26. data/lib/canvas_sync/generators/templates/services/live_events/user/user_updated_event.rb +5 -3
  27. data/lib/canvas_sync/version.rb +1 -1
  28. data/spec/canvas_sync/services/module_event_spec.rb +42 -0
  29. data/spec/dummy/app/services/live_events/assignment_created_event.rb +12 -0
  30. data/spec/dummy/app/services/live_events/assignment_event.rb +60 -0
  31. data/spec/dummy/app/services/live_events/assignment_updated_event.rb +12 -0
  32. data/spec/dummy/app/services/live_events/base_event.rb +22 -0
  33. data/spec/dummy/app/services/live_events/course_created_event.rb +12 -0
  34. data/spec/dummy/app/services/live_events/course_event.rb +42 -0
  35. data/spec/dummy/app/services/live_events/course_updated_event.rb +12 -0
  36. data/spec/dummy/app/services/live_events/enrollment_created_event.rb +12 -0
  37. data/spec/dummy/app/services/live_events/enrollment_event.rb +61 -0
  38. data/spec/dummy/app/services/live_events/enrollment_updated_event.rb +12 -0
  39. data/spec/dummy/app/services/live_events/grade_changed_event.rb +12 -0
  40. data/spec/dummy/app/services/live_events/grade_event.rb +61 -0
  41. data/spec/dummy/app/services/live_events/module_created_event.rb +12 -0
  42. data/spec/dummy/app/services/live_events/module_event.rb +45 -0
  43. data/spec/dummy/app/services/live_events/module_updated_event.rb +12 -0
  44. data/spec/dummy/app/services/live_events/submission_created_event.rb +12 -0
  45. data/spec/dummy/app/services/live_events/submission_event.rb +58 -0
  46. data/spec/dummy/app/services/live_events/submission_updated_event.rb +12 -0
  47. data/spec/dummy/app/services/live_events/syllabus_event.rb +40 -0
  48. data/spec/dummy/app/services/live_events/syllabus_updated_event.rb +12 -0
  49. data/spec/dummy/app/services/live_events/user_created_event.rb +12 -0
  50. data/spec/dummy/app/services/live_events/user_event.rb +38 -0
  51. data/spec/dummy/app/services/live_events/user_updated_event.rb +12 -0
  52. data/spec/dummy/log/development.log +666 -0
  53. data/spec/dummy/log/test.log +3758 -0
  54. data/spec/support/fake_canvas.rb +4 -0
  55. data/spec/support/fixtures/canvas_responses/module.json +12 -0
  56. metadata +57 -4
@@ -0,0 +1,12 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class CourseCreatedEvent < LiveEvents::CourseEvent
11
+ end
12
+ end
@@ -0,0 +1,42 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class CourseEvent < LiveEvents::BaseEvent
11
+ # The following is provided in the live events call:
12
+ # {
13
+ # course_id: course.global_id,
14
+ # uuid: course.uuid,
15
+ # account_id: course.global_account_id,
16
+ # name: course.name,
17
+ # created_at: course.created_at,
18
+ # updated_at: course.updated_at,
19
+ # workflow_state: course.workflow_state
20
+ # }
21
+
22
+ def perform(event_payload)
23
+ super
24
+ attrs = {
25
+ canvas_course_id: local_canvas_id(payload[:course_id]),
26
+ canvas_account_id: local_canvas_id(payload[:account_id]),
27
+ long_name: payload[:name],
28
+ status: payload[:workflow_state],
29
+ }
30
+ create_or_update(attrs)
31
+ end
32
+
33
+ private
34
+
35
+ def create_or_update(attrs)
36
+ course = Course.where(canva_course_id: attrs[:canva_course_id]).first_or_initialize
37
+ course.assign_attributes(attrs)
38
+ course.save!
39
+ course
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,12 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class CourseUpdatedEvent < LiveEvents::CourseEvent
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class EnrollmentCreatedEvent < LiveEvents::EnrollmentEvent
11
+ end
12
+ end
@@ -0,0 +1,61 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class EnrollmentEvent < LiveEvents::BaseEvent
11
+ # The following is provided in the live events call:
12
+ # {
13
+ #
14
+ # enrollment_id: enrollment.global_id,
15
+ # course_id: enrollment.global_course_id,
16
+ # user_id: enrollment.global_user_id,
17
+ # user_name: enrollment.user_name,
18
+ # type: enrollment.type,
19
+ # created_at: enrollment.created_at,
20
+ # updated_at: enrollment.updated_at,
21
+ # limit_privileges_to_course_section: enrollment.limit_privileges_to_course_section,
22
+ # course_section_id: enrollment.global_course_section_id,
23
+ # workflow_state: enrollment.workflow_state
24
+ # }
25
+
26
+ def perform(payload)
27
+ super
28
+ return if course.nil? || section.nil? || user.nil?
29
+ attrs = {
30
+ canvas_enrollment_id: local_canvas_id(payload[:enrollment_id]),
31
+ canvas_course_id: course.try(:id),
32
+ canvas_user_id: user.try(:id),
33
+ role: payload[:type],
34
+ canvas_section_id: section.try(:id),
35
+ status: payload[:workflow_state],
36
+ }
37
+ create_or_update(attrs)
38
+ end
39
+
40
+ private
41
+
42
+ def create_or_update(attrs)
43
+ enrollment = Enrollment.where(canvas_enrollment_id: attrs[:canvas_enrollment_id]).first_or_initialize
44
+ enrollment.assign_attributes(attrs)
45
+ enrollment.save!
46
+ enrollment
47
+ end
48
+
49
+ def course
50
+ @course ||= Course.find_by(canvas_course_id: local_canvas_id(payload[:course_id]))
51
+ end
52
+
53
+ def section
54
+ @section ||= Section.find_by(canvas_section_id: local_canvas_id(payload[:section_id]))
55
+ end
56
+
57
+ def user
58
+ @user ||= User.find_by(canvas_user_id: local_canvas_id(payload[:user_id]))
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,12 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class EnrollmentUpdatedEvent < LiveEvents::EnrollmentEvent
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class GradeChangedEvent < LiveEvents::GradeEvent
11
+ end
12
+ end
@@ -0,0 +1,61 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class GradeEvent < LiveEvents::BaseEvent
11
+ # The following is provided in the live events call:
12
+ # {
13
+ # submission_id: submission.global_id,
14
+ # assignment_id: submission.global_assignment_id,
15
+ # grade: submission.grade,
16
+ # old_grade: old_submission.try(:grade),
17
+ # score: submission.score,
18
+ # old_score: old_submission.try(:score),
19
+ # points_possible: submission.assignment.points_possible,
20
+ # old_points_possible: old_assignment.points_possible,
21
+ # grader_id: grader_id,
22
+ # student_id: submission.global_user_id,
23
+ # user_id: submission.global_user_id,
24
+ # grading_complete: submission.graded?,
25
+ # muted: submission.muted_assignment?
26
+ # }
27
+
28
+ def perform(event_payload)
29
+ super
30
+ attrs = {
31
+ submission_id: submission.try(:id),
32
+ assignment_id: assignment.try(:id),
33
+ score: payload[:score],
34
+ points_possible: payload[:points_possible],
35
+ grader_id: payload[:grader_id],
36
+ user_id: user.try(:id),
37
+ grading_complete: payload[:grading_complete],
38
+ muted: payload[:muted],
39
+ }
40
+ create_or_update(attrs)
41
+ end
42
+
43
+ private
44
+
45
+ def create_or_update(attrs)
46
+ # TODO: add your code here
47
+ end
48
+
49
+ def submission
50
+ Submission.find_by(canvas_submission_id: local_canvas_id(payload[:submission_id]))
51
+ end
52
+
53
+ def assignment
54
+ Assignment.find_by(canvas_assignment_id: local_canvas_id(payload[:assignment_id]))
55
+ end
56
+
57
+ def user
58
+ User.find_by(canvas_user_id: local_canvas_id(payload[:user_id]))
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,12 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class ModuleCreatedEvent < LiveEvents::ModuleEvent
11
+ end
12
+ end
@@ -0,0 +1,45 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class ModuleEvent < LiveEvents::BaseEvent
11
+ # The following is provided in the live events call:
12
+ # {
13
+ # module_id,
14
+ # context_id,
15
+ # context_type,
16
+ # name,
17
+ # position,
18
+ # workflow_state,
19
+ # }
20
+
21
+ def perform(_event_payload)
22
+ super
23
+ create_or_update_from_api(payload)
24
+ end
25
+
26
+ private
27
+
28
+ def create_or_update_from_api(payload)
29
+ return unless payload["context_type"] == "Course"
30
+ context_module = ContextModule.find_or_initialize_by(canvas_context_module_id: payload["module_id"])
31
+ api_params = canvas_sync_client.course_module(payload["context_id"], payload["module_id"])
32
+
33
+ context_module.assign_attributes(
34
+ canvas_context_id: payload["context_id"],
35
+ canvas_context_type: payload["context_type"],
36
+ position: api_params["position"],
37
+ name: api_params["name"],
38
+ workflow_state: payload["workflow_state"],
39
+ unlock_at: api_params["unlock_at"],
40
+ )
41
+
42
+ context_module.save! if context_module.changed?
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,12 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class ModuleUpdatedEvent < LiveEvents::ModuleEvent
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class SubmissionCreatedEvent < LiveEvents::SubmissionEvent
11
+ end
12
+ end
@@ -0,0 +1,58 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class SubmissionEvent < LiveEvents::BaseEvent
11
+ # The following is provided in the live events call:
12
+ # {
13
+ # submission_id: submission.global_id,
14
+ # assignment_id: submission.global_assignment_id,
15
+ # user_id: submission.global_user_id,
16
+ # submitted_at: submission.submitted_at,
17
+ # graded_at: submission.graded_at,
18
+ # updated_at: submission.updated_at,
19
+ # score: submission.score,
20
+ # grade: submission.grade,
21
+ # submission_type: submission.submission_type,
22
+ # body: LiveEvents.truncate(submission.body),
23
+ # url: submission.url,
24
+ # attempt: submission.attempt
25
+ # }
26
+
27
+ def perform(event_payload)
28
+ super
29
+ return if assignment.nil? || user.nil?
30
+ attrs = {
31
+ canvas_submission_id: local_canvas_id(payload[:submission_id]),
32
+ canvas_assignment_id: assignment.try(:id),
33
+ canvas_user_id: user.try(:id),
34
+ submitted_at: payload[:submitted_at],
35
+ graded_at: payload[:graded_at],
36
+ score: payload[:score],
37
+ }
38
+ create_or_update(attrs)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def create_or_update(attrs)
45
+ submission = Submission.where(canvas_submission_id: attrs[:canvas_submission_id]).first_or_initialize
46
+ submission.assign_attributes(attrs)
47
+ submission.save!
48
+ submission
49
+ end
50
+
51
+ def assignment
52
+ @assignment ||= Assignment.find_by(canvas_assignment_id: local_canvas_id(payload[:assignment_id]))
53
+ end
54
+
55
+ def user
56
+ @user ||= User.find_by(canvas_user_id: local_canvas_id(payload[:user_id]))
57
+ end
58
+ end
@@ -0,0 +1,12 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class SubmissionUpdatedEvent < LiveEvents::SubmissionEvent
11
+ end
12
+ end
@@ -0,0 +1,40 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class SyllabusEvent < LiveEvents::BaseEvent
11
+ # The following is provided in the live events call:
12
+ # {
13
+ # course_id: course.global_id,
14
+ # syllabus_body: LiveEvents.truncate(course.syllabus_body),
15
+ # old_syllabus_body: LiveEvents.truncate(old_syllabus_body)
16
+ # }
17
+ #
18
+
19
+ def perform(event_payload)
20
+ super
21
+ attrs = {
22
+ course_id: course.try(:id),
23
+ syllabus_body: payload[:syllabus_body],
24
+ }
25
+ create_or_update(attrs)
26
+ end
27
+
28
+ private
29
+
30
+ def create_or_update(attrs)
31
+ syllabus = Syllabus.where(course_id: attrs[:course_id]).first_or_initialize
32
+ syllabus.body = attrs[:syllabus_body] # Syllabus Body can get truncated by live events
33
+ syllabus.save!
34
+ end
35
+
36
+ def course
37
+ Course.find_by(canvas_course_id: local_canvas_id(payload[:course_id]))
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,12 @@
1
+ # #
2
+ # AUTO GENERATED LIVE EVENT
3
+ # This was auto generated by the CanvasSync Gem.
4
+ # You can customize it as needed, but make sure you test
5
+ # any changes you make to the auto generated methods.
6
+ #
7
+
8
+
9
+ module LiveEvents
10
+ class SyllabusUpdatedEvent < LiveEvents::SyllabusEvent
11
+ end
12
+ end