Ltix.DeepLinking.ContentItem protocol (Ltix v0.1.0)

Copy Markdown View Source

Protocol for serializing content items in Deep Linking responses.

Ltix implements this protocol for the five standard content item types and for plain maps (as an escape hatch for one-off custom types). Implement this protocol on your own struct when you need a reusable custom content item type:

defmodule MyApp.ProctoredExam do
  defstruct [:url, :title, :duration_minutes]

  defimpl Ltix.DeepLinking.ContentItem do
    def item_type(_item), do: "https://myapp.example.com/proctored_exam"

    def to_json(item) do
      %{
        "type" => "https://myapp.example.com/proctored_exam",
        "url" => item.url,
        "title" => item.title,
        "https://myapp.example.com/duration" => item.duration_minutes
      }
    end
  end
end

The platform's accept_types must include your custom type string.

Summary

Types

t()

All the types that implement this protocol.

Functions

Return the content item type string (e.g., "ltiResourceLink").

Serialize the content item to a JSON-compatible map.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

item_type(content_item)

@spec item_type(t()) :: String.t()

Return the content item type string (e.g., "ltiResourceLink").

to_json(content_item)

@spec to_json(t()) :: %{required(String.t()) => any()}

Serialize the content item to a JSON-compatible map.