matrix-sdk: Rename the AsyncClient to just Client.

master
Damir Jelić 2020-05-08 14:02:49 +02:00
parent 4e0bef064f
commit 9d09d19101
5 changed files with 80 additions and 82 deletions

View File

@ -3,18 +3,18 @@ use std::{env, process::exit};
use matrix_sdk::{ use matrix_sdk::{
self, self,
events::room::message::{MessageEvent, MessageEventContent, TextMessageEventContent}, events::room::message::{MessageEvent, MessageEventContent, TextMessageEventContent},
AsyncClient, AsyncClientConfig, EventEmitter, JsonStore, RoomState, SyncSettings, Client, ClientConfig, EventEmitter, JsonStore, RoomState, SyncSettings,
}; };
use url::Url; use url::Url;
struct CommandBot { struct CommandBot {
/// This clone of the `AsyncClient` will send requests to the server, /// This clone of the `Client` will send requests to the server,
/// while the other keeps us in sync with the server using `sync_forever`. /// while the other keeps us in sync with the server using `sync_forever`.
client: AsyncClient, client: Client,
} }
impl CommandBot { impl CommandBot {
pub fn new(client: AsyncClient) -> Self { pub fn new(client: Client) -> Self {
Self { client } Self { client }
} }
} }
@ -68,14 +68,14 @@ async fn login_and_sync(
home.push("party_bot"); home.push("party_bot");
let store = JsonStore::open(&home)?; let store = JsonStore::open(&home)?;
let client_config = AsyncClientConfig::new() let client_config = ClientConfig::new()
.proxy("http://localhost:8080")? .proxy("http://localhost:8080")?
.disable_ssl_verification() .disable_ssl_verification()
.state_store(Box::new(store)); .state_store(Box::new(store));
let homeserver_url = Url::parse(&homeserver_url).expect("Couldn't parse the homeserver URL"); let homeserver_url = Url::parse(&homeserver_url).expect("Couldn't parse the homeserver URL");
// create a new AsyncClient with the given homeserver url and config // create a new Client with the given homeserver url and config
let mut client = AsyncClient::new_with_config(homeserver_url, None, client_config).unwrap(); let mut client = Client::new_with_config(homeserver_url, None, client_config).unwrap();
client client
.login( .login(

View File

@ -4,7 +4,7 @@ use url::Url;
use matrix_sdk::{ use matrix_sdk::{
self, self,
events::room::message::{MessageEvent, MessageEventContent, TextMessageEventContent}, events::room::message::{MessageEvent, MessageEventContent, TextMessageEventContent},
AsyncClient, AsyncClientConfig, EventEmitter, RoomState, SyncSettings, Client, ClientConfig, EventEmitter, RoomState, SyncSettings,
}; };
struct EventCallback; struct EventCallback;
@ -41,11 +41,11 @@ async fn login(
username: String, username: String,
password: String, password: String,
) -> Result<(), matrix_sdk::Error> { ) -> Result<(), matrix_sdk::Error> {
let client_config = AsyncClientConfig::new() let client_config = ClientConfig::new()
.proxy("http://localhost:8080")? .proxy("http://localhost:8080")?
.disable_ssl_verification(); .disable_ssl_verification();
let homeserver_url = Url::parse(&homeserver_url).expect("Couldn't parse the homeserver URL"); let homeserver_url = Url::parse(&homeserver_url).expect("Couldn't parse the homeserver URL");
let mut client = AsyncClient::new_with_config(homeserver_url, None, client_config).unwrap(); let mut client = Client::new_with_config(homeserver_url, None, client_config).unwrap();
client.add_event_emitter(Box::new(EventCallback)).await; client.add_event_emitter(Box::new(EventCallback)).await;

View File

@ -55,9 +55,9 @@ const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
/// An async/await enabled Matrix client. /// An async/await enabled Matrix client.
/// ///
/// All of the state is held in an `Arc` so the `AsyncClient` can be cloned freely. /// All of the state is held in an `Arc` so the `Client` can be cloned freely.
#[derive(Clone)] #[derive(Clone)]
pub struct AsyncClient { pub struct Client {
/// The URL of the homeserver to connect to. /// The URL of the homeserver to connect to.
homeserver: Url, homeserver: Url,
/// The underlying HTTP client. /// The underlying HTTP client.
@ -66,14 +66,14 @@ pub struct AsyncClient {
pub(crate) base_client: BaseClient, pub(crate) base_client: BaseClient,
} }
impl std::fmt::Debug for AsyncClient { impl std::fmt::Debug for Client {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> StdResult<(), std::fmt::Error> { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> StdResult<(), std::fmt::Error> {
write!(fmt, "AsyncClient {{ homeserver: {} }}", self.homeserver) write!(fmt, "Client {{ homeserver: {} }}", self.homeserver)
} }
} }
#[derive(Default)] #[derive(Default)]
/// Configuration for the creation of the `AsyncClient`. /// Configuration for the creation of the `Client`.
/// ///
/// When setting the `StateStore` it is up to the user to open/connect /// When setting the `StateStore` it is up to the user to open/connect
/// the storage backend before client creation. /// the storage backend before client creation.
@ -81,32 +81,32 @@ impl std::fmt::Debug for AsyncClient {
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # use matrix_sdk::AsyncClientConfig; /// # use matrix_sdk::ClientConfig;
/// // To pass all the request through mitmproxy set the proxy and disable SSL /// // To pass all the request through mitmproxy set the proxy and disable SSL
/// // verification /// // verification
/// let client_config = AsyncClientConfig::new() /// let client_config = ClientConfig::new()
/// .proxy("http://localhost:8080") /// .proxy("http://localhost:8080")
/// .unwrap() /// .unwrap()
/// .disable_ssl_verification(); /// .disable_ssl_verification();
/// ``` /// ```
/// An example of adding a default `JsonStore` to the `AsyncClient`. /// An example of adding a default `JsonStore` to the `Client`.
/// ```no_run /// ```no_run
/// # use matrix_sdk::{AsyncClientConfig, JsonStore}; /// # use matrix_sdk::{ClientConfig, JsonStore};
/// ///
/// let store = JsonStore::open("path/to/json").unwrap(); /// let store = JsonStore::open("path/to/json").unwrap();
/// let client_config = AsyncClientConfig::new() /// let client_config = ClientConfig::new()
/// .state_store(Box::new(store)); /// .state_store(Box::new(store));
/// ``` /// ```
pub struct AsyncClientConfig { pub struct ClientConfig {
proxy: Option<reqwest::Proxy>, proxy: Option<reqwest::Proxy>,
user_agent: Option<HeaderValue>, user_agent: Option<HeaderValue>,
disable_ssl_verification: bool, disable_ssl_verification: bool,
state_store: Option<Box<dyn StateStore>>, state_store: Option<Box<dyn StateStore>>,
} }
impl std::fmt::Debug for AsyncClientConfig { impl std::fmt::Debug for ClientConfig {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> StdResult<(), std::fmt::Error> { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> StdResult<(), std::fmt::Error> {
fmt.debug_struct("AsyncClientConfig") fmt.debug_struct("ClientConfig")
.field("proxy", &self.proxy) .field("proxy", &self.proxy)
.field("user_agent", &self.user_agent) .field("user_agent", &self.user_agent)
.field("disable_ssl_verification", &self.disable_ssl_verification) .field("disable_ssl_verification", &self.disable_ssl_verification)
@ -114,8 +114,8 @@ impl std::fmt::Debug for AsyncClientConfig {
} }
} }
impl AsyncClientConfig { impl ClientConfig {
/// Create a new default `AsyncClientConfig`. /// Create a new default `ClientConfig`.
pub fn new() -> Self { pub fn new() -> Self {
Default::default() Default::default()
} }
@ -131,9 +131,9 @@ impl AsyncClientConfig {
/// # Example /// # Example
/// ///
/// ``` /// ```
/// use matrix_sdk::AsyncClientConfig; /// use matrix_sdk::ClientConfig;
/// ///
/// let client_config = AsyncClientConfig::new() /// let client_config = ClientConfig::new()
/// .proxy("http://localhost:8080") /// .proxy("http://localhost:8080")
/// .unwrap(); /// .unwrap();
/// ``` /// ```
@ -228,7 +228,7 @@ use api::r0::sync::sync_events;
use api::r0::to_device::send_event_to_device; use api::r0::to_device::send_event_to_device;
use api::r0::typing::create_typing_event; use api::r0::typing::create_typing_event;
impl AsyncClient { impl Client {
/// Creates a new client for making HTTP requests to the given homeserver. /// Creates a new client for making HTTP requests to the given homeserver.
/// ///
/// # Arguments /// # Arguments
@ -237,8 +237,8 @@ impl AsyncClient {
/// * `session` - If a previous login exists, the access token can be /// * `session` - If a previous login exists, the access token can be
/// reused by giving a session object here. /// reused by giving a session object here.
pub fn new<U: TryInto<Url>>(homeserver_url: U, session: Option<Session>) -> Result<Self> { pub fn new<U: TryInto<Url>>(homeserver_url: U, session: Option<Session>) -> Result<Self> {
let config = AsyncClientConfig::new(); let config = ClientConfig::new();
AsyncClient::new_with_config(homeserver_url, session, config) Client::new_with_config(homeserver_url, session, config)
} }
/// Create a new client with the given configuration. /// Create a new client with the given configuration.
@ -252,7 +252,7 @@ impl AsyncClient {
pub fn new_with_config<U: TryInto<Url>>( pub fn new_with_config<U: TryInto<Url>>(
homeserver_url: U, homeserver_url: U,
session: Option<Session>, session: Option<Session>,
config: AsyncClientConfig, config: ClientConfig,
) -> Result<Self> { ) -> Result<Self> {
#[allow(clippy::match_wild_err_arm)] #[allow(clippy::match_wild_err_arm)]
let homeserver: Url = match homeserver_url.try_into() { let homeserver: Url = match homeserver_url.try_into() {
@ -307,7 +307,7 @@ impl AsyncClient {
&self.homeserver &self.homeserver
} }
/// Add `EventEmitter` to `AsyncClient`. /// Add `EventEmitter` to `Client`.
/// ///
/// The methods of `EventEmitter` are called when the respective `RoomEvents` occur. /// The methods of `EventEmitter` are called when the respective `RoomEvents` occur.
pub async fn add_event_emitter(&mut self, emitter: Box<dyn EventEmitter>) { pub async fn add_event_emitter(&mut self, emitter: Box<dyn EventEmitter>) {
@ -362,21 +362,21 @@ impl AsyncClient {
self.base_client.get_left_room(room_id).await self.base_client.get_left_room(room_id).await
} }
/// This allows `AsyncClient` to manually sync state with the provided `StateStore`. /// This allows `Client` to manually sync state with the provided `StateStore`.
/// ///
/// Returns true when a successful `StateStore` sync has completed. /// Returns true when a successful `StateStore` sync has completed.
/// ///
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// use matrix_sdk::{AsyncClient, AsyncClientConfig, JsonStore, RoomBuilder}; /// use matrix_sdk::{Client, ClientConfig, JsonStore, RoomBuilder};
/// # use matrix_sdk::api::r0::room::Visibility; /// # use matrix_sdk::api::r0::room::Visibility;
/// # use url::Url; /// # use url::Url;
/// ///
/// # let homeserver = Url::parse("http://example.com").unwrap(); /// # let homeserver = Url::parse("http://example.com").unwrap();
/// let store = JsonStore::open("path/to/store").unwrap(); /// let store = JsonStore::open("path/to/store").unwrap();
/// let config = AsyncClientConfig::new().state_store(Box::new(store)); /// let config = ClientConfig::new().state_store(Box::new(store));
/// let mut client = AsyncClient::new(homeserver, None).unwrap(); /// let mut client = Client::new(homeserver, None).unwrap();
/// # use futures::executor::block_on; /// # use futures::executor::block_on;
/// # block_on(async { /// # block_on(async {
/// let _ = client.login("name", "password", None, None).await.unwrap(); /// let _ = client.login("name", "password", None, None).await.unwrap();
@ -603,7 +603,7 @@ impl AsyncClient {
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// use matrix_sdk::{AsyncClient, RoomBuilder}; /// use matrix_sdk::{Client, RoomBuilder};
/// # use matrix_sdk::api::r0::room::Visibility; /// # use matrix_sdk::api::r0::room::Visibility;
/// # use url::Url; /// # use url::Url;
/// ///
@ -615,7 +615,7 @@ impl AsyncClient {
/// .name("name") /// .name("name")
/// .room_version("v1.0"); /// .room_version("v1.0");
/// ///
/// let mut cli = AsyncClient::new(homeserver, None).unwrap(); /// let mut cli = Client::new(homeserver, None).unwrap();
/// # use futures::executor::block_on; /// # use futures::executor::block_on;
/// # block_on(async { /// # block_on(async {
/// assert!(cli.create_room(builder).await.is_ok()); /// assert!(cli.create_room(builder).await.is_ok());
@ -644,7 +644,7 @@ impl AsyncClient {
/// # Examples /// # Examples
/// ```no_run /// ```no_run
/// # use std::convert::TryFrom; /// # use std::convert::TryFrom;
/// use matrix_sdk::{AsyncClient, MessagesRequestBuilder}; /// use matrix_sdk::{Client, MessagesRequestBuilder};
/// # use matrix_sdk::identifiers::RoomId; /// # use matrix_sdk::identifiers::RoomId;
/// # use matrix_sdk::api::r0::filter::RoomEventFilter; /// # use matrix_sdk::api::r0::filter::RoomEventFilter;
/// # use matrix_sdk::api::r0::message::get_message_events::Direction; /// # use matrix_sdk::api::r0::message::get_message_events::Direction;
@ -659,7 +659,7 @@ impl AsyncClient {
/// .direction(Direction::Backward) /// .direction(Direction::Backward)
/// .limit(UInt::new(10).unwrap()); /// .limit(UInt::new(10).unwrap());
/// ///
/// let mut cli = AsyncClient::new(homeserver, None).unwrap(); /// let mut cli = Client::new(homeserver, None).unwrap();
/// # use futures::executor::block_on; /// # use futures::executor::block_on;
/// # block_on(async { /// # block_on(async {
/// assert!(cli.room_messages(builder).await.is_ok()); /// assert!(cli.room_messages(builder).await.is_ok());
@ -789,12 +789,12 @@ impl AsyncClient {
/// # }; /// # };
/// # use matrix_sdk::Room; /// # use matrix_sdk::Room;
/// # use std::sync::{Arc, RwLock}; /// # use std::sync::{Arc, RwLock};
/// # use matrix_sdk::{AsyncClient, SyncSettings}; /// # use matrix_sdk::{Client, SyncSettings};
/// # use url::Url; /// # use url::Url;
/// # use futures::executor::block_on; /// # use futures::executor::block_on;
/// # block_on(async { /// # block_on(async {
/// # let homeserver = Url::parse("http://localhost:8080").unwrap(); /// # let homeserver = Url::parse("http://localhost:8080").unwrap();
/// # let mut client = AsyncClient::new(homeserver, None).unwrap(); /// # let mut client = Client::new(homeserver, None).unwrap();
/// ///
/// use async_std::sync::channel; /// use async_std::sync::channel;
/// ///
@ -970,7 +970,7 @@ impl AsyncClient {
/// ```no_run /// ```no_run
/// # use matrix_sdk::Room; /// # use matrix_sdk::Room;
/// # use std::sync::{Arc, RwLock}; /// # use std::sync::{Arc, RwLock};
/// # use matrix_sdk::{AsyncClient, SyncSettings}; /// # use matrix_sdk::{Client, SyncSettings};
/// # use url::Url; /// # use url::Url;
/// # use futures::executor::block_on; /// # use futures::executor::block_on;
/// # use ruma_identifiers::RoomId; /// # use ruma_identifiers::RoomId;
@ -978,7 +978,7 @@ impl AsyncClient {
/// use matrix_sdk::events::room::message::{MessageEventContent, TextMessageEventContent}; /// use matrix_sdk::events::room::message::{MessageEventContent, TextMessageEventContent};
/// # block_on(async { /// # block_on(async {
/// # let homeserver = Url::parse("http://localhost:8080").unwrap(); /// # let homeserver = Url::parse("http://localhost:8080").unwrap();
/// # let mut client = AsyncClient::new(homeserver, None).unwrap(); /// # let mut client = Client::new(homeserver, None).unwrap();
/// # let room_id = RoomId::try_from("!test:localhost").unwrap(); /// # let room_id = RoomId::try_from("!test:localhost").unwrap();
/// use uuid::Uuid; /// use uuid::Uuid;
/// ///
@ -1196,7 +1196,7 @@ mod test {
ban_user, create_receipt, create_typing_event, forget_room, invite_user, kick_user, ban_user, create_receipt, create_typing_event, forget_room, invite_user, kick_user,
leave_room, Invite3pid, MessageEventContent, RoomIdOrAliasId, leave_room, Invite3pid, MessageEventContent, RoomIdOrAliasId,
}; };
use super::{AsyncClient, AsyncClientConfig, Session, SyncSettings, Url}; use super::{Client, ClientConfig, Session, SyncSettings, Url};
use crate::events::collections::all::RoomEvent; use crate::events::collections::all::RoomEvent;
use crate::events::room::member::MembershipState; use crate::events::room::member::MembershipState;
use crate::events::room::message::TextMessageEventContent; use crate::events::room::message::TextMessageEventContent;
@ -1228,7 +1228,7 @@ mod test {
.with_body_from_file("../test_data/sync.json") .with_body_from_file("../test_data/sync.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
@ -1247,7 +1247,7 @@ mod test {
device_id: "DEVICEID".to_owned(), device_id: "DEVICEID".to_owned(),
}; };
let homeserver = url::Url::parse(&mockito::server_url()).unwrap(); let homeserver = url::Url::parse(&mockito::server_url()).unwrap();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let mut response = EventBuilder::default() let mut response = EventBuilder::default()
.add_room_event_from_file("../test_data/events/member.json", RoomEvent::RoomMember) .add_room_event_from_file("../test_data/events/member.json", RoomEvent::RoomMember)
@ -1282,7 +1282,7 @@ mod test {
.with_body_from_file("../test_data/login_response_error.json") .with_body_from_file("../test_data/login_response_error.json")
.create(); .create();
let client = AsyncClient::new(homeserver, None).unwrap(); let client = Client::new(homeserver, None).unwrap();
if let Err(err) = client.login("example", "wordpass", None, None).await { if let Err(err) = client.login("example", "wordpass", None, None).await {
if let crate::Error::RumaResponse(crate::FromHttpResponseError::Http( if let crate::Error::RumaResponse(crate::FromHttpResponseError::Http(
@ -1331,7 +1331,7 @@ mod test {
.with_body_from_file("../test_data/room_id.json") .with_body_from_file("../test_data/room_id.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let room_id = RoomId::try_from("!testroom:example.org").unwrap(); let room_id = RoomId::try_from("!testroom:example.org").unwrap();
assert_eq!( assert_eq!(
@ -1359,7 +1359,7 @@ mod test {
.with_body_from_file("../test_data/room_id.json") .with_body_from_file("../test_data/room_id.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let room_id = RoomIdOrAliasId::try_from("!testroom:example.org").unwrap(); let room_id = RoomIdOrAliasId::try_from("!testroom:example.org").unwrap();
assert_eq!( assert_eq!(
@ -1394,7 +1394,7 @@ mod test {
.with_body_from_file("../test_data/logout_response.json") .with_body_from_file("../test_data/logout_response.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
if let invite_user::Response = client.invite_user_by_id(&room_id, &user).await.unwrap() {} if let invite_user::Response = client.invite_user_by_id(&room_id, &user).await.unwrap() {}
} }
@ -1420,7 +1420,7 @@ mod test {
.with_body_from_file("../test_data/logout_response.json") .with_body_from_file("../test_data/logout_response.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
if let invite_user::Response = client if let invite_user::Response = client
.invite_user_by_3pid( .invite_user_by_3pid(
@ -1457,7 +1457,7 @@ mod test {
.with_body_from_file("../test_data/logout_response.json") .with_body_from_file("../test_data/logout_response.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let room_id = RoomId::try_from("!testroom:example.org").unwrap(); let room_id = RoomId::try_from("!testroom:example.org").unwrap();
let response = client.leave_room(&room_id).await.unwrap(); let response = client.leave_room(&room_id).await.unwrap();
@ -1492,7 +1492,7 @@ mod test {
.with_body_from_file("../test_data/logout_response.json") .with_body_from_file("../test_data/logout_response.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let response = client.ban_user(&room_id, &user, None).await.unwrap(); let response = client.ban_user(&room_id, &user, None).await.unwrap();
if let ban_user::Response = response { if let ban_user::Response = response {
@ -1526,7 +1526,7 @@ mod test {
.with_body_from_file("../test_data/logout_response.json") .with_body_from_file("../test_data/logout_response.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let response = client.kick_user(&room_id, &user, None).await.unwrap(); let response = client.kick_user(&room_id, &user, None).await.unwrap();
if let kick_user::Response = response { if let kick_user::Response = response {
@ -1560,7 +1560,7 @@ mod test {
.with_body_from_file("../test_data/logout_response.json") .with_body_from_file("../test_data/logout_response.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let response = client.forget_room_by_id(&room_id).await.unwrap(); let response = client.forget_room_by_id(&room_id).await.unwrap();
if let forget_room::Response = response { if let forget_room::Response = response {
@ -1595,7 +1595,7 @@ mod test {
.with_body_from_file("../test_data/logout_response.json") .with_body_from_file("../test_data/logout_response.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let response = client.read_receipt(&room_id, &event_id).await.unwrap(); let response = client.read_receipt(&room_id, &event_id).await.unwrap();
if let create_receipt::Response = response { if let create_receipt::Response = response {
@ -1629,7 +1629,7 @@ mod test {
.with_body_from_file("../test_data/logout_response.json") .with_body_from_file("../test_data/logout_response.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let response = client let response = client
.typing_notice( .typing_notice(
@ -1671,7 +1671,7 @@ mod test {
.with_body_from_file("../test_data/event_id.json") .with_body_from_file("../test_data/event_id.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let content = MessageEventContent::Text(TextMessageEventContent { let content = MessageEventContent::Text(TextMessageEventContent {
body: "Hello world".to_owned(), body: "Hello world".to_owned(),
@ -1709,7 +1709,7 @@ mod test {
.with_body_from_file("../test_data/sync.json") .with_body_from_file("../test_data/sync.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
@ -1749,7 +1749,7 @@ mod test {
.with_body_from_file("../test_data/sync_with_summary.json") .with_body_from_file("../test_data/sync_with_summary.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
let _response = client.sync(sync_settings).await.unwrap(); let _response = client.sync(sync_settings).await.unwrap();
@ -1773,7 +1773,7 @@ mod test {
}; };
let homeserver = url::Url::parse(&mockito::server_url()).unwrap(); let homeserver = url::Url::parse(&mockito::server_url()).unwrap();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let _m = mock( let _m = mock(
"GET", "GET",
@ -1806,7 +1806,7 @@ mod test {
}; };
let homeserver = url::Url::parse(&mockito::server_url()).unwrap(); let homeserver = url::Url::parse(&mockito::server_url()).unwrap();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let _m = mock( let _m = mock(
"GET", "GET",
@ -1853,21 +1853,19 @@ mod test {
let dir = tempfile::tempdir().unwrap(); let dir = tempfile::tempdir().unwrap();
// a sync response to populate our JSON store // a sync response to populate our JSON store
let config = AsyncClientConfig::default() let config =
.state_store(Box::new(JsonStore::open(dir.path()).unwrap())); ClientConfig::default().state_store(Box::new(JsonStore::open(dir.path()).unwrap()));
let client = let client =
AsyncClient::new_with_config(homeserver.clone(), Some(session.clone()), config) Client::new_with_config(homeserver.clone(), Some(session.clone()), config).unwrap();
.unwrap();
let sync_settings = SyncSettings::new().timeout(std::time::Duration::from_millis(3000)); let sync_settings = SyncSettings::new().timeout(std::time::Duration::from_millis(3000));
// gather state to save to the db, the first time through loading will be skipped // gather state to save to the db, the first time through loading will be skipped
let _ = client.sync(sync_settings.clone()).await.unwrap(); let _ = client.sync(sync_settings.clone()).await.unwrap();
// now syncing the client will update from the state store // now syncing the client will update from the state store
let config = AsyncClientConfig::default() let config =
.state_store(Box::new(JsonStore::open(dir.path()).unwrap())); ClientConfig::default().state_store(Box::new(JsonStore::open(dir.path()).unwrap()));
let client = let client = Client::new_with_config(homeserver, Some(session.clone()), config).unwrap();
AsyncClient::new_with_config(homeserver, Some(session.clone()), config).unwrap();
client.sync(sync_settings).await.unwrap(); client.sync(sync_settings).await.unwrap();
let base_client = &client.base_client; let base_client = &client.base_client;
@ -1893,7 +1891,7 @@ mod test {
.with_body_from_file("../test_data/login_response.json") .with_body_from_file("../test_data/login_response.json")
.create(); .create();
let client = AsyncClient::new(homeserver, None).unwrap(); let client = Client::new(homeserver, None).unwrap();
client client
.login("example", "wordpass", None, None) .login("example", "wordpass", None, None)
@ -1922,7 +1920,7 @@ mod test {
.with_body_from_file("../test_data/sync.json") .with_body_from_file("../test_data/sync.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
@ -1951,7 +1949,7 @@ mod test {
.with_body_from_file("../test_data/sync.json") .with_body_from_file("../test_data/sync.json")
.create(); .create();
let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = Client::new(homeserver, Some(session)).unwrap();
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));

View File

@ -37,7 +37,7 @@ pub use matrix_sdk_base::{Device, TrustState};
mod client; mod client;
mod error; mod error;
mod request_builder; mod request_builder;
pub use client::{AsyncClient, AsyncClientConfig, SyncSettings}; pub use client::{Client, ClientConfig, SyncSettings};
pub use error::{Error, Result}; pub use error::{Error, Result};
pub use request_builder::{MessagesRequestBuilder, RoomBuilder}; pub use request_builder::{MessagesRequestBuilder, RoomBuilder};

View File

@ -17,7 +17,7 @@ use crate::js_int::UInt;
/// # Examples /// # Examples
/// ``` /// ```
/// # use std::convert::TryFrom; /// # use std::convert::TryFrom;
/// # use matrix_sdk::{AsyncClient, RoomBuilder}; /// # use matrix_sdk::{Client, RoomBuilder};
/// # use matrix_sdk::api::r0::room::Visibility; /// # use matrix_sdk::api::r0::room::Visibility;
/// # use matrix_sdk::identifiers::UserId; /// # use matrix_sdk::identifiers::UserId;
/// # use url::Url; /// # use url::Url;
@ -30,7 +30,7 @@ use crate::js_int::UInt;
/// .visibility(Visibility::Public) /// .visibility(Visibility::Public)
/// .name("name") /// .name("name")
/// .room_version("v1.0"); /// .room_version("v1.0");
/// let mut cli = AsyncClient::new(homeserver, None).unwrap(); /// let mut cli = Client::new(homeserver, None).unwrap();
/// cli.create_room(builder).await; /// cli.create_room(builder).await;
/// # }) /// # })
/// ``` /// ```
@ -179,7 +179,7 @@ impl Into<create_room::Request> for RoomBuilder {
/// # Examples /// # Examples
/// ``` /// ```
/// # use std::convert::TryFrom; /// # use std::convert::TryFrom;
/// # use matrix_sdk::{AsyncClient, MessagesRequestBuilder}; /// # use matrix_sdk::{Client, MessagesRequestBuilder};
/// # use matrix_sdk::api::r0::message::get_message_events::{self, Direction}; /// # use matrix_sdk::api::r0::message::get_message_events::{self, Direction};
/// # use matrix_sdk::identifiers::RoomId; /// # use matrix_sdk::identifiers::RoomId;
/// # use url::Url; /// # use url::Url;
@ -188,7 +188,7 @@ impl Into<create_room::Request> for RoomBuilder {
/// # rt.block_on(async { /// # rt.block_on(async {
/// # let room_id = RoomId::try_from("!test:localhost").unwrap(); /// # let room_id = RoomId::try_from("!test:localhost").unwrap();
/// # let last_sync_token = "".to_string(); /// # let last_sync_token = "".to_string();
/// let mut cli = AsyncClient::new(homeserver, None).unwrap(); /// let mut cli = Client::new(homeserver, None).unwrap();
/// ///
/// let mut builder = MessagesRequestBuilder::new(); /// let mut builder = MessagesRequestBuilder::new();
/// builder.room_id(room_id) /// builder.room_id(room_id)
@ -296,7 +296,7 @@ mod test {
use crate::api::r0::filter::{LazyLoadOptions, RoomEventFilter}; use crate::api::r0::filter::{LazyLoadOptions, RoomEventFilter};
use crate::events::room::power_levels::NotificationPowerLevels; use crate::events::room::power_levels::NotificationPowerLevels;
use crate::js_int::Int; use crate::js_int::Int;
use crate::{identifiers::RoomId, AsyncClient, Session}; use crate::{identifiers::RoomId, Client, Session};
use mockito::{mock, Matcher}; use mockito::{mock, Matcher};
use std::convert::TryFrom; use std::convert::TryFrom;
@ -342,7 +342,7 @@ mod test {
.room_alias_name("room_alias") .room_alias_name("room_alias")
.topic("room topic") .topic("room topic")
.visibility(Visibility::Private); .visibility(Visibility::Private);
let cli = AsyncClient::new(homeserver, Some(session)).unwrap(); let cli = Client::new(homeserver, Some(session)).unwrap();
assert!(cli.create_room(builder).await.is_ok()); assert!(cli.create_room(builder).await.is_ok());
} }
@ -378,7 +378,7 @@ mod test {
..Default::default() ..Default::default()
}); });
let cli = AsyncClient::new(homeserver, Some(session)).unwrap(); let cli = Client::new(homeserver, Some(session)).unwrap();
assert!(cli.room_messages(builder).await.is_ok()); assert!(cli.room_messages(builder).await.is_ok());
} }
} }