Implemented 4.1.1
This commit is contained in:
parent
7aa5928764
commit
ec47ed24e4
2 changed files with 42 additions and 7 deletions
|
@ -5,7 +5,7 @@
|
||||||
- [x] ~~3 Web Browser Clients~~ *Not applicable*
|
- [x] ~~3 Web Browser Clients~~ *Not applicable*
|
||||||
- [ ] 4 Server Discovery
|
- [ ] 4 Server Discovery
|
||||||
- [ ] 4.1 Well-known URI
|
- [ ] 4.1 Well-known URI
|
||||||
- [ ] 4.1.1 GET /.well-known/matrix/client
|
- [x] ~~4.1.1 GET /.well-known/matrix/client~~
|
||||||
- [ ] 5 Client Authentication
|
- [ ] 5 Client Authentication
|
||||||
- [x] ~~5.1 Using access tokens~~ *Only through Authorization header*
|
- [x] ~~5.1 Using access tokens~~ *Only through Authorization header*
|
||||||
- [ ] 5.2 Relationship between access tokens and devices
|
- [ ] 5.2 Relationship between access tokens and devices
|
||||||
|
|
|
@ -68,6 +68,23 @@ pub struct SupportedSpecs {
|
||||||
pub unstable_features: Option<HashMap<String, bool>>,
|
pub unstable_features: Option<HashMap<String, bool>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct DiscoveryInformation {
|
||||||
|
#[serde(rename = "m.homeserver")]
|
||||||
|
homeserver: HomeserverInformation,
|
||||||
|
identity_server: Option<IdentityServerInformation>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct HomeserverInformation {
|
||||||
|
base_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct IdentityServerInformation {
|
||||||
|
base_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
homeserver_url: &str,
|
homeserver_url: &str,
|
||||||
|
@ -100,15 +117,33 @@ impl Client {
|
||||||
Ok(client)
|
Ok(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implementation of [Section 2.1 **GET** /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.5.0#get-matrix-client-versions).
|
/// Implementation of [Section 4.1.1 **GET** `/.well-known/matrix/client`](https://matrix.org/docs/spec/client_server/r0.5.0#get-well-known-matrix-client).
|
||||||
|
///
|
||||||
|
/// This does not implement the expected behavior a client *should* perform
|
||||||
|
/// as described in [Section 4.1 Well-Known URI](https://matrix.org/docs/spec/client_server/r0.5.0#well-known-uri).
|
||||||
|
/// Higher level clients must implement this behavior.
|
||||||
|
pub fn discovery_information(&self) -> Result<DiscoveryInformation, Box<dyn Error>> {
|
||||||
|
Ok(self
|
||||||
|
.send(
|
||||||
|
MatrixHTTPMethod::Get,
|
||||||
|
"/.well-known/matrix/client",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
)?
|
||||||
|
.json()?)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implementation of [Section 2.1 **GET** `/_matrix/client/versions`](https://matrix.org/docs/spec/client_server/r0.5.0#get-matrix-client-versions).
|
||||||
///
|
///
|
||||||
/// Returns a list of matrix specifications a server supports, as well as
|
/// Returns a list of matrix specifications a server supports, as well as
|
||||||
/// a map of unstable features the server has advertised.
|
/// a map of unstable features the server has advertised. This is not rate-
|
||||||
|
/// limited nor requires authorization.
|
||||||
pub fn supported_versions(&self) -> Result<SupportedSpecs, Box<dyn Error>> {
|
pub fn supported_versions(&self) -> Result<SupportedSpecs, Box<dyn Error>> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.send(
|
.send(
|
||||||
MatrixHTTPMethod::Get,
|
MatrixHTTPMethod::Get,
|
||||||
Some("/_matrix/client/versions"),
|
"/_matrix/client/versions",
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -130,7 +165,7 @@ impl Client {
|
||||||
fn send(
|
fn send(
|
||||||
&self,
|
&self,
|
||||||
method: MatrixHTTPMethod,
|
method: MatrixHTTPMethod,
|
||||||
path: Option<&str>,
|
path: &str,
|
||||||
content: Option<String>,
|
content: Option<String>,
|
||||||
query_params: Option<HashMap<String, String>>,
|
query_params: Option<HashMap<String, String>>,
|
||||||
headers: Option<HeaderMap>,
|
headers: Option<HeaderMap>,
|
||||||
|
@ -143,7 +178,7 @@ impl Client {
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
let url = &self.homeserver_url;
|
let url = &self.homeserver_url;
|
||||||
|
|
||||||
let endpoint = &format!("{}{}", url, path.unwrap_or_else(|| V2_API_PATH));
|
let endpoint = &format!("{}{}", url, path);
|
||||||
let mut request = match method {
|
let mut request = match method {
|
||||||
MatrixHTTPMethod::Get => self.reqwest_client.get(endpoint),
|
MatrixHTTPMethod::Get => self.reqwest_client.get(endpoint),
|
||||||
MatrixHTTPMethod::Put => self.reqwest_client.put(endpoint),
|
MatrixHTTPMethod::Put => self.reqwest_client.put(endpoint),
|
||||||
|
@ -209,7 +244,7 @@ impl Client {
|
||||||
path: &str,
|
path: &str,
|
||||||
query_params: HashMap<String, String>,
|
query_params: HashMap<String, String>,
|
||||||
) -> Result<Response, Box<dyn Error>> {
|
) -> Result<Response, Box<dyn Error>> {
|
||||||
self.send(method, Some(path), None, Some(query_params), None)
|
self.send(method, path, None, Some(query_params), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sync(
|
pub fn sync(
|
||||||
|
|
Loading…
Reference in a new issue