Sha256: f999a79fc5855a1c3dca330b002c028aa72a686f5fb1e424038759935bf3ead7

Contents?: true

Size: 1.07 KB

Versions: 25

Compression:

Stored size: 1.07 KB

Contents

# <%= autogenerated_event_warning %>

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_context_module_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

25 entries across 25 versions & 1 rubygems

Version Path
canvas_sync-0.9.4 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.9.3 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.9.2 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.9.1 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.9.0 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.8.4 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.8.3 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.8.2 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.8.1 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.8.0 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.7.3 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.7.2 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.7.1 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.7.0 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.6.4 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.6.3 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.6.2 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.6.1 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.6.0 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb
canvas_sync-0.5.4 lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb