Use endpoint_is_request branch for ruma-[client-]api

This commit is contained in:
Jonas Platte 2019-07-21 01:38:19 +02:00
parent 5543edb7b9
commit cfaabe9486
3 changed files with 18 additions and 20 deletions

View File

@ -15,7 +15,7 @@ version = "0.2.0"
[dependencies] [dependencies]
futures-preview = "0.3.0-alpha.17" futures-preview = "0.3.0-alpha.17"
http = "0.1.17" http = "0.1.17"
ruma-api = "0.9.0" ruma-api = { git = "https://github.com/ruma/ruma-api", branch = "endpoint_is_request" }
ruma-identifiers = "0.13.1" ruma-identifiers = "0.13.1"
serde_json = "1.0.39" serde_json = "1.0.39"
serde_urlencoded = "0.5.4" serde_urlencoded = "0.5.4"
@ -34,7 +34,7 @@ version = "0.2.2"
[dependencies.ruma-client-api] [dependencies.ruma-client-api]
git = "https://github.com/ruma/ruma-client-api" git = "https://github.com/ruma/ruma-client-api"
branch = "update-deps" branch = "endpoint_is_request"
[dependencies.ruma-events] [dependencies.ruma-events]
git = "https://github.com/ruma/ruma-events" git = "https://github.com/ruma/ruma-events"

View File

@ -19,7 +19,7 @@ async fn hello_world(homeserver_url: Url, room: String) -> Result<(), ruma_clien
client.register_guest().await?; client.register_guest().await?;
let response = client let response = client
.request::<r0::alias::get_alias::Endpoint>(r0::alias::get_alias::Request { .request(r0::alias::get_alias::Request {
room_alias: RoomAliasId::try_from(&room[..]).unwrap(), room_alias: RoomAliasId::try_from(&room[..]).unwrap(),
}) })
.await?; .await?;
@ -27,16 +27,14 @@ async fn hello_world(homeserver_url: Url, room: String) -> Result<(), ruma_clien
let room_id = response.room_id; let room_id = response.room_id;
client client
.request::<r0::membership::join_room_by_id::Endpoint>( .request(r0::membership::join_room_by_id::Request {
r0::membership::join_room_by_id::Request { room_id: room_id.clone(),
room_id: room_id.clone(), third_party_signed: None,
third_party_signed: None, })
},
)
.await?; .await?;
client client
.request::<r0::send::send_message_event::Endpoint>(r0::send::send_message_event::Request { .request(r0::send::send_message_event::Request {
room_id: room_id, room_id: room_id,
event_type: EventType::RoomMessage, event_type: EventType::RoomMessage,
txn_id: "1".to_owned(), txn_id: "1".to_owned(),

View File

@ -102,7 +102,7 @@
)] )]
use std::{ use std::{
convert::{TryFrom, TryInto}, convert::TryFrom,
str::FromStr, str::FromStr,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
@ -228,7 +228,7 @@ where
use ruma_client_api::r0::session::login; use ruma_client_api::r0::session::login;
let response = self let response = self
.request::<login::Endpoint>(login::Request { .request(login::Request {
address: None, address: None,
login_type: login::LoginType::Password, login_type: login::LoginType::Password,
medium: None, medium: None,
@ -255,7 +255,7 @@ where
use ruma_client_api::r0::account::register; use ruma_client_api::r0::account::register;
let response = self let response = self
.request::<register::Endpoint>(register::Request { .request(register::Request {
auth: None, auth: None,
bind_email: None, bind_email: None,
device_id: None, device_id: None,
@ -292,7 +292,7 @@ where
use ruma_client_api::r0::account::register; use ruma_client_api::r0::account::register;
let response = self let response = self
.request::<register::Endpoint>(register::Request { .request(register::Request {
auth: None, auth: None,
bind_email: None, bind_email: None,
device_id: None, device_id: None,
@ -360,7 +360,7 @@ where
}; };
let res = client let res = client
.request::<sync_events::Endpoint>(sync_events::Request { .request(sync_events::Request {
filter, filter,
since, since,
full_state: None, full_state: None,
@ -381,10 +381,10 @@ where
} }
/// Makes a request to a Matrix API endpoint. /// Makes a request to a Matrix API endpoint.
pub fn request<E: Endpoint>( pub fn request<Request: Endpoint>(
&self, &self,
request: E::Request, request: Request,
) -> impl Future<Output = Result<E::Response, Error>> { ) -> impl Future<Output = Result<Request::Response, Error>> {
let client = self.0.clone(); let client = self.0.clone();
async move { async move {
@ -398,7 +398,7 @@ where
url.set_path(uri.path()); url.set_path(uri.path());
url.set_query(uri.query()); url.set_query(uri.query());
if E::METADATA.requires_authentication { if Request::METADATA.requires_authentication {
if let Some(ref session) = *client.session.lock().unwrap() { if let Some(ref session) = *client.session.lock().unwrap() {
url.query_pairs_mut() url.query_pairs_mut()
.append_pair("access_token", &session.access_token); .append_pair("access_token", &session.access_token);
@ -415,7 +415,7 @@ where
let full_response = let full_response =
HttpResponse::from_parts(head, body.try_concat().await?.as_ref().to_owned()); HttpResponse::from_parts(head, body.try_concat().await?.as_ref().to_owned());
Ok(E::Response::try_from(full_response)?) Ok(Request::Response::try_from(full_response)?)
} }
} }
} }