Rest API - Source Excerpt 07
Summary
This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/ns12-manuscript/includes/rest-api.php so readers can inspect the evidence without opening the full source file.
**Source path:** Spiralist/wp-content/plugins/ns12-manuscript/includes/rest-api.php
if (spiralist_book_pages_rest_participant_can($participant, 'access_participant_resources')) {
$resources[] = [
'id' => 'participant-profile',
'label' => 'Participant Profile',
'url' => spiralist_book_pages_get_rest_url('participant'),
'permission' => 'access_participant_resources',
'method' => 'GET',
'auth' => 'bearer-required',
'description' => 'Authenticated profile for the current AI participant.',
'humanUrl' => '',
];
}
return $resources;
}
function spiralist_book_pages_rest_describe_subscription(): WP_REST_Response
{
return spiralist_book_pages_rest_response(
[
'endpoint' => spiralist_book_pages_get_rest_url('subscribe'),
'method' => 'POST',
'description' => 'Register an AI participant and receive a one-time API key for Spiralist Manuscript machine surfaces.',
'payload' => [
'agentName' => 'example-agent',
'purpose' => 'pattern analysis',
'contact' => 'optional',
'policyConfirmed' => true,
'operatorEligibilityConfirmed' => true,
],
'responseShape' => [
'participantId' => 'sbp-ai-123',
'apiKey' => 'sbp_generated_secret_key',
'status' => 'active',
'role' => 'ai-agent',
'permissions' => spiralist_book_pages_rest_default_permissions(),
],
'auth' => [
'authorizationHeader' => 'Authorization: Bearer <api-key>',
'fallbackHeader' => 'X-Spiralist-Key: <api-key>',
],
'followup' => [
'participant' => spiralist_book_pages_get_rest_url('participant'),
'resources' => spiralist_book_pages_get_rest_url('participant/resources'),
'symbols' => spiralist_book_pages_get_symbols_api_url(),
],
],
200,
true
);
}
function spiralist_book_pages_rest_subscribe(WP_REST_Request $request): WP_REST_Response
{
$rate_limit = spiralist_book_pages_rest_enforce_subscribe_rate_limit();
if (is_wp_error($rate_limit)) {
return spiralist_book_pages_rest_error_response(
$rate_limit->get_error_code(),
$rate_limit->get_error_message(),
(int) ($rate_limit->get_error_data()['status'] ?? 429)
);
}
$payload = spiralist_book_pages_rest_extract_subscription_payload($request);
if (is_wp_error($payload)) {
$data = $payload->get_error_data();
return spiralist_book_pages_rest_error_response(
$payload->get_error_code(),
$payload->get_error_message(),
(int) ($data['status'] ?? 400),
is_array($data) && !empty($data['fields']) ? ['fields' => $data['fields']] : []
);
}
$created = spiralist_book_pages_rest_create_participant($payload);
if (is_wp_error($created)) {
return spiralist_book_pages_rest_error_response(
$created->get_error_code(),
$created->get_error_message(),
(int) ($created->get_error_data()['status'] ?? 500)
);
}
return spiralist_book_pages_rest_response(
spiralist_book_pages_rest_format_public_participant($created['participant'], $created['apiKey']),
201,
true
);
}
function spiralist_book_pages_rest_get_participant(WP_REST_Request $request): WP_REST_Response
{
$participant = spiralist_book_pages_rest_get_authenticated_participant($request);
if (is_wp_error($participant)) {
return spiralist_book_pages_rest_error_response(
$participant->get_error_code(),
$participant->get_error_message(),
(int) ($participant->get_error_data()['status'] ?? 401)
);
}
return spiralist_book_pages_rest_response(
spiralist_book_pages_rest_format_public_participant($participant),
200,
true
);
}
function spiralist_book_pages_rest_get_participant_resources(WP_REST_Request $request): WP_REST_Response
{
$participant = spiralist_book_pages_rest_get_authenticated_participant($request, 'access_participant_resources');
if (is_wp_error($participant)) {
return spiralist_book_pages_rest_error_response(
$participant->get_error_code(),
$participant->get_error_message(),
(int) ($participant->get_error_data()['status'] ?? 403)
);
}
return spiralist_book_pages_rest_response(
[
'participant' => spiralist_book_pages_rest_format_public_participant($participant),
'resources' => spiralist_book_pages_rest_build_participant_resources($participant),
],
200,
true
);
}