Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
0c5d1ba
Add model module from start.spring.io
Dec 12, 2022
6b41777
wip
Jan 11, 2023
fdddf02
Update xapi-client/src/main/java/dev/learning/xapi/client/XapiClient.…
thomasturrell Jan 16, 2023
0351b13
fix pom (this change can be overridden)
Jan 16, 2023
d5886be
fix pom
Jan 16, 2023
2bb5d61
working state endpoint requests
Selindek Jan 18, 2023
1c95190
add improvements
Selindek Jan 18, 2023
82ec854
add improvements
Selindek Jan 18, 2023
2d3707a
more improvements
Selindek Jan 18, 2023
b42b7a0
fix
Selindek Jan 18, 2023
c7c9f48
Merge branch 'main' into add-xapi-client
Selindek Jan 18, 2023
d94566b
fix
Selindek Jan 18, 2023
07ae77c
Merge branch 'add-xapi-client' of https://github.com/BerryCloud/xapi-…
Selindek Jan 18, 2023
4fc7771
fsi
Selindek Jan 18, 2023
e79e085
Change author
Jan 19, 2023
74afef7
Remove unnecessary brackets from superbuilder annotations
Jan 19, 2023
e6cf23a
Configure code coverage
Jan 19, 2023
5bccb42
Use builder for builder name
Jan 19, 2023
5ee2181
Add agent consumer builder to StatesRequest
Jan 19, 2023
26982ca
Should use NonNull instead of NotNull
Jan 19, 2023
ab3a2ff
Add builder method for activityId which accepts a String
Jan 20, 2023
d4c164c
Work in progress but works with request builder
Jan 20, 2023
06b87fe
wip
Jan 20, 2023
81b58af
Merge branch 'main' into add-xapi-client
thomasturrell Jan 23, 2023
b43e3f4
tip
Jan 24, 2023
a299fac
stuff not compling for a while
Jan 24, 2023
d1a2791
this compiles
Jan 24, 2023
f4d14c9
still complies
Jan 24, 2023
7679c90
still complies
Jan 24, 2023
681c518
basic tests on requests
Jan 24, 2023
85a46d5
clear test
Jan 24, 2023
da7e62d
fixed checkstyle
Jan 24, 2023
f88cf49
wip
Jan 24, 2023
d2b291a
blar
Jan 24, 2023
3bbb200
assorted rubbish
Jan 26, 2023
0621e5a
wip
Jan 27, 2023
ca42b59
sort of ok
Jan 27, 2023
0fe0198
tip
Jan 27, 2023
14f7cd3
top
Jan 30, 2023
f4849ff
closer
Jan 30, 2023
fef0945
tip
Jan 30, 2023
1759a78
tidy
Jan 31, 2023
08a54c6
Merge remote-tracking branch 'origin/main' into add-xapi-client
Feb 2, 2023
9a18cbd
bosh
Feb 2, 2023
55027f7
tip
Feb 3, 2023
fac7337
added get but messy
Feb 3, 2023
0d47d8c
stuff
Feb 3, 2023
d6e5e5d
reasonable state
Feb 6, 2023
4d20918
tidy
Feb 6, 2023
a86d136
wip
Feb 7, 2023
54409e0
Tip
Feb 7, 2023
931e3ca
Merge branch 'main' into add-xapi-client-simple
thomasturrell Feb 7, 2023
084b73b
fix
Feb 7, 2023
7a54f66
Merge branch 'add-xapi-client-simple' of https://github.com/BerryClou…
Feb 7, 2023
bf9b0fc
tip
Feb 8, 2023
6a745c8
tip
Feb 8, 2023
2868426
tip
Feb 8, 2023
20aea42
tip
Feb 8, 2023
69a3260
tip
Feb 8, 2023
65b239b
Tip
Feb 9, 2023
bbc0b72
private
Feb 9, 2023
bb0c527
tip
Feb 9, 2023
65c2c78
tip
Feb 9, 2023
b80d8e3
tip
Feb 9, 2023
c0ec512
tip
Feb 9, 2023
953fd64
tip
Feb 9, 2023
df40e91
sonar test
Feb 9, 2023
1a38b21
tip
Feb 9, 2023
94d7525
hearders
Feb 9, 2023
75931b7
d
Feb 9, 2023
bea4f39
tip
Feb 9, 2023
43afed4
stuff
Feb 9, 2023
f7c9328
documentation
Feb 9, 2023
67cfe6f
t
Feb 9, 2023
948e2d2
d
Feb 9, 2023
82555df
d
Feb 9, 2023
64a47e4
fix broken tests
Feb 10, 2023
689e029
tip
Feb 10, 2023
0c77915
pop
Feb 10, 2023
0cd08db
tip
Feb 10, 2023
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
109 changes: 106 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,112 @@

