Sha256: 0f08fc2b66ad97fd2af3f727d7d4d2f186b02e18fe15cb0c096fce8097b73754

Contents?: true

Size: 1.72 KB

Versions: 27

Compression:

Stored size: 1.72 KB

Contents

# #
# AUTO GENERATED LIVE EVENT
# This was auto generated by the CanvasSync Gem.
# You can customize it as needed, but make sure you test
# any changes you make to the auto generated methods.
#


module LiveEvents
  class SubmissionEvent < LiveEvents::BaseEvent
    # The following is provided in the live events call:
    # {
    #     submission_id: submission.global_id,
    #     assignment_id: submission.global_assignment_id,
    #     user_id: submission.global_user_id,
    #     submitted_at: submission.submitted_at,
    #     graded_at: submission.graded_at,
    #     updated_at: submission.updated_at,
    #     score: submission.score,
    #     grade: submission.grade,
    #     submission_type: submission.submission_type,
    #     body: LiveEvents.truncate(submission.body),
    #     url: submission.url,
    #     attempt: submission.attempt
    # }

    def perform(event_payload)
      super
      return if assignment.nil? || user.nil?
      attrs = {
        canvas_submission_id: local_canvas_id(payload[:submission_id]),
        canvas_assignment_id: assignment.try(:id),
        canvas_user_id: user.try(:id),
        submitted_at: payload[:submitted_at],
        graded_at: payload[:graded_at],
        score: payload[:score],
      }
      create_or_update(attrs)
    end
  end

  private

  def create_or_update(attrs)
    submission = Submission.where(canvas_submission_id: attrs[:canvas_submission_id]).first_or_initialize
    submission.assign_attributes(attrs)
    submission.save!
    submission
  end

  def assignment
    @assignment ||= Assignment.find_by(canvas_assignment_id: local_canvas_id(payload[:assignment_id]))
  end

  def user
    @user ||= User.find_by(canvas_user_id: local_canvas_id(payload[:user_id]))
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
canvas_sync-0.10.2 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.10.0 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.9.4 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.9.3 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.9.2 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.9.1 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.9.0 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.8.4 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.8.3 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.8.2 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.8.1 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.8.0 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.7.3 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.7.2 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.7.1 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.7.0 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.6.4 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.6.3 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.6.2 spec/dummy/app/services/live_events/submission_event.rb
canvas_sync-0.6.1 spec/dummy/app/services/live_events/submission_event.rb