Turn homeserver url and room into command line params for hello_world examples
This commit is contained in:
parent
76d0780f5a
commit
5df3d4888d
@ -9,6 +9,8 @@ extern crate tokio_core;
|
|||||||
extern crate url;
|
extern crate url;
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
use std::env;
|
||||||
|
use std::process::exit;
|
||||||
|
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use ruma_client::Client;
|
use ruma_client::Client;
|
||||||
@ -41,12 +43,13 @@ macro_rules! clone {
|
|||||||
fn hello_world(
|
fn hello_world(
|
||||||
tokio_handle: &Handle,
|
tokio_handle: &Handle,
|
||||||
homeserver_url: Url,
|
homeserver_url: Url,
|
||||||
|
room: String,
|
||||||
) -> impl Future<Item = (), Error = ruma_client::Error> + 'static {
|
) -> impl Future<Item = (), Error = ruma_client::Error> + 'static {
|
||||||
let client = Client::https(tokio_handle, homeserver_url, None).unwrap();
|
let client = Client::https(tokio_handle, homeserver_url, None).unwrap();
|
||||||
|
|
||||||
client.register_guest().and_then(clone!(client => move |_| {
|
client.register_guest().and_then(clone!(client => move |_| {
|
||||||
r0::alias::get_alias::call(client, r0::alias::get_alias::Request {
|
r0::alias::get_alias::call(client, r0::alias::get_alias::Request {
|
||||||
room_alias: RoomAliasId::try_from("#ruma-client-test:matrix.org").unwrap(),
|
room_alias: RoomAliasId::try_from(&room[..]).unwrap(),
|
||||||
})
|
})
|
||||||
})).and_then(clone!(client => move |response| {
|
})).and_then(clone!(client => move |response| {
|
||||||
let room_id = response.room_id;
|
let room_id = response.room_id;
|
||||||
@ -69,9 +72,17 @@ fn hello_world(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let (homeserver_url, room) = match (env::args().nth(1), env::args().nth(2)) {
|
||||||
|
(Some(a), Some(b)) => (a, b),
|
||||||
|
_ => {
|
||||||
|
eprintln!("Usage: {} <homeserver_url> <room>", env::args().next().unwrap());
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let mut core = Core::new().unwrap();
|
let mut core = Core::new().unwrap();
|
||||||
let handle = core.handle();
|
let handle = core.handle();
|
||||||
let server = Url::parse("https://matrix.org/").unwrap();
|
let server = Url::parse(&homeserver_url).unwrap();
|
||||||
|
|
||||||
core.run(hello_world(&handle, server)).unwrap();
|
core.run(hello_world(&handle, server, room)).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ extern crate tokio_core;
|
|||||||
extern crate url;
|
extern crate url;
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
use std::env;
|
||||||
|
use std::process::exit;
|
||||||
|
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use ruma_client::Client;
|
use ruma_client::Client;
|
||||||
@ -24,6 +26,7 @@ use url::Url;
|
|||||||
fn hello_world(
|
fn hello_world(
|
||||||
tokio_handle: &Handle,
|
tokio_handle: &Handle,
|
||||||
homeserver_url: Url,
|
homeserver_url: Url,
|
||||||
|
room: String,
|
||||||
) -> impl Future<Item = (), Error = ruma_client::Error> + 'static {
|
) -> impl Future<Item = (), Error = ruma_client::Error> + 'static {
|
||||||
let client = Client::https(tokio_handle, homeserver_url, None).unwrap();
|
let client = Client::https(tokio_handle, homeserver_url, None).unwrap();
|
||||||
|
|
||||||
@ -33,7 +36,7 @@ fn hello_world(
|
|||||||
let response = await!(r0::alias::get_alias::call(
|
let response = await!(r0::alias::get_alias::call(
|
||||||
client.clone(),
|
client.clone(),
|
||||||
r0::alias::get_alias::Request {
|
r0::alias::get_alias::Request {
|
||||||
room_alias: RoomAliasId::try_from("#ruma-client-test:matrix.org").unwrap(),
|
room_alias: RoomAliasId::try_from(&room[..]).unwrap(),
|
||||||
}
|
}
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
@ -65,9 +68,18 @@ fn hello_world(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let (homeserver_url, room) = match (env::args().nth(1), env::args().nth(2)) {
|
||||||
|
(Some(a), Some(b)) => (a, b),
|
||||||
|
_ => {
|
||||||
|
eprintln!("Usage: {} <homeserver_url> <room>", env::args().next().unwrap());
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
let mut core = Core::new().unwrap();
|
let mut core = Core::new().unwrap();
|
||||||
let handle = core.handle();
|
let handle = core.handle();
|
||||||
let server = Url::parse("https://matrix.org/").unwrap();
|
let server = Url::parse(&homeserver_url).unwrap();
|
||||||
|
|
||||||
core.run(hello_world(&handle, server)).unwrap();
|
core.run(hello_world(&handle, server, room)).unwrap();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user