Make all of Endpoint's associated types optional parameters when building a request.
This commit is contained in:
parent
1492147875
commit
212d3a5e7b
23
src/lib.rs
23
src/lib.rs
@ -70,19 +70,26 @@ impl Client {
|
|||||||
/// Get the versions of the Matrix client-server specification supported by the homeserver.
|
/// Get the versions of the Matrix client-server specification supported by the homeserver.
|
||||||
pub fn get_supported_versions(&mut self)
|
pub fn get_supported_versions(&mut self)
|
||||||
-> Result<FutureResponse<<get_supported_versions::Endpoint as Endpoint>::Response>, Error> {
|
-> Result<FutureResponse<<get_supported_versions::Endpoint as Endpoint>::Response>, Error> {
|
||||||
self.request::<get_supported_versions::Endpoint>((), (), ())
|
self.request::<get_supported_versions::Endpoint>(None, None, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request<E>(
|
fn request<E>(
|
||||||
&mut self,
|
&mut self,
|
||||||
body_params: E::BodyParams,
|
body_params: Option<E::BodyParams>,
|
||||||
path_params: E::PathParams,
|
path_params: Option<E::PathParams>,
|
||||||
query_params: E::QueryParams,
|
query_params: Option<E::QueryParams>,
|
||||||
) -> Result<FutureResponse<E::Response>, Error>
|
) -> Result<FutureResponse<E::Response>, Error>
|
||||||
where E: Endpoint, <E as Endpoint>::Response: Debug + Send {
|
where E: Endpoint, <E as Endpoint>::Response: Debug + Send {
|
||||||
let mut url = self.homeserver_url.join(&E::request_path(path_params))?.try_into()?;
|
let path = match path_params {
|
||||||
|
Some(params) => E::request_path(params),
|
||||||
|
None => E::router_path().to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
url.set_query(Some(&serde_urlencoded::to_string(&query_params)?));
|
let mut url = self.homeserver_url.join(&path)?.try_into()?;
|
||||||
|
|
||||||
|
if let Some(params) = query_params {
|
||||||
|
url.set_query(Some(&serde_urlencoded::to_string(¶ms)?));
|
||||||
|
}
|
||||||
|
|
||||||
if E::requires_authentication() {
|
if E::requires_authentication() {
|
||||||
if let Some(ref session) = self.session {
|
if let Some(ref session) = self.session {
|
||||||
@ -96,7 +103,9 @@ impl Client {
|
|||||||
|
|
||||||
match E::method() {
|
match E::method() {
|
||||||
Method::Post | Method::Put => {
|
Method::Post | Method::Put => {
|
||||||
request.set_body(serde_json::to_string(&body_params)?);
|
if let Some(params) = body_params {
|
||||||
|
request.set_body(serde_json::to_string(¶ms)?);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user