From 30fbb891fd83f2291e0f9dcbce6bac6b72f0b3cf Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sun, 14 May 2017 04:19:34 -0700 Subject: [PATCH] Use ruma-api-macros for the versions endpoint. --- Cargo.toml | 6 +++++ src/lib.rs | 10 ++++----- src/unversioned.rs | 56 ++++++---------------------------------------- 3 files changed, 17 insertions(+), 55 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2e676bb9..b973058a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/lib.rs b/src/lib.rs index 93bcdb35..3bbac1ce 100644 --- a/src/lib.rs +++ b/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; diff --git a/src/unversioned.rs b/src/unversioned.rs index d08cb253..0c1dc831 100644 --- a/src/unversioned.rs +++ b/src/unversioned.rs @@ -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 for HyperRequest { - type Error = Error; - fn try_from(_request: Request) -> Result { - 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, - } + request {} - impl TryFrom for Response { - type Error = Error; - - fn try_from(hyper_response: HyperResponse) -> Result { - 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, } } }