Ltix.GradeService (Ltix v0.1.0)

Copy Markdown View Source

Manage line items, post scores, and read results from a platform's gradebook using the Assignment and Grade Services (AGS) v2.0.

AGS has two workflows depending on the launch claim:

Coupled — the platform creates a single line item for the resource link. The tool posts scores against that line item directly.

{:ok, client} = Ltix.GradeService.authenticate(launch_context)
:ok = Ltix.GradeService.post_score(client, score)

Programmatic — the tool manages its own line items and can create, update, or delete them.

{:ok, client} = Ltix.GradeService.authenticate(launch_context)
{:ok, items} = Ltix.GradeService.list_line_items(client)
{:ok, item} = Ltix.GradeService.create_line_item(client,
  label: "Quiz 1", score_maximum: 100
)
:ok = Ltix.GradeService.post_score(client, score, line_item: item)

Summary

Functions

Acquire an OAuth token for the grade service.

Create a new line item.

Fetch a single line item.

Fetch results for a line item.

Fetch all line items from the container endpoint.

Post a score for a user.

Update a line item.

Functions

authenticate(context_or_registration, opts \\ [])

@spec authenticate(
  Ltix.LaunchContext.t() | Ltix.Registration.t(),
  keyword()
) :: {:ok, Ltix.OAuth.Client.t()} | {:error, Exception.t()}

Acquire an OAuth token for the grade service.

Accepts a %LaunchContext{} or a %Registration{}. With a launch context, the endpoint and scopes are extracted from the AGS claim. With a registration, pass the endpoint via the :endpoint option.

From a launch context

{:ok, client} = Ltix.GradeService.authenticate(launch_context)

From a registration

{:ok, client} = Ltix.GradeService.authenticate(registration,
  endpoint: %AgsEndpoint{
    lineitems: "https://lms.example.com/lineitems",
    scope: ["https://purl.imsglobal.org/spec/lti-ags/scope/lineitem"]
  }
)

Options (launch context)

Options (registration)

authenticate!(context_or_registration, opts \\ [])

Same as authenticate/2 but raises on error.

create_line_item(client, opts)

@spec create_line_item(
  Ltix.OAuth.Client.t(),
  keyword()
) :: {:ok, Ltix.GradeService.LineItem.t()} | {:error, Exception.t()}

Create a new line item.

Options

  • :label (String.t/0) - Required. Human-readable label.

  • :score_maximum (number/0) - Required. Maximum score (must be > 0).

  • :resource_link_id (String.t/0) - Bind to a resource link.

  • :resource_id (String.t/0) - Tool's resource identifier.

  • :tag (String.t/0) - Qualifier tag.

  • :start_date_time (String.t/0) - ISO 8601 with timezone.

  • :end_date_time (String.t/0) - ISO 8601 with timezone.

  • :grades_released (boolean/0) - Hint about releasing grades.

  • :extensions (map/0) - Extension properties keyed by fully qualified URLs. The default value is %{}.

delete_line_item(client, line_item_or_url, opts \\ [])

@spec delete_line_item(
  Ltix.OAuth.Client.t(),
  Ltix.GradeService.LineItem.t() | String.t(),
  keyword()
) ::
  :ok | {:error, Exception.t()}

Delete a line item.

Accepts a %LineItem{} struct or a URL string. Returns :ok on success.

By default, refuses to delete the platform-coupled line item (the lineitem URL from the launch claim). Pass force: true to override.

Options

  • :force (boolean/0) - Delete even if this is the coupled line item from the launch claim. The default value is false.

get_line_item(client, opts \\ [])

@spec get_line_item(
  Ltix.OAuth.Client.t(),
  keyword()
) :: {:ok, Ltix.GradeService.LineItem.t()} | {:error, Exception.t()}

Fetch a single line item.

Options

get_results(client, opts \\ [])

@spec get_results(
  Ltix.OAuth.Client.t(),
  keyword()
) :: {:ok, [Ltix.GradeService.Result.t()]} | {:error, Exception.t()}

Fetch results for a line item.

GETs {lineitem}/results. Follows all rel="next" pagination links and returns a list of %Result{} structs.

Options

list_line_items(client, opts \\ [])

@spec list_line_items(
  Ltix.OAuth.Client.t(),
  keyword()
) :: {:ok, [Ltix.GradeService.LineItem.t()]} | {:error, Exception.t()}

Fetch all line items from the container endpoint.

Follows all rel="next" pagination links and returns a flat list of %LineItem{} structs.

Options

  • :resource_link_id (String.t/0) - Filter to line items bound to this resource link.

  • :resource_id (String.t/0) - Filter by the tool's resource identifier.

  • :tag (String.t/0) - Filter by tag.

  • :per_page (integer/0) - Page size hint.

post_score(client, score, opts \\ [])

@spec post_score(Ltix.OAuth.Client.t(), Ltix.GradeService.Score.t(), keyword()) ::
  :ok | {:error, Exception.t()}

Post a score for a user.

The score is POSTed to {lineitem}/scores. When no :line_item option is given, uses the endpoint's lineitem URL (coupled flow).

Options

update_line_item(client, item)

@spec update_line_item(Ltix.OAuth.Client.t(), Ltix.GradeService.LineItem.t()) ::
  {:ok, Ltix.GradeService.LineItem.t()} | {:error, Exception.t()}

Update a line item.

PUTs the full line item to its id URL. Callers should GET first to avoid overwriting fields they did not intend to change.