Sha256: 55d160790c1eb51b898bc755c5a884d1d73478affe530b7d4bedd3cdaa273a7f

Contents?: true

Size: 1.05 KB

Versions: 24

Compression:

Stored size: 1.05 KB

Contents

# <%= autogenerated_event_warning %>

module LiveEvents
  class ModuleItemEvent < LiveEvents::BaseEvent
    # The following is provided in the live events call:
    # {
    #   module_item_id,
    #   module_id,
    #   context_id,
    #   context_type,
    #   position,
    #   workflow_state,
    # }

    def perform(_event_payload)
      super
      create_or_update_from_api(payload)
    end

    private

    def create_or_update_from_api(payload)
      context_module_item = ContextModuleItem.find_or_initialize_by(canvas_context_module_item_id: payload["module_item_id"])
      api_params = canvas_sync_client.module_item(payload["context_id"], payload["module_id"], payload["module_item_id"])

      context_module_item.assign_attributes(
        canvas_context_module_id: payload["module_id"],
        position: payload["position"],
        workflow_state: payload["workflow_state"],
        content_id: api_params["content_id"],
        content_type: api_params["type"],
      )

      context_module_item.save! if context_module_item.changed?
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

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