Update README.md
This commit is contained in:
parent
2b06e8d1ef
commit
b42c9ab1e9
77
README.md
77
README.md
@ -1,70 +1,29 @@
|
|||||||
# Matrix Client SDK for GLib
|
# Matrix Client SDK for GLib
|
||||||
|
|
||||||
This is a Matrix client-server SDK for GLib >= 2.40. As of now it
|
This is a [Matrix.org](http://matrix.org/) client-server SDK for
|
||||||
mostly mimics the official Python SDK. The API and ABI are both very
|
GLib >= 2.40. It contains both raw API calls and a signal based
|
||||||
volatile as of now; don’t rely on any specific feature until the API
|
asynchronous client. The API and ABI are both very volatile as of now;
|
||||||
is frozen.
|
don’t rely on any specific feature until the API is frozen.
|
||||||
|
|
||||||
|
The main interfaces are `MatrixAPI` and
|
||||||
|
`MatrixClient`. `MatrixHTTPAPI` and `MatrixHTTPClient` implement these
|
||||||
|
interfaces, respectively and can communicate with an HTTP based
|
||||||
|
homeserver. If a new protocol becomes supported oficially, a new `API`
|
||||||
|
and `Client` class will be added.
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
The SDK provides 2 layers of interaction. The low-level layer just wraps the
|
The SDK provides two layers of interaction. The low-level layer
|
||||||
raw HTTP API calls. The high-level layer wraps the low-level layer and provides
|
(`MatrixAPI` implementations like `MatrixHTTPAPI`) just wraps the raw
|
||||||
an object model to perform actions on.
|
API calls. The high-level layer (`MatrixClient` implementations like
|
||||||
|
`MatrixHTTPClient`) is a `GMainLoop` based asynchronous object that
|
||||||
|
emits `GObject` signals and uses the low-level layer to provide an
|
||||||
|
object model to perform actions on.
|
||||||
|
|
||||||
## Client
|
## Client
|
||||||
|
|
||||||
``` c
|
The `MatrixClient` interface is not fully planned yet.
|
||||||
|
|
||||||
#include <matrix-glib/matrix-client.h>
|
|
||||||
|
|
||||||
gchar *token = NULL;
|
|
||||||
MatrixClient *client = matrix_client_new("http://localhost:8008", NULL);
|
|
||||||
matrix_client_register_with_password(client, "foobar", "monkey”);
|
|
||||||
g_object_get(client, "token", &token, NULL);
|
|
||||||
room = matrix_client_create_room(client, "my_room_alias");
|
|
||||||
matrix_room_send_text(room, "Hello!");
|
|
||||||
```
|
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
```c
|
For a full blown example, see [test-client.c](src/test-client.c).
|
||||||
#include <matrix-glib/matrix-api.h>
|
|
||||||
|
|
||||||
static void
|
|
||||||
sync_finished(MatrixAPI *api,
|
|
||||||
MatrixAPIResponse *response,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
/* Do something with the response */
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
message_sent(MatrixAPI *api,
|
|
||||||
MatrixAPIResponse *response,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
/* Do something with the response */
|
|
||||||
}
|
|
||||||
|
|
||||||
matrix = matrix_api_new("https://matrix.org", "some_token");
|
|
||||||
g_signal_connect(G_OBJECT(api),
|
|
||||||
"request-finished",
|
|
||||||
G_CALLBACK(sync_finished),
|
|
||||||
NULL);
|
|
||||||
matrix_api_initial_sync(matrix, sync_finished);
|
|
||||||
matrix_api_send_message(matrix, "!roomid:matrix.org", "Hello!", message_sent);
|
|
||||||
```
|
|
||||||
|
|
||||||
# Structure
|
|
||||||
|
|
||||||
The SDK is split into two modules: `MatrixAPI` and `MatrixClient`.
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
This contains the raw HTTP API calls and has minimal business logic. You can
|
|
||||||
set the access token (`token`) to use for requests as well as set a custom
|
|
||||||
transaction ID (`txn_id`) which will be incremented for each request.
|
|
||||||
|
|
||||||
## Client
|
|
||||||
|
|
||||||
This encapsulates the API module and provides object models such as `Room`.
|
|
||||||
|
Loading…
Reference in New Issue
Block a user