16 unstable releases (7 breaking)

0.7.0 Aug 11, 2021
0.6.0 Jun 21, 2021
0.5.0 May 16, 2021
0.5.0-alpha.1 Jan 2, 2021
0.0.0 Jan 5, 2017

#479 in Web programming

Download history 41/week @ 2021-08-10 32/week @ 2021-08-17 21/week @ 2021-08-24 1/week @ 2021-08-31 16/week @ 2021-09-07 16/week @ 2021-09-14 8/week @ 2021-09-21 44/week @ 2021-09-28 36/week @ 2021-10-05 42/week @ 2021-10-12 7/week @ 2021-10-19 11/week @ 2021-10-26 17/week @ 2021-11-02 15/week @ 2021-11-09 12/week @ 2021-11-16 10/week @ 2021-11-23

54 downloads per month
Used in 3 crates

MIT license

465KB
10K SLoC

ruma-client

crates.io page docs.rs page license: MIT

ruma-client is a low-level Matrix client library for Rust.

Status

This project is a work in progress and not ready for production usage yet. If you are looking to build a client application or a bot, you are likely going to have a better time using the Matrix Rust SDK, which also builds on the other Ruma crates but provides a higher-level API.


lib.rs:

A minimal Matrix client library.

Usage

Begin by creating a Client, selecting one of the type aliases from ruma_client::http_client for the generic parameter. For the client API, there are login and registration methods provided for the client (feature client-api):

# // HACK: "ignore" the doctest here because client.log_in needs client-api feature.
// type MatrixClient = ruma_client::Client<ruma_client::http_client::_>;
# type MatrixClient = ruma_client::Client<ruma_client::http_client::Dummy>;
# let work = async {
let homeserver_url = "https://example.com".parse().unwrap();
let client = MatrixClient::new(homeserver_url, None);

let session = client
    .log_in("@alice:example.com", "secret", None, None)
    .await?;

// You're now logged in! Write the session to a file if you want to restore it later.
// Then start using the API!
# Result::<(), ruma_client::Error<_, _>>::Ok(())
# };

You can also pass an existing access token to the Client constructor to restore a previous session rather than calling log_in. This can also be used to create a session for an application service that does not need to log in, but uses the access_token directly:

# type MatrixClient = ruma_client::Client<ruma_client::http_client::Dummy>;

let work = async {
    let homeserver_url = "https://example.com".parse().unwrap();
    let client = MatrixClient::new(homeserver_url, Some("as_access_token".into()));

    // make calls to the API
};

The Client type also provides methods for registering a new account if you don't already have one with the given homeserver.

Beyond these basic convenience methods, ruma-client gives you access to the entire Matrix client-server API via the request method. You can pass it any of the Request types found in ruma::api::* and get back a corresponding response from the homeserver.

For example:

# type MatrixClient = ruma_client::Client<ruma_client::http_client::Dummy>;
# let homeserver_url = "https://example.com".parse().unwrap();
# let client = MatrixClient::new(homeserver_url, None);
use std::convert::TryFrom;

use ruma_client_api::r0::alias::get_alias;
use ruma_identifiers::{room_alias_id, room_id};

async {
    let response = client
        .send_request(get_alias::Request::new(&room_alias_id!("#example_room:example.com")))
        .await?;

    assert_eq!(response.room_id, room_id!("!n8f893n9:example.com"));
#   Result::<(), ruma_client::Error<_, _>>::Ok(())
}
# ;

Crate features

The following features activate http client types in the [http_client] module:

  • hyper
  • hyper-native-tls
  • hyper-rustls
  • isahc
  • reqwest – if you use the reqwest library already, activate this feature and configure the TLS backend on reqwest directly. If you want to use reqwest but don't depend on it already, use one of the sub-features instead. For details on the meaning of these, see reqwest's documentation:
    • reqwest-native-tls
    • reqwest-native-tls-alpn
    • reqwest-native-tls-vendored
    • reqwest-rustls-manual-roots
    • reqwest-rustls-webpki-roots
    • reqwest-rustls-native-roots

Dependencies

~2.7–8MB
~179K SLoC

Ca