WIP
This commit is contained in:
parent
52f027d655
commit
d28912a148
20
Cargo.toml
20
Cargo.toml
@ -11,10 +11,16 @@ repository = "https://github.com/ruma/ruma-client-api"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ruma-api = "0.3.0"
|
ruma-events = "0.8.0"
|
||||||
ruma-events = "0.3.0"
|
ruma-identifiers = "0.11.0"
|
||||||
ruma-identifiers = "0.6.0"
|
ruma-signatures = "0.3.0"
|
||||||
ruma-signatures = "0.1.0"
|
serde = "1.0.2"
|
||||||
serde = "0.8.21"
|
serde_derive = "1.0.2"
|
||||||
serde_derive = "0.8.21"
|
serde_json = "1.0.1"
|
||||||
serde_json = "0.8.4"
|
|
||||||
|
[dependencies.hyper]
|
||||||
|
git = "https://github.com/hyperium/hyper"
|
||||||
|
rev = "fed04dfb58e19b408322d4e5ca7474871e848a35"
|
||||||
|
|
||||||
|
[dependencies.ruma-api]
|
||||||
|
git = "https://github.com/ruma/ruma-api"
|
||||||
|
62
src/lib.rs
62
src/lib.rs
@ -3,43 +3,47 @@
|
|||||||
//! shared by client and server code.
|
//! shared by client and server code.
|
||||||
|
|
||||||
#![deny(missing_debug_implementations)]
|
#![deny(missing_debug_implementations)]
|
||||||
|
#![feature(associated_consts, try_from)]
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
|
extern crate hyper;
|
||||||
extern crate ruma_api;
|
extern crate ruma_api;
|
||||||
extern crate ruma_events;
|
extern crate ruma_events;
|
||||||
extern crate ruma_identifiers;
|
extern crate ruma_identifiers;
|
||||||
extern crate ruma_signatures;
|
extern crate ruma_signatures;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
#[macro_use] extern crate serde_derive;
|
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
pub use ruma_api::{Endpoint, Method};
|
// /// Endpoints for the r0.x.x versions of the client API specification.
|
||||||
|
// pub mod r0 {
|
||||||
/// Endpoints for the r0.x.x versions of the client API specification.
|
// pub mod account;
|
||||||
pub mod r0 {
|
// pub mod alias;
|
||||||
pub mod account;
|
// pub mod config;
|
||||||
pub mod alias;
|
// pub mod contact;
|
||||||
pub mod config;
|
// pub mod context;
|
||||||
pub mod contact;
|
// pub mod directory;
|
||||||
pub mod context;
|
// pub mod filter;
|
||||||
pub mod directory;
|
// pub mod media;
|
||||||
pub mod filter;
|
// pub mod membership;
|
||||||
pub mod media;
|
// pub mod presence;
|
||||||
pub mod membership;
|
// pub mod profile;
|
||||||
pub mod presence;
|
// pub mod push;
|
||||||
pub mod profile;
|
// pub mod receipt;
|
||||||
pub mod push;
|
// pub mod redact;
|
||||||
pub mod receipt;
|
// pub mod room;
|
||||||
pub mod redact;
|
// pub mod search;
|
||||||
pub mod room;
|
// pub mod send;
|
||||||
pub mod search;
|
// pub mod server;
|
||||||
pub mod send;
|
// pub mod session;
|
||||||
pub mod server;
|
// pub mod sync;
|
||||||
pub mod session;
|
// pub mod tag;
|
||||||
pub mod sync;
|
// pub mod typing;
|
||||||
pub mod tag;
|
// pub mod voip;
|
||||||
pub mod typing;
|
// }
|
||||||
pub mod voip;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod unversioned;
|
pub mod unversioned;
|
||||||
|
|
||||||
|
/// An error when converting an endpoint's request into a `hyper::Request` or converting a
|
||||||
|
/// `hyper::Response` into an endpoint's response.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Error;
|
||||||
|
@ -2,49 +2,65 @@
|
|||||||
|
|
||||||
/// [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions)
|
/// [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions)
|
||||||
pub mod get_supported_versions {
|
pub mod get_supported_versions {
|
||||||
/// Details about this API endpoint.
|
use std::convert::TryFrom;
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
|
use hyper::{Method, Request as HyperRequest, Response as HyperResponse, StatusCode};
|
||||||
|
use ruma_api::{Endpoint as ApiEndpoint, Metadata};
|
||||||
|
|
||||||
|
use Error;
|
||||||
|
|
||||||
|
/// Endpoint
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Endpoint;
|
pub struct Endpoint;
|
||||||
|
|
||||||
/// This API endpoint's response.
|
impl ApiEndpoint for Endpoint {
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
type Request = Request;
|
||||||
|
type Response = Response;
|
||||||
|
|
||||||
|
const METADATA: Metadata = Metadata {
|
||||||
|
description: "Get the versions of the client-server API supported by this homeserver.",
|
||||||
|
method: Method::Get,
|
||||||
|
name: "api_versions",
|
||||||
|
path: "/_matrix/client/versions",
|
||||||
|
rate_limited: false,
|
||||||
|
requires_authentication: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Request
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Request;
|
||||||
|
|
||||||
|
impl TryFrom<Request> for HyperRequest {
|
||||||
|
type Error = Error;
|
||||||
|
fn try_from(_request: Request) -> Result<HyperRequest, Self::Error> {
|
||||||
|
let metadata = Endpoint::METADATA;
|
||||||
|
|
||||||
|
let hyper_request = HyperRequest::new(
|
||||||
|
metadata.method,
|
||||||
|
metadata.path.parse().map_err(|_| Error)?,
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(hyper_request)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Response
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
/// A list of Matrix client API protocol versions supported by the homeserver.
|
/// A list of Matrix client API protocol versions supported by the homeserver.
|
||||||
pub versions: Vec<String>,
|
pub versions: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::Endpoint for Endpoint {
|
impl TryFrom<HyperResponse> for Response {
|
||||||
type BodyParams = ();
|
type Error = Error;
|
||||||
type PathParams = ();
|
|
||||||
type QueryParams = ();
|
|
||||||
type Response = Response;
|
|
||||||
|
|
||||||
fn method() -> ::Method {
|
fn try_from(hyper_response: HyperResponse) -> Result<Response, Self::Error> {
|
||||||
::Method::Get
|
if hyper_response.status() == StatusCode::Ok {
|
||||||
}
|
Ok(Response { versions: vec![] })
|
||||||
|
} else {
|
||||||
fn request_path(_params: Self::PathParams) -> String {
|
Err(Error)
|
||||||
Self::router_path().to_string()
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
|
||||||
"/_matrix/client/versions"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"api_version"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description() -> &'static str {
|
|
||||||
"Get the versions of the client-server API supported by this homeserver."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user