Package edu.ucsb.cs.scaffold.services
Class PrairieLearnService
java.lang.Object
edu.ucsb.cs.scaffold.services.PrairieLearnService
Thin wrapper around the PrairieLearn REST API (see https://docs.prairielearn.com/api/),
authenticated per call with a user's PrairieLearn personal access token. Callers handle
PrairieLearn's HTTP errors (401 = bad token, 403/404 = unknown or inaccessible course instance),
which RestTemplate surfaces as HttpClientErrorException subclasses.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne assessment from the/course_instances/{id}/assessmentsresponse — the fields PlAssessment stores (issue #71).static final recordThe parts of a course instance response this app uses; the numeric id is the crucial one, since it cannot be obtained from the GitHub repo. -
Constructor Summary
ConstructorsConstructorDescriptionPrairieLearnService(org.springframework.web.client.RestTemplate restTemplate, String plApiBase, long retryInitialSleepSeconds, int retryMax, long rateLimitSleepInitialMs) -
Method Summary
Modifier and TypeMethodDescriptiongetAssessments(long instanceId, String token) Fetches all assessments of a course instance, e.g.getCourseInstance(long instanceId, String token) Fetches one course instance by its numeric id, e.g.
-
Constructor Details
-
PrairieLearnService
public PrairieLearnService(org.springframework.web.client.RestTemplate restTemplate, @Value("${pl.api.base:https://us.prairielearn.com/pl/api/v1}") String plApiBase, @Value("${PL_SERVICE_RETRY_INITIAL_SLEEP_SECONDS:8}") long retryInitialSleepSeconds, @Value("${PL_SERVICE_RETRY_MAX:3}") int retryMax, @Value("${PL_SERVICE_RATE_LIMIT_SLEEP_INITIAL_MS:1000}") long rateLimitSleepInitialMs)
-
-
Method Details
-
getCourseInstance
Fetches one course instance by its numeric id, e.g./course_instances/213133. Returns null when the response has no usable body.- Parameters:
instanceId- PrairieLearn's numeric course instance idtoken- the user's PrairieLearn PAT (plaintext)
-
getAssessments
Fetches all assessments of a course instance, e.g./course_instances/213133/assessments. Entries without anassessment_idare skipped.- Parameters:
instanceId- PrairieLearn's numeric course instance idtoken- the user's PrairieLearn PAT (plaintext)
-