Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ To use the xAPI Java Client include the appropriate XML in the `dependencies` se
</project>
```

### Configuration

The xAPI Java Client has a Spring AutoConfiguration bean which picks up the following properties:

| Property | Description |
| ----------------------------- | ------------------------------------------------------------------ |
| xapi.client.baseUrl | The base url of the LRS endpoint |
| xapi.client.username | Username for basic authorization header |
| xapi.client.password | Password for basic authorization header |
| xapi.client.authorization | Authorization header (has precedence over the username and password properties) |

Properties can be set using any [external configuration](https://docs.spring.io/spring-boot/docs/3.0.4/reference/htmlsingle/#features.external-config.files) method supported by Spring Boot.

If you need more specific customization (eg. your LRS needs specific headers, or you want to set the authorization header dynamically) you can create a custom configurer by implementing the `XapiClientConfigurer` interface.

### Statement Resource

The xAPI Java Client allows applications to store and fetch xAPI [Statements](https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#statements).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import dev.learning.xapi.client.XapiClient;
import dev.learning.xapi.samples.core.ExampleState;
import java.time.Instant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.reactive.function.client.WebClient;

/**
* Sample using xAPI client to delete an activity profile.
Expand All @@ -20,24 +20,11 @@
@SpringBootApplication
public class DeleteActivityProfileApplication implements CommandLineRunner {

private final XapiClient client;

/**
* Constructor for application. In this sample the WebClient.Builder instance is injected by the
* Spring Framework.
* Default xAPI client. Properties are picked automatically from application.properties.
*/
public DeleteActivityProfileApplication(WebClient.Builder webClientBuilder) {

webClientBuilder
// Change for the URL of your LRS
.baseUrl("https://example.com/xapi/")
// Set the Authorization value
.defaultHeader("Authorization", "")

.build();

client = new XapiClient(webClientBuilder);
}
@Autowired
private XapiClient client;

public static void main(String[] args) {
SpringApplication.run(DeleteActivityProfileApplication.class, args).close();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
xapi.client.username = admin
xapi.client.password = password
xapi.client.baseUrl = https://example.com/xapi/
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import dev.learning.xapi.client.XapiClient;
import dev.learning.xapi.samples.core.ExampleState;
import java.time.Instant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.reactive.function.client.WebClient;

/**
* Sample using xAPI client to delete an agent profile.
Expand All @@ -20,24 +20,11 @@
@SpringBootApplication
public class DeleteAgentProfileApplication implements CommandLineRunner {

private final XapiClient client;

/**
* Constructor for application. In this sample the WebClient.Builder instance is injected by the
* Spring Framework.
* Default xAPI client. Properties are picked automatically from application.properties.
*/
public DeleteAgentProfileApplication(WebClient.Builder webClientBuilder) {

webClientBuilder
// Change for the URL of your LRS
.baseUrl("https://example.com/xapi/")
// Set the Authorization value
.defaultHeader("Authorization", "")

.build();

client = new XapiClient(webClientBuilder);
}
@Autowired
private XapiClient client;

public static void main(String[] args) {
SpringApplication.run(DeleteAgentProfileApplication.class, args).close();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
xapi.client.username = admin
xapi.client.password = password
xapi.client.baseUrl = https://example.com/xapi/
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import dev.learning.xapi.client.XapiClient;
import dev.learning.xapi.samples.core.ExampleState;
import java.time.Instant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.reactive.function.client.WebClient;

/**
* Sample using xAPI client to delete a state.
Expand All @@ -20,24 +20,11 @@
@SpringBootApplication
public class DeleteStateApplication implements CommandLineRunner {

private final XapiClient client;

/**
* Constructor for application. In this sample the WebClient.Builder instance is injected by the
* Spring Framework.
* Default xAPI client. Properties are picked automatically from application.properties.
*/
public DeleteStateApplication(WebClient.Builder webClientBuilder) {

webClientBuilder
// Change for the URL of your LRS
.baseUrl("https://example.com/xapi/")
// Set the Authorization value
.defaultHeader("Authorization", "")

.build();

client = new XapiClient(webClientBuilder);
}
@Autowired
private XapiClient client;

public static void main(String[] args) {
SpringApplication.run(DeleteStateApplication.class, args).close();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
xapi.client.username = admin
xapi.client.password = password
xapi.client.baseUrl = https://example.com/xapi/
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import dev.learning.xapi.client.XapiClient;
import dev.learning.xapi.samples.core.ExampleState;
import java.time.Instant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.reactive.function.client.WebClient;

/**
* Sample using xAPI client to delete multiple states.
Expand All @@ -20,24 +20,11 @@
@SpringBootApplication
public class DeleteStatesApplication implements CommandLineRunner {

private final XapiClient client;

/**
* Constructor for application. In this sample the WebClient.Builder instance is injected by the
* Spring Framework.
* Default xAPI client. Properties are picked automatically from application.properties.
*/
public DeleteStatesApplication(WebClient.Builder webClientBuilder) {

webClientBuilder
// Change for the URL of your LRS
.baseUrl("https://example.com/xapi/")
// Set the Authorization value
.defaultHeader("Authorization", "")

.build();

client = new XapiClient(webClientBuilder);
}
@Autowired
private XapiClient client;

public static void main(String[] args) {
SpringApplication.run(DeleteStatesApplication.class, args).close();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
xapi.client.username = admin
xapi.client.password = password
xapi.client.baseUrl = https://example.com/xapi/
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import dev.learning.xapi.client.XapiClient;
import dev.learning.xapi.model.About;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.web.reactive.function.client.WebClient;

/**
* Sample using xAPI client to get about.
Expand All @@ -20,24 +20,11 @@
@SpringBootApplication
public class GetAboutApplication implements CommandLineRunner {

private final XapiClient client;

/**
* Constructor for application. In this sample the WebClient.Builder instance is injected by the
* Spring Framework.
* Default xAPI client. Properties are picked automatically from application.properties.
*/
public GetAboutApplication(WebClient.Builder webClientBuilder) {

webClientBuilder
// Change for the URL of your LRS
.baseUrl("https://example.com/xapi/")
// Set the Authorization value
.defaultHeader("Authorization", "")

.build();

client = new XapiClient(webClientBuilder);
}
@Autowired
private XapiClient client;

public static void main(String[] args) {
SpringApplication.run(GetAboutApplication.class, args).close();
Expand Down
3 changes: 3 additions & 0 deletions samples/get-about/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
xapi.client.username = admin
xapi.client.password = password
xapi.client.baseUrl = https://example.com/xapi/
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import dev.learning.xapi.client.XapiClient;
import dev.learning.xapi.samples.core.ExampleState;
import java.time.Instant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.web.reactive.function.client.WebClient;

/**
* Sample using xAPI client to get an activity profile.
Expand All @@ -21,24 +21,11 @@
@SpringBootApplication
public class GetActivityProfileApplication implements CommandLineRunner {

private final XapiClient client;

/**
* Constructor for application. In this sample the WebClient.Builder instance is injected by the
* Spring Framework.
* Default xAPI client. Properties are picked automatically from application.properties.
*/
public GetActivityProfileApplication(WebClient.Builder webClientBuilder) {

webClientBuilder
// Change for the URL of your LRS
.baseUrl("https://example.com/xapi/")
// Set the Authorization value
.defaultHeader("Authorization", "")

.build();

client = new XapiClient(webClientBuilder);
}
@Autowired
private XapiClient client;

public static void main(String[] args) {
SpringApplication.run(GetActivityProfileApplication.class, args).close();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
xapi.client.username = admin
xapi.client.password = password
xapi.client.baseUrl = https://example.com/xapi/
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import dev.learning.xapi.samples.core.ExampleState;
import java.time.Instant;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.web.reactive.function.client.WebClient;

/**
* Sample using xAPI client to get activity profiles.
Expand All @@ -22,24 +22,11 @@
@SpringBootApplication
public class GetActivityProfilesApplication implements CommandLineRunner {

private final XapiClient client;

/**
* Constructor for application. In this sample the WebClient.Builder instance is injected by the
* Spring Framework.
* Default xAPI client. Properties are picked automatically from application.properties.
*/
public GetActivityProfilesApplication(WebClient.Builder webClientBuilder) {

webClientBuilder
// Change for the URL of your LRS
.baseUrl("https://example.com/xapi/")
// Set the Authorization value
.defaultHeader("Authorization", "")

.build();

client = new XapiClient(webClientBuilder);
}
@Autowired
private XapiClient client;

public static void main(String[] args) {
SpringApplication.run(GetActivityProfilesApplication.class, args).close();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
xapi.client.username = admin
xapi.client.password = password
xapi.client.baseUrl = https://example.com/xapi/
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import java.net.URI;
import java.util.Locale;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.web.reactive.function.client.WebClient;

/**
* Sample using xAPI client to get an activity.
Expand All @@ -24,25 +24,11 @@
@SpringBootApplication
public class GetActivityApplication implements CommandLineRunner {

private final XapiClient client;

/**
* Constructor for application. In this sample the WebClient.Builder instance is injected by the
* Spring Framework.
* Default xAPI client. Properties are picked automatically from application.properties.
*/
public GetActivityApplication(WebClient.Builder webClientBuilder) {

webClientBuilder
// Change for the URL of your LRS
.baseUrl("https://example.com/xapi/")
// Set the Authorization value
.defaultHeader("Authorization", "")

.build();


client = new XapiClient(webClientBuilder);
}
@Autowired
private XapiClient client;

public static void main(String[] args) {
SpringApplication.run(GetActivityApplication.class, args).close();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
xapi.client.username = admin
xapi.client.password = password
xapi.client.baseUrl = https://example.com/xapi/
Loading