Skip to content

Commit 5604389

Browse files
committed
Add example dir, clean up README.md
1 parent 977775c commit 5604389

2 files changed

Lines changed: 67 additions & 28 deletions

File tree

‎README.md‎

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,16 @@ A client-side Java library for the [Matrix](https://matrix.org) protocol.
1010
This library aims to allow authors to build any kind of Matrix program such as a bot or a desktop client, the library
1111
handles all matters of serialization, validation and authentication.
1212

13-
## Quick start
14-
15-
```java
16-
17-
import io.github.hikingc.matrixsdk.api.MatrixAuth;
18-
import io.github.hikingc.matrixsdk.api.MatrixClient;
19-
import io.github.hikingc.matrixsdk.api.auth.TokenMetadata;
20-
import io.github.hikingc.matrixsdk.context.DiscoveryResponse;
21-
22-
MatrixAuth auth = new MatrixAuth(URI.create("https://example.org")); // Set the URI of your Matrix server.
23-
DiscoveryResponse response = auth.fetchWellKnown(); // Fetch well known for future operations
24-
25-
TokenMetadata token = auth.performOAuthLogin(CLIENT_NAME, PORT, DEVICE_ID); // Set configuration parameters
26-
// After doing the login with the server in your browser, you will be returned the tokens...
27-
MatrixClient client = MatrixClient.create(response, token.accessToken()); // Use any service you want!
28-
29-
```
30-
3113
## Feature support
3214

33-
| Service | Capabilities | Status |
34-
|-----------|------------------------------------------------|-----------|
35-
| Rooms | Banning, kicking, room summary, room search | Supported |
36-
| Events | Sending messages, reading room events, `/sync` | Partial |
37-
| User Data | Profile search, profile modification | Supported |
38-
| Filtering | Creating and retrieving filters | Supported |
39-
| Auth | OpenIDConnect handshake | Supported |
15+
| Service | Capabilities | Status |
16+
|----------------------|---------------------------------------------|---------------------|
17+
| Rooms | Banning, kicking, room summary, room search | Supported |
18+
| Events | Sending and reading events, `/sync` | Partial |
19+
| User Data | Profile search, profile modification | Supported |
20+
| Filtering | Creating and retrieving filters | Supported |
21+
| Auth | OpenIDConnect handshake | Partial |
22+
| Capability Awareness | Notify consumers about user capabilities | Not yet implemented |
4023

4124
## Current project status
4225

@@ -50,9 +33,9 @@ The baseline to reach v1.0 is to implement all endpoints that are required in th
5033

5134
1. This project does not handle multimedia resources, it _does_ expose the necessary Objects to handle serialization
5235
(RoomMessage) but consumers are required to bring their own library to pass required metadata.
53-
2. This project does not allow for the creation or hookup of custom event types, for example: `org.custom.type`. It
54-
_does_ recognize these events with `UnknownEvent.java` but consumers will be required to cast to a proper Object
55-
type.
36+
2. This project does not allow for the creation or hookup of custom event types, for setUpClientPrints:
37+
`org.custom.type`. It _does_ recognize these events with `UnknownEvent.java` but consumers will be required to cast
38+
to a proper Object type.
5639
3. Resource serialization/deserialization depends heavily on Jackson 3.0.
5740
4. There is a limit of tolerance to wrongly created events, but in general the library will not attempt to serialize
5841
badly created objects. See: https://github.com/matrix-org/matrix-spec-proposals/pull/2801 on why this is the case.
@@ -61,6 +44,8 @@ The baseline to reach v1.0 is to implement all endpoints that are required in th
6144

6245
Currently, the only way to use this library is to compile it on your own using ```mvn compile```.
6346

47+
Set-up and usage is described in the [examples directory](examples).
48+
6449
### Requirements
6550

6651
- Java 25+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package setUpClientPrints;
2+
3+
import io.github.hikingc.matrixsdk.api.MatrixAuth;
4+
import io.github.hikingc.matrixsdk.api.MatrixClient;
5+
import io.github.hikingc.matrixsdk.api.MatrixClientBuilder;
6+
import io.github.hikingc.matrixsdk.api.auth.TokenMetadata;
7+
import io.github.hikingc.matrixsdk.api.events.RoomInfo;
8+
import io.github.hikingc.matrixsdk.api.events.queries.QueryParametersSync;
9+
import io.github.hikingc.matrixsdk.api.events.sync.Sync;
10+
import io.github.hikingc.matrixsdk.api.identifiers.RoomID;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
13+
14+
import java.net.URI;
15+
import java.net.http.HttpClient;
16+
17+
public class Main {
18+
private static final Logger log = LoggerFactory.getLogger(Main.class);
19+
20+
static void main() {
21+
HttpClient httpClient =
22+
HttpClient.newBuilder().build(); // Create a client, this will do for this example.
23+
MatrixAuth auth =
24+
new MatrixAuth(URI.create("https://example.org"), httpClient); // Set the URI and the client
25+
TokenMetadata res =
26+
auth.performOAuthLogin(
27+
"clienttest", 8080, "defgagagea"); // Perform interactive login (browser needed)
28+
29+
MatrixClient client =
30+
new MatrixClientBuilder()
31+
.setDiscoveryResponse(auth.fetchWellKnown()) // Get .well_known
32+
.setAuthToken(res.accessToken()) // Set up the code
33+
.createMatrixClient();
34+
Sync sync =
35+
client
36+
.events()
37+
.sync(
38+
new QueryParametersSync(null, true, null, null, 100, true)); // Perform operations.
39+
log.info(String.valueOf(sync)); // This endpoint will take a while, you have been warned...
40+
41+
try {
42+
RoomInfo roomInfo =
43+
client
44+
.events()
45+
.getInitialSync(
46+
RoomID.create(
47+
"!foobar:example.org")); // Type safe identifiers, will crash if given wrong
48+
// format.
49+
log.info(roomInfo.visibility());
50+
} catch (IllegalArgumentException e) {
51+
log.info("Room id is bad!, Reason: {}", e.getMessage());
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)