xAPI Java helps you to create applications that send or receive xAPI [Statements](https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#statements) or [Documents](https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#10-documents).

There are two projects in this [Monorepo](https://en.wikipedia.org/wiki/Monorepo), xAPI Client and xAPI Model.

Both the xAPI client and xAPI Model use a [fluent interface](https://en.wikipedia.org/wiki/Fluent_interface). Objects are [immutable](https://en.wikipedia.org/wiki/Immutable_object).

## xAPI Java Client

The xAPI Java Client can be used by learning record providers (LRP) to communicate with learning record stores (LRS) or a system which follows the LRS requirements of one or more of the xAPI resources.

### Getting started

To use the xAPI Client include the appropriate XML in the `dependencies` section of your `pom.xml`, as shown in the following example:

```xml
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>getting-started</artifactId>
<!-- ... -->
<dependencies>
<!-- ... -->
<dependency>
<groupId>dev.learning.xapi</groupId>
<artifactId>xapi-client</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies>
</project>
```

### State Resource

The xAPI Client allows applications to store, change, fetch, or delete [state documents](https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Communication.md#23-state-resource).

#### Getting a state

Example:

```java
final var request = client.getState(r -> r.activityId("https://example.com/activity/1")

.agent(a -> a.name("A N Other").mbox("another@example.com"))

.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")

.stateId("bookmark"), String.class)

.block();

final String state = request.getBody();
```

#### Posting a state

Example:

```java
client.postState(r -> r.activityId("https://example.com/activity/1")

.agent(a -> a.name("A N Other").mbox("another@example.com"))

.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")

.stateId("bookmark")

.state("Hello World!"))

.block();
```

#### Putting a state

Example:

```java
client.putState(r -> r.activityId("https://example.com/activity/1")

.agent(a -> a.name("A N Other").mbox("another@example.com"))

.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")

.stateId("bookmark")

.state("Hello World!"))

.block();
```

#### Deleting a state

Example:

```java
client.deleteState(r -> r.activityId("https://example.com/activity/1")

.agent(a -> a.name("A N Other").mbox("another@example.com"))

.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")

.stateId("bookmark"))

.block();
```


## xAPI Java Model

The xAPI Model has a [fluent interface](https://en.wikipedia.org/wiki/Fluent_interface). Objects are [immutable](https://en.wikipedia.org/wiki/Immutable_object).
The xAPI model can be used by clients that send xAPI data or by servers that receive xAPI data.

### Getting started

Expand All @@ -20,7 +123,7 @@ To use the xAPI Model include the appropriate XML in the `dependencies` section
<dependency>
<groupId>dev.learning.xapi</groupId>
<artifactId>xapi-model</artifactId>
<version>1.0.1</version>
<version>1.0.3</version>
</dependency>
</dependencies>
</project>
Expand Down Expand Up @@ -95,7 +198,7 @@ final String json = objectMapper.writeValueAsString(statement);

```

### Creating a new statment using an existing statement as template
### Creating a new statement using an existing statement as template

Example:

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@

<modules>
<module>xapi-model</module>
<module>xapi-client</module>
</modules>

<build>
Expand Down
3 changes: 3 additions & 0 deletions xapi-client/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Suppress code coverage on Lombok annotations
lombok.addLombokGeneratedAnnotation = true
lombok.builder.className = Builder
61 changes: 61 additions & 0 deletions xapi-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.learning.xapi</groupId>
<artifactId>xapi-build</artifactId>
<version>1.0.3-SNAPSHOT</version>
</parent>

<artifactId>xapi-client</artifactId>

<name>xAPI Client</name>
<description>learning.dev xAPI Client</description>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>dev.learning.xapi</groupId>
<artifactId>xapi-model</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-resolver-dns-native-macos</artifactId>
<classifier>osx-aarch_64</classifier>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2016-2023 Berry Cloud Ltd. All rights reserved.
*/

package dev.learning.xapi.client;

import lombok.experimental.SuperBuilder;
import org.springframework.http.HttpMethod;

/**
* Request for deleting a single State document.
*
* @see <a href=
* "https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Communication.md#single-document-put--post--get--delete">Single
* State Document DELETE</a>
*
* @author István Rátkai (Selindek)
*/
@SuperBuilder
public class DeleteStateRequest extends StateRequest {

@Override
protected HttpMethod getMethod() {
return HttpMethod.DELETE;
}

/**
* Builder for DeleteStateRequest.
*/
public abstract static class Builder<C extends DeleteStateRequest, B extends Builder<C, B>>
extends StateRequest.Builder<C, B> {

// This static class extends the lombok builder.

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2016-2023 Berry Cloud Ltd. All rights reserved.
*/

package dev.learning.xapi.client;

import lombok.experimental.SuperBuilder;
import org.springframework.http.HttpMethod;

/**
* Request for deleting multiple State documents.
*
* @see <a href=
* "https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Communication.md#multiple-document-delete">Multiple
* State Document DELETE</a>
*
* @author István Rátkai (Selindek)
*/
@SuperBuilder
public class DeleteStatesRequest extends StatesRequest {

@Override
protected HttpMethod getMethod() {
return HttpMethod.DELETE;
}

/**
* Builder for DeleteStatesRequest.
*/
public abstract static class Builder<C extends DeleteStatesRequest, B extends Builder<C, B>>
extends StatesRequest.Builder<C, B> {

// This static class extends the lombok builder.

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2016-2023 Berry Cloud Ltd. All rights reserved.
*/

package dev.learning.xapi.client;

import lombok.experimental.SuperBuilder;
import org.springframework.http.HttpMethod;

/**
* Request for getting a single State document.
*
* @see <a href=
* "https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Communication.md#single-document-put--post--get--delete">Single
* State Document GET</a>
*
* @author István Rátkai (Selindek)
*/
@SuperBuilder
public class GetStateRequest extends StateRequest {

@Override
protected HttpMethod getMethod() {
return HttpMethod.GET;
}

/**
* Builder for GetStateRequest.
*/
public abstract static class Builder<C extends GetStateRequest, B extends Builder<C, B>>
extends StateRequest.Builder<C, B> {

// This static class extends the lombok builder.

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2016-2023 Berry Cloud Ltd. All rights reserved.
*/

package dev.learning.xapi.client;

import java.time.Instant;
import java.util.Map;
import java.util.Optional;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import org.springframework.http.HttpMethod;
import org.springframework.web.util.UriBuilder;

/**
* Request for getting multiple State documents.
*
* @see <a href=
* "https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Communication.md#multiple-document-get">Multiple
* State Document GET</a>
*
* @author István Rátkai (Selindek)
*/
@SuperBuilder
@Getter
public class GetStatesRequest extends StatesRequest {

/**
* Only ids of states stored since the specified instant (exclusive) are returned.
*/
private final Instant since;

@Override
protected HttpMethod getMethod() {
return HttpMethod.GET;
}

@Override
protected UriBuilder url(UriBuilder uriBuilder, Map<String, Object> queryParams) {

return super.url(uriBuilder, queryParams).queryParamIfPresent("since",
Optional.ofNullable(since));

}

/**
* Builder for DeleteStateRequest.
*/
public abstract static class Builder<C extends GetStatesRequest, B extends Builder<C, B>>
extends StatesRequest.Builder<C, B> {

// This static class extends the lombok builder.

}

}
Loading