Use ruma-api-macros for the versions endpoint.
This commit is contained in:
parent
d28912a148
commit
30fbb891fd
@ -11,6 +11,7 @@ repository = "https://github.com/ruma/ruma-client-api"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
futures = "0.1.13"
|
||||
ruma-events = "0.8.0"
|
||||
ruma-identifiers = "0.11.0"
|
||||
ruma-signatures = "0.3.0"
|
||||
@ -24,3 +25,8 @@ rev = "fed04dfb58e19b408322d4e5ca7474871e848a35"
|
||||
|
||||
[dependencies.ruma-api]
|
||||
git = "https://github.com/ruma/ruma-api"
|
||||
rev = "3635fe51ac31b9ff899c70a0d1218caa8cf6a8dc"
|
||||
|
||||
[dependencies.ruma-api-macros]
|
||||
git = "https://github.com/ruma/ruma-api-macros"
|
||||
rev = "10f4647037c81cc3c35097f6156dd9706d38964a"
|
||||
|
10
src/lib.rs
10
src/lib.rs
@ -3,16 +3,19 @@
|
||||
//! shared by client and server code.
|
||||
|
||||
#![deny(missing_debug_implementations)]
|
||||
#![feature(associated_consts, try_from)]
|
||||
#![feature(associated_consts, proc_macro, try_from)]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
extern crate futures;
|
||||
extern crate hyper;
|
||||
extern crate ruma_api;
|
||||
extern crate ruma_api_macros;
|
||||
extern crate ruma_events;
|
||||
extern crate ruma_identifiers;
|
||||
extern crate ruma_signatures;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
|
||||
// /// Endpoints for the r0.x.x versions of the client API specification.
|
||||
// pub mod r0 {
|
||||
@ -42,8 +45,3 @@ extern crate serde_json;
|
||||
// }
|
||||
|
||||
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,65 +2,23 @@
|
||||
|
||||
/// [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions)
|
||||
pub mod get_supported_versions {
|
||||
use std::convert::TryFrom;
|
||||
use ruma_api_macros::ruma_api;
|
||||
|
||||
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;
|
||||
|
||||
impl ApiEndpoint for Endpoint {
|
||||
type Request = Request;
|
||||
type Response = Response;
|
||||
|
||||
const METADATA: Metadata = Metadata {
|
||||
ruma_api! {
|
||||
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>,
|
||||
}
|
||||
request {}
|
||||
|
||||
impl TryFrom<HyperResponse> for Response {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(hyper_response: HyperResponse) -> Result<Response, Self::Error> {
|
||||
if hyper_response.status() == StatusCode::Ok {
|
||||
Ok(Response { versions: vec![] })
|
||||
} else {
|
||||
Err(Error)
|
||||
}
|
||||
response {
|
||||
/// A list of Matrix client API protocol versions supported by the homeserver.
|
||||
pub versions: Vec<String>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user