Last active
August 29, 2015 14:23
-
-
Save ljwolford/a2b0400be064403b2574 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.gson.JsonObject; | |
import gov.adlnet.xapi.client.ActivityClient; | |
import gov.adlnet.xapi.client.StatementClient; | |
import gov.adlnet.xapi.model.*; | |
import java.io.IOException; | |
import java.net.URISyntaxException; | |
import java.util.HashMap; | |
import java.util.UUID; | |
public class jxapiExample { | |
public static void main(String[] args) throws URISyntaxException, IOException { | |
StatementClient client = new StatementClient("https://lrs.adlnet.gov/xapi/", "jXAPI", "password"); | |
String statementId = UUID.randomUUID().toString(); | |
Agent ag = new Agent("John Doe", "mailto:jd@example.com"); | |
Activity act = new Activity("http://testactivity.com/session"); | |
Statement stmt = new Statement(ag, Verbs.experienced(), act); | |
stmt.setId(statementId); | |
boolean putResp = client.putStatement(stmt, statementId); | |
if (putResp){ | |
System.out.println("Sent statement with ID: "+ statementId +" to LRS"); | |
Statement collection = client.get(statementId); | |
System.out.println(String.format("Received statement with ID: "+ statementId +" from LRS:")); | |
System.out.println(collection.toString()); | |
} | |
else{ | |
System.out.println("Error with sending statement"); | |
} | |
StatementResult result = client.filterByVerb(Verbs.attempted()).limitResults(5).getStatements(); | |
System.out.println("Results from LRS querying by verb and limiting to 5 statements:"); | |
System.out.println(result.getStatements()); | |
String activityID = "http://example.test.activity.com"; | |
String profileID = "test_profile_id"; | |
ActivityClient act_client = new ActivityClient("https://lrs.adlnet.gov/xapi/", "jXAPI", "password"); | |
JsonObject act_profile_content = new JsonObject(); | |
act_profile_content.addProperty("testkey", "test profile value"); | |
ActivityProfile act_profile = new ActivityProfile(activityID, profileID); | |
act_profile.setProfile(act_profile_content); | |
HashMap<String, String> putEtag = new HashMap<String, String>(); | |
putEtag.put("If-Match", "*"); | |
boolean actResp = act_client.putActivityProfile(act_profile, putEtag); | |
if (actResp){ | |
System.out.println("Sent activity profile with activityID: "+ activityID +" and profileID: " + profileID); | |
JsonObject returnedProfile = act_client.getActivityProfile(new ActivityProfile(activityID, profileID)); | |
System.out.println("Returned activity profile with contents:"); | |
System.out.println(returnedProfile); | |
} | |
else{ | |
System.out.println("Error with sending activity profile"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment