Skip to content

Repository files navigation

scormcloud-api-v2-client

SCORM Cloud Rest API

  • API version: 2.0
    • Build date: 2023-12-14T11:28:58.809-06:00

REST API used for SCORM Cloud integrations.

Automatically generated by the Swagger Codegen

Requirements

Building the API client library requires:

  1. Java 1.7+
  2. Maven/Gradle

Installation

Maven

scormcloud-api-v2-client

Local

To install the API client library to your local Maven repository, simply execute:

mvn clean install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn clean deploy

Refer to the OSSRH Guide for more information.

Maven users

Add this dependency to your project's POM:

<dependency>
<groupId>com.rusticisoftware.cloud.v2.client</groupId>
<artifactId>scormcloud-api-v2-client</artifactId>
<version>4.0.0</version>
<scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project's build file:

compile "com.rusticisoftware.cloud.v2.client:scormcloud-api-v2-client:4.0.0"

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/scormcloud-api-v2-client-4.0.0.jar
  • target/lib/*.jar

Tips and Tricks

Working with headers will require calling the WithHttpInfo version of the function. This allows for grabbing the header directly from the response object:

// Note: This code is specifically designed to not modify any existing dataDispatchApidispatchApi = newDispatchApi();
ApiResponse<Void> response = dispatchApi.updateDispatchesWithHttpInfo(newUpdateDispatchSchema(), null, OffsetDateTime.now(), null, null, null, null, null);
System.out.println(response.getHeaders().get("X-Total-Count"));

Changelog:

Check the changelog for details of what has changed.

Sample Code

importcom.rusticisoftware.cloud.v2.client.ApiClient;
importcom.rusticisoftware.cloud.v2.client.ApiException;
importcom.rusticisoftware.cloud.v2.client.Configuration;
importcom.rusticisoftware.cloud.v2.client.api.ApplicationManagementApi;
importcom.rusticisoftware.cloud.v2.client.api.CourseApi;
importcom.rusticisoftware.cloud.v2.client.api.RegistrationApi;
importcom.rusticisoftware.cloud.v2.client.auth.HttpBasicAuth;
importcom.rusticisoftware.cloud.v2.client.auth.OAuth;
importcom.rusticisoftware.cloud.v2.client.model.*;
importjava.io.File;
importjava.io.IOException;
importjava.time.OffsetDateTime;
importjava.util.Arrays;
importjava.util.Collections;
importjava.util.List;
publicclassScormCloud_Java_Sample {
// ScormCloud API credentials// Note: These are not the same credentials used to log in to ScormCloudfinalstaticStringAPP_ID = "APP_ID";
finalstaticStringSECRET_KEY = "SECRET_KEY";
// Sample values for datafinalstaticStringCOURSE_PATH = "/PATH/TO/COURSE/RunTimeAdvancedCalls_SCORM20043rdEdition.zip";
finalstaticStringCOURSE_ID = "JAVA_SAMPLE_COURSE";
finalstaticStringLEARNER_ID = "JAVA_SAMPLE_COURSE_LEARNER";
finalstaticStringREGISTRATION_ID = "JAVA_SAMPLE_COURSE_REGISTRATION";
// String used for output formattingfinalstaticStringOUTPUT_BORDER = "---------------------------------------------------------\n";
/** * This sample will consist of: * 1. Creating a course. * 2. Registering a learner for the course. * 3. Building a link for the learner to take the course. * 4. Getting the learner's progress after having taken the course. * 5. Viewing all courses and registrations. * 6. Deleting all of the data created via this sample. * * All input variables used in this sample are defined up above. */publicstaticvoidmain(String[] args) throwsApiException {
// Configure HTTP basic authorization: APP_NORMALHttpBasicAuthAPP_NORMAL = (HttpBasicAuth) Configuration.getDefaultApiClient().getAuthentication("APP_NORMAL");
APP_NORMAL.setUsername(APP_ID);
APP_NORMAL.setPassword(SECRET_KEY);
ScormCloud_Java_Samplesc = newScormCloud_Java_Sample();
try
{
// Create a course and a registrationCourseSchemacourseDetails = sc.createCourse(COURSE_ID, COURSE_PATH);
sc.createRegistration(COURSE_ID, LEARNER_ID, REGISTRATION_ID);
// Show details of the newly imported courseSystem.out.println("Newly Imported Course Details: ");
System.out.println(courseDetails);
// Create the registration launch linkStringlaunchLink = sc.buildLaunchLink(REGISTRATION_ID);
// Show the launch linkSystem.out.println(OUTPUT_BORDER);
System.out.printf("Launch Link: %s%n", launchLink);
System.out.println("Navigate to the url above to take the course. Hit enter once complete.");
try {
System.in.read();
} catch (IOExceptione) {
e.printStackTrace();
}
// Get the results for the registrationRegistrationSchemaregistrationProgress = sc.getResultForRegistration(REGISTRATION_ID);
// Show details of the registration progressSystem.out.println(OUTPUT_BORDER);
System.out.println("Registration Progress: ");
System.out.println(registrationProgress);
// Get information about all the courses in ScormCloudList<CourseSchema> courseList = sc.getAllCourses();
// Show details of the coursesSystem.out.println(OUTPUT_BORDER);
System.out.println("Course List: ");
for (CourseSchemacourse: courseList)
{
System.out.println(course);
}
// Get information about all the registrations in ScormCloudList<RegistrationSchema> registrationList = sc.getAllRegistrations();
// Show details of the registrationsSystem.out.println(OUTPUT_BORDER);
System.out.println("Registration List: ");
for (RegistrationSchemaregistration: registrationList)
{
System.out.println(registration);
}
} catch (ApiException | IllegalArgumentExceptione) {
System.out.println(e.toString());
} finally {
// Delete all the data created by this samplesc.cleanUp(COURSE_ID, REGISTRATION_ID);
}
}
/** * Sets the default OAuth token passed with all calls to the API. * * If a token is created with limited scope (i.e. read:registration), * calls that require a different permission set will error. Either a * new token needs to be generated with the correct scope, or the * default access token can be reset to null. This would cause the * request to be made with basic auth credentials (appId/ secret key) * instead. * * Additionally, you could create a new configuration object and set * the token on that object instead of the default access token. This * configuration would then be passed into the Api object: * * ApiClient apiClient = new ApiClient(); * TokenRequestSchema tokenRequest = new TokenRequestSchema() * .permissions(new PermissionsSchema().scopes(Arrays.asList("write:course", "read:course"))) * .expiry(OffsetDateTime.now().plusMinutes(2)); * apiClient.setAccessToken(applicationManagementApi.createToken(tokenRequest).getResult()); * CourseApi courseApi = new CourseApi(apiClient); * * Any calls that would use this CourseApi instance would then have the * write:course and read:course permissions passed automatically, but * other instances would be unaffected and continue to use other means * of authorization. * * @param scopes List of permissions for calls made with the token. */privatevoidconfigureOAuth(List<String> scopes) throwsApiException {
ApplicationManagementApiappManagementApi = newApplicationManagementApi();
// Set permissions and expiry time of the tokenOffsetDateTimeexpiry = OffsetDateTime.now().plusMinutes(2);
PermissionsSchemapermissions = newPermissionsSchema()
.scopes(scopes);
// Make the request to get the OAuth tokenTokenRequestSchematokenRequest = newTokenRequestSchema()
.expiry(expiry)
.permissions(permissions);
StringResultSchematokenResult = appManagementApi.createToken(tokenRequest);
// Set the default access token used with further API requests.// To remove the token, reset the accessToken of// Configuration.getDefaultApiClient().getAuthentication("OAUTH")// back to null before the next call.OAuthOAUTH = (OAuth) Configuration.getDefaultApiClient().getAuthentication("OAUTH");
OAUTH.setAccessToken(tokenResult.getResult());
}
/** * Creates a course by uploading the course from your local machine. * Courses are a package of content for a learner to consume. * * Other methods for importing a course exist. Check the documentation * for additional ways of importing a course. * * @param courseId Id that will be used to identify the course. * @param coursePath Path to the course being uploaded. * @return Detailed information about the newly uploaded course. */publicCourseSchemacreateCourse(StringcourseId, StringcoursePath) throwsApiException {
// (Optional) Further authenticate via OAuth token access// configureOAuth(Arrays.asList("write:course", "read:course"));// This call will use OAuth with the "write:course" scope// if configured. Otherwise the basic auth credentials will be usedCourseApicourseApi = newCourseApi();
StringResultSchemajobId = courseApi.createUploadAndImportCourseJob(courseId, null, null, null, null, newFile(coursePath));
// This call will use OAuth with the "read:course" scope// if configured. Otherwise the basic auth credentials will be usedImportJobResultSchemajobResult = courseApi.getImportJobStatus(jobId.getResult());
while (jobResult.getStatus() == ImportJobResultSchema.StatusEnum.RUNNING) {
try {
Thread.sleep(1000);
} catch (InterruptedExceptionignored) {
Thread.currentThread().interrupt();
}
jobResult = courseApi.getImportJobStatus(jobId.getResult());
}
if (jobResult.getStatus() == ImportJobResultSchema.StatusEnum.ERROR)
thrownewIllegalArgumentException("Course is not properly formatted: " + jobResult.getMessage());
returnjobResult.getImportResult().getCourse();
}
/** * Creates a registration allowing the learner to consume the course * content. A registration is the link between a learner and a single * course. * * @param courseId Id of the course to register the learner for. * @param learnerId Id that will be used to identify the learner. * @param registrationId Id that will be used to identify the registration. */publicvoidcreateRegistration(StringcourseId, StringlearnerId, StringregistrationId) throwsApiException {
// (Optional) Further authenticate via OAuth token access// configureOAuth(Collections.singletonList("write:registration"));RegistrationApiregistrationApi = newRegistrationApi();
LearnerSchemalearner = newLearnerSchema()
.id(learnerId);
CreateRegistrationSchemaregistration = newCreateRegistrationSchema()
.courseId(courseId)
.learner(learner)
.registrationId(registrationId);
registrationApi.createRegistration(registration, null);
}
/** * Builds a url allowing the learner to access the course. * * This sample will build the launch link and print it out. It will then * pause and wait for user input, allowing you to navigate to the course * to generate sample learner progress. Once this step has been reached, * hitting the enter key will continue program execution. * * @param registrationId Id of the registration the link is being built for. * @return Link for the learner to launch the course. */publicStringbuildLaunchLink(StringregistrationId) throwsApiException {
// (Optional) Further authenticate via OAuth token access// configureOAuth(Collections.singletonList("read:registration"));RegistrationApiregistrationApi = newRegistrationApi();
LaunchLinkRequestSchemasettings = newLaunchLinkRequestSchema()
.redirectOnExitUrl("Message");
LaunchLinkSchemalaunchLink = registrationApi.buildRegistrationLaunchLink(registrationId, settings);
returnlaunchLink.getLaunchLink();
}
/** * Gets information about the progress of the registration. * * For the most up-to-date results, you should implement our postback * mechanism. The basic premise is that any update to the registration * would cause us to send the updated results to your system. * * More details can be found in the documentation: * https://cloud.scorm.com/docs/v2/guides/postback/ * * @param registrationId Id of the registration to get results for. * @return Detailed information about the registration's progress. */publicRegistrationSchemagetResultForRegistration(StringregistrationId) throwsApiException {
// (Optional) Further authenticate via OAuth token access// configureOAuth(Collections.singletonList("read:registration"));RegistrationApiregistrationApi = newRegistrationApi();
RegistrationSchemaprogress = registrationApi.getRegistrationProgress(registrationId, null, null, null);
returnprogress;
}
/** * Gets information about all courses. The result received from the API * call is a paginated list, meaning that additional calls are required * to retrieve all the information from the API. This has already been * accounted for in the sample. * * @return List of detailed information about all of the courses. */publicList<CourseSchema> getAllCourses() throwsApiException {
// (Optional) Further authenticate via OAuth token access// configureOAuth(Collections.singletonList("read:course"));// Additional filters can be provided to this call to get a subset// of all courses.CourseApicourseApi = newCourseApi();
CourseListSchemaresponse = courseApi.getCourses(null, null, null, null, null, null, null, null, null, null, null);
// This call is paginated, with a token provided if more results existList<CourseSchema> courseList = response.getCourses();
while (response.getMore() != null)
{
response = courseApi.getCourses(null, null, null, null, null, null, null, response.getMore(), null, null, null);
courseList.addAll(response.getCourses());
}
returncourseList;
}
/** * Gets information about the registration progress for all * registrations. The result received from the API call is a paginated * list, meaning that additional calls are required to retrieve all the * information from the API. This has already been accounted for in the * sample. * * This call can be quite time-consuming and tedious with lots of * registrations. If you find yourself making lots of calls to this * endpoint, it might be worthwhile to look into registration postbacks. * * More details can be found in the documentation: * https://cloud.scorm.com/docs/v2/guides/postback/ * * @return List of detailed information about all of the registrations. */publicList<RegistrationSchema> getAllRegistrations() throwsApiException {
// (Optional) Further authenticate via OAuth token access// configureOAuth(Collections.singletonList("read:registration"));// Additional filters can be provided to this call to get a subset// of all registrations.RegistrationApiregistrationApi = newRegistrationApi();
RegistrationListSchemaresponse = registrationApi.getRegistrations(null, null, null, null, null, null, null, null, null, null, null, null, null, null);
// This call is paginated, with a token provided if more results existList<RegistrationSchema> registrationList = response.getRegistrations();
while (response.getMore() != null)
{
response = registrationApi.getRegistrations(null, null, null, null, null, null, null, null, null, response.getMore(), null, null, null, null);
registrationList.addAll(response.getRegistrations());
}
returnregistrationList;
}
/** * Deletes all of the data generated by this sample. * * This code is run even if the program has errored out, providing a * "clean slate" for every run of this sample. * * It is not necessary to delete registrations if the course * they belong to has been deleted. Deleting the course will * automatically queue deletion of all registrations associated with * the course. There will be a delay between when the course is deleted * and when the registrations for the course have been removed. The * registration deletion has been handled here to prevent scenarios * where the registration hasn't been deleted yet by the time the * sample has been rerun. * * @param courseId Id of the course to delete. * @param registrationId Id of the registration to delete. */publicvoidcleanUp(StringcourseId, StringregistrationId) throwsApiException {
// (Optional) Further authenticate via OAuth token access// configureOAuth(Arrays.asList("delete:course", "delete:registration"));// This call will use OAuth with the "delete:course" scope// if configured. Otherwise the basic auth credentials will be usedCourseApicourseApi = newCourseApi();
courseApi.deleteCourse(courseId);
// The code below is to prevent race conditions if the// sample is run in quick successions.// This call will use OAuth2 with the "delete:registration" scope// if configured. Otherwise the basic auth credentials will be used.RegistrationApiregistrationApi = newRegistrationApi();
registrationApi.deleteRegistration(registrationId);
}
}

About

Swagger Generated Java Client for SCORM Cloud API v2

Resources

Stars

4 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages