Class PrairieLearnService

java.lang.Object
edu.ucsb.cs.scaffold.services.PrairieLearnService

@Service public class PrairieLearnService extends Object
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.
  • 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

      public PrairieLearnService.CourseInstanceInfo getCourseInstance(long instanceId, String token)
      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 id
      token - the user's PrairieLearn PAT (plaintext)
    • getAssessments

      public List<PrairieLearnService.AssessmentInfo> getAssessments(long instanceId, String token)
      Fetches all assessments of a course instance, e.g. /course_instances/213133/assessments. Entries without an assessment_id are skipped.
      Parameters:
      instanceId - PrairieLearn's numeric course instance id
      token - the user's PrairieLearn PAT (plaintext)