#![doc(html_favicon_url = "https://www.ruma.io/favicon.ico")]
#![doc(html_logo_url = "https://www.ruma.io/images/logo.png")]
//! A minimal [Matrix](https://matrix.org/) client library.
//!
//! # Usage
//!
//! Begin by creating a `Client` type, usually using the `https` method for a client that supports
//! secure connections, and then logging in:
//!
//! ```ignore
//! use ruma_client::Client;
//!
//! let work = async {
//! let homeserver_url = "https://example.com".parse().unwrap();
//! let client = Client::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:
//!
//! ```ignore
//! use ruma_client::Client;
//!
//! let work = async {
//! let homeserver_url = "https://example.com".parse().unwrap();
//! let client = Client::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:
//!
//! ```ignore
//! # use ruma_client::Client;
//! # let homeserver_url = "https://example.com".parse().unwrap();
//! # let client = Client::new(homeserver_url, None);
//! use std::convert::TryFrom;
//!
//! use ruma::{
//! api::client::r0::alias::get_alias,
//! 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(())
//! }
//! # ;
//! ```
#![warn(rust_2018_idioms)]
#![deny(missing_debug_implementations, missing_docs)]
use std::{
collections::BTreeMap,
sync::{Arc, Mutex},
};
use assign::assign;
use http::uri::Uri;
use ruma_api::{AuthScheme, OutgoingRequest, SendAccessToken};
use ruma_serde::urlencoded;
// "Undo" rename from `Cargo.toml` that only serves to make `hyper-rustls` available as a Cargo
// feature name.
#[cfg(feature = "hyper-rustls")]
extern crate hyper_rustls_crate as hyper_rustls;
#[cfg(feature = "client-api")]
mod client_api;
mod error;
pub mod http_client;
pub use self::{
error::Error,
http_client::{DefaultConstructibleHttpClient, HttpClient},
};
/// A client for the Matrix client-server API.
#[derive(Clone, Debug)]
pub struct Client(Arc>);
/// Data contained in Client's Rc
#[derive(Debug)]
struct ClientData {
/// The URL of the homeserver to connect to.
homeserver_url: Uri,
/// The underlying HTTP client.
http_client: C,
/// User session data.
access_token: Mutex