State Resource

Manages learner state for an activity.

createState

Creates or merges into a state document by the agent, activity identifier and state identifier.

Example

const agent: Agent = {
  objectType: "Agent",
  name: "Test Agent",
  mbox: "mailto:test@agent.com"
};
const activityId: string = "https://example.com/activities/test-activity";
const stateId: string = activityId + "/states/myStateId";
const state: DocumentJson = {
  myKey: "myValue"
};

xapi.createState({
  agent: agent,
  activityId: activityId,
  stateId: stateId,
  state: state
});

Parameters

Returns

This method returns an AxiosPromise with empty success data if successful.

setState

Creates or overwrites a state document by the agent, activity identifier and state identifier.

Example

const agent: Agent = {
  objectType: "Agent",
  name: "Test Agent",
  mbox: "mailto:test@agent.com"
};
const activityId: string = "https://example.com/activities/test-activity";
const stateId: string = activityId + "/states/myStateId";
const state: Document = {
  myKey: "myValue"
};

xapi.setState(agent, activityId, stateId, state);

Parameters

Returns

This method returns an AxiosPromise with empty success data if successful.

getStates

Gets an array of state identifiers by the agent and activity identifier.

Example

const agent: Agent = {
  objectType: "Agent",
  name: "Test Agent",
  mbox: "mailto:test@agent.com"
};
const activityId: string = "https://example.com/activities/test-activity";

xapi.getStates({
  agent: agent,
  activityId: activityId
}).then((result: AxiosResponse<string[]>) => {
  const states: string[] = result.data;
  console.log(states); // ["https://example.com/activities/test-activity/states/myStateId"]
});

Parameters

Returns

This method returns an AxiosPromise with the success data containing an array of state identifiers if successful.

getState

Gets a state document by the agent, activity identifier and the state identifier.

Example

const agent: Agent = {
  objectType: "Agent",
  name: "Test Agent",
  mbox: "mailto:test@agent.com"
};
const activityId: string = "https://example.com/activities/test-activity";
const stateId: string = activityId + "/states/myStateId";

xapi.getState({
  agent: agent,
  activityId: activityId,
  stateId: stateId
}).then((result: AxiosResponse<Document>) => {
  const state = result.data;
  // do stuff with state
});

Parameters

Returns

This method returns an AxiosPromise with the success data containing the stored Document if successful.

deleteState

Deletes a state document by the agent, activity identifier and the state identifier.

Example

const agent: Agent = {
  objectType: "Agent",
  name: "Test Agent",
  mbox: "mailto:test@agent.com"
};
const activityId: string = "https://example.com/activities/test-activity";
const stateId: string = activityId + "/states/myStateId";

xapi.deleteState({
  agent: agent,
  activityId: activityId,
  stateId: stateId
});

Parameters

Returns

This method returns an AxiosPromise with empty success data if successful.

deleteStates

Deletes all state documents by the agent and activity identifier.

Example

const agent: Agent = {
  objectType: "Agent",
  name: "Test Agent",
  mbox: "mailto:test@agent.com"
};
const activityId: string = "https://example.com/activities/test-activity";

xapi.deleteStates({
  agent: agent,
  activityId: activityId
});

Parameters

Returns

This method returns an AxiosPromise with empty success data if successful.

Last updated