Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target/
config
session
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions hello_world/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
A simple example to demonstrate `ruma-client` functionality. Sends "Hello
World!" to the given room.
A simple example to demonstrate `ruma-client` functionality. Joins the given
room and sends "Hello World!".

# Usage

Expand Down
31 changes: 23 additions & 8 deletions hello_world/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::{env, process::exit};

use ruma::{
OwnedRoomAliasId, TransactionId,
api::client::{alias::get_alias, membership::join_room_by_id, message::send_message_event},
OwnedRoomId, OwnedRoomOrAliasId, TransactionId,
api::client::{
alias::get_alias, membership::join_room_by_id_or_alias, message::send_message_event,
},
events::room::message::RoomMessageEventContent,
};

Expand All @@ -12,8 +14,9 @@ async fn hello_world(
homeserver_url: String,
username: &str,
password: &str,
room_alias: OwnedRoomAliasId,
room_id_or_alias: OwnedRoomOrAliasId,
) -> anyhow::Result<()> {
// Construct and log in the client.
let client = ruma_client::Client::builder()
.homeserver_url(homeserver_url)
.build::<HttpClient>()
Expand All @@ -22,13 +25,25 @@ async fn hello_world(
.log_in(username, password, None, Some("ruma-example-client"))
.await?;

let room_id = client
.send_request(get_alias::v3::Request::new(room_alias))
.await?
.room_id;
// Join the room.
client
.send_request(join_room_by_id::v3::Request::new(room_id.clone()))
.send_request(join_room_by_id_or_alias::v3::Request::new(
room_id_or_alias.clone(),
))
.await?;

// Resolve the room alias to a room ID if necessary.
let room_id = match OwnedRoomId::try_from(room_id_or_alias) {
Ok(room_id) => room_id,
Err(room_alias) => {
client
.send_request(get_alias::v3::Request::new(room_alias))
.await?
.room_id
}
};

// Send the message.
client
.send_request(send_message_event::v3::Request::new(
room_id,
Expand Down
10 changes: 0 additions & 10 deletions joke_bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,10 @@ publish = false
[dependencies]
ruma = { version = "0.13.0", features = ["client-api-c", "rand"] }
ruma-client = { version = "0.16.0", features = ["client-api", "hyper-native-tls"] }
# For building locally: use the git dependencies below.
#
# Browse the source at this revision here: https://github.com/ruma/ruma/tree/bb825c7280a4b49302e74ecd89e8a4c5c37e9a36
# ruma = { git = "https://github.com/ruma/ruma", rev = "bb825c7280a4b49302e74ecd89e8a4c5c37e9a36", features = ["client-api-c", "rand"] }
#
# Browse the source at this revision here: https://github.com/ruma/ruma-client/tree/464eda0e196a9a43c85db12734693e0c99214e69
# ruma-client = { git = "https://github.com/ruma/ruma-client", rev = "464eda0e196a9a43c85db12734693e0c99214e69", features = ["client-api", "hyper-native-tls"] }

futures-util = { version = "0.3.21", default-features = false, features = ["std"] }
http = "1.1.0"
http-body-util = "0.1.1"
hyper = "1.3.1"
hyper-tls = "0.6.0"
hyper-util = { version = "0.1.3", features = ["client-legacy", "http1", "http2", "tokio"] }
serde_json = "1.0"
tokio = { version = "1", features = ["full"] }
tokio-stream = "0.1.7"
6 changes: 0 additions & 6 deletions joke_bot/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
A simple bot to demonstrate `ruma-client` functionality. Tells jokes when you ask for them.

# Note on dependency versions

This example was written against pre-release versions of `ruma` and
`ruma-client-api`. Check the comments in the `[dependencies]` section of
[`Cargo.toml`](Cargo.toml) for more information.

# Usage

Create a file called `config` and populate it with the following values in `key=value` format:
Expand Down
Loading