Sha256: dbb9e26581e8b8bc50441f28edd504732b8b62167688d531de3c072460a8ad05

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 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 ModuleEvent < LiveEvents::BaseEvent
    # The following is provided in the live events call:
    # {
    #   module_id,
    #   context_id,
    #   context_type,
    #   name,
    #   position,
    #   workflow_state,
    # }

    def perform(_event_payload)
      super
      create_or_update_from_api(payload)
    end

    private

    def create_or_update_from_api(payload)
      return unless payload["context_type"] == "Course"
      context_module = ContextModule.find_or_initialize_by(canvas_id: payload["module_id"])
      api_params = canvas_sync_client.course_module(payload["context_id"], payload["module_id"])

      context_module.assign_attributes(
        canvas_context_id: payload["context_id"],
        canvas_context_type: payload["context_type"],
        position: api_params["position"],
        name: api_params["name"],
        workflow_state: payload["workflow_state"],
        unlock_at: api_params["unlock_at"],
      )

      context_module.save! if context_module.changed?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
canvas_sync-0.10.2 spec/dummy/app/services/live_events/module_event.rb
canvas_sync-0.10.0 spec/dummy/app/services/live_events/module_event.rb