Ltix.MembershipsService.Member (Ltix v0.2.0)

Copy Markdown View Source

A single member in a roster response from the memberships service.

Each member has a user_id (matching sub from launch JWTs) and roles (parsed into %Role{} structs). Additional fields like name, email, and picture depend on platform consent. Fields Ltix does not recognize, such as platform-specific extensions, are in extensions with their original JSON keys.

Examples

{:ok, member} = Ltix.MembershipsService.Member.from_json(%{
  "user_id" => "user-1",
  "roles" => ["http://purl.imsglobal.org/vocab/lis/v2/membership#Learner"],
  "name" => "Jane Doe",
  "email" => "jane@example.edu"
})

member.user_id
#=> "user-1"

member.name
#=> "Jane Doe"

hd(member.roles).name
#=> :learner

Summary

Functions

Parse a member from a JSON map in a membership container response.

Serialize a member to a map with the JSON keys of a membership container response.

Types

t()

@type t() :: %Ltix.MembershipsService.Member{
  email: String.t() | nil,
  extensions: %{optional(String.t()) => term()} | nil,
  family_name: String.t() | nil,
  given_name: String.t() | nil,
  lis_person_source_id: String.t() | nil,
  lti_1_1_legacy_user_id: String.t() | nil,
  message: [Ltix.LaunchClaims.t()] | nil,
  middle_name: String.t() | nil,
  name: String.t() | nil,
  picture: String.t() | nil,
  roles: [Ltix.LaunchClaims.Role.t()],
  status: :active | :inactive | :deleted,
  unrecognized_roles: [String.t()],
  user_id: String.t()
}

Functions

from_json(json)

@spec from_json(map()) :: {:ok, t()} | {:error, Exception.t()}

Parse a member from a JSON map in a membership container response.

Returns {:ok, member} on success or {:error, exception} if required fields are missing or invalid.

to_map(member)

@spec to_map(t()) :: map()

Serialize a member to a map with the JSON keys of a membership container response.

Fields that are nil are omitted, and extensions are merged in. The message section is not included.

Examples

iex> member = %Ltix.MembershipsService.Member{
...>   user_id: "user-1",
...>   status: :active,
...>   name: "Jane Doe",
...>   roles: [Ltix.LaunchClaims.Role.from_atom(:learner)]
...> }
iex> Ltix.MembershipsService.Member.to_map(member)
%{
  "user_id" => "user-1",
  "status" => "Active",
  "name" => "Jane Doe",
  "roles" => ["http://purl.imsglobal.org/vocab/lis/v2/membership#Learner"]
}