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"
|
||||
|
||||
[dependencies]
|
||||
ruma-api = "0.3.0"
|
||||
ruma-events = "0.3.0"
|
||||
ruma-identifiers = "0.6.0"
|
||||
ruma-signatures = "0.1.0"
|
||||
serde = "0.8.21"
|
||||
serde_derive = "0.8.21"
|
||||
serde_json = "0.8.4"
|
||||
ruma-events = "0.8.0"
|
||||
ruma-identifiers = "0.11.0"
|
||||
ruma-signatures = "0.3.0"
|
||||
serde = "1.0.2"
|
||||
serde_derive = "1.0.2"
|
||||
serde_json = "1.0.1"
|
||||
|
||||
[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.
|
||||
|
||||
#![deny(missing_debug_implementations)]
|
||||
#![feature(associated_consts, try_from)]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
extern crate hyper;
|
||||
extern crate ruma_api;
|
||||
extern crate ruma_events;
|
||||
extern crate ruma_identifiers;
|
||||
extern crate ruma_signatures;
|
||||
extern crate serde;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
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 {
|
||||
pub mod account;
|
||||
pub mod alias;
|
||||
pub mod config;
|
||||
pub mod contact;
|
||||
pub mod context;
|
||||
pub mod directory;
|
||||
pub mod filter;
|
||||
pub mod media;
|
||||
pub mod membership;
|
||||
pub mod presence;
|
||||
pub mod profile;
|
||||
pub mod push;
|
||||
pub mod receipt;
|
||||
pub mod redact;
|
||||
pub mod room;
|
||||
pub mod search;
|
||||
pub mod send;
|
||||
pub mod server;
|
||||
pub mod session;
|
||||
pub mod sync;
|
||||
pub mod tag;
|
||||
pub mod typing;
|
||||
pub mod voip;
|
||||
}
|
||||
// /// Endpoints for the r0.x.x versions of the client API specification.
|
||||
// pub mod r0 {
|
||||
// pub mod account;
|
||||
// pub mod alias;
|
||||
// pub mod config;
|
||||
// pub mod contact;
|
||||
// pub mod context;
|
||||
// pub mod directory;
|
||||
// pub mod filter;
|
||||
// pub mod media;
|
||||
// pub mod membership;
|
||||
// pub mod presence;
|
||||
// pub mod profile;
|
||||
// pub mod push;
|
||||
// pub mod receipt;
|
||||
// pub mod redact;
|
||||
// pub mod room;
|
||||
// pub mod search;
|
||||
// pub mod send;
|
||||
// pub mod server;
|
||||
// pub mod session;
|
||||
// pub mod sync;
|
||||
// pub mod tag;
|
||||
// pub mod typing;
|
||||
// pub mod voip;
|
||||
// }
|
||||
|
||||
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)
|
||||
pub mod get_supported_versions {
|
||||
/// Details about this API endpoint.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
use std::convert::TryFrom;
|
||||
|
||||
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;
|
||||
|
||||
/// This API endpoint's response.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
impl ApiEndpoint for Endpoint {
|
||||
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 {
|
||||
/// A list of Matrix client API protocol versions supported by the homeserver.
|
||||
pub versions: Vec<String>,
|
||||
}
|
||||
|
||||
impl ::Endpoint for Endpoint {
|
||||
type BodyParams = ();
|
||||
type PathParams = ();
|
||||
type QueryParams = ();
|
||||
type Response = Response;
|
||||
impl TryFrom<HyperResponse> for Response {
|
||||
type Error = Error;
|
||||
|
||||
fn method() -> ::Method {
|
||||
::Method::Get
|
||||
}
|
||||
|
||||
fn request_path(_params: Self::PathParams) -> String {
|
||||
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
|
||||
fn try_from(hyper_response: HyperResponse) -> Result<Response, Self::Error> {
|
||||
if hyper_response.status() == StatusCode::Ok {
|
||||
Ok(Response { versions: vec![] })
|
||||
} else {
|
||||
Err(Error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user