Define module layout and fill in types for a few APIs.

This commit is contained in:
Jimmy Cuadra 2016-09-30 16:13:59 -07:00
parent 0251019b01
commit 409b8202f7
26 changed files with 197 additions and 1 deletions

View File

@ -1,5 +1,4 @@
[package]
authors = ["Jimmy Cuadra <jimmy@jimmycuadra.com>"]
description = "Serializable request and response types for the Matrix client API."
documentation = "https://docs.rs/ruma-client-api"
@ -12,3 +11,6 @@ repository = "https://github.com/ruma/ruma-client-api"
version = "0.1.0"
[dependencies]
ruma-identifiers = "0.4.1"
serde = "0.8.10"
serde_derive = "0.8.10"

View File

@ -0,0 +1,39 @@
//! Crate ruma_client_api contains serializable types for the requests and responses for each
//! endpoint in the [Matrix](https://matrix.org/) client API specification. These types can be
//! shared by client and server code.
#![feature(rustc_macro)]
extern crate ruma_identifiers;
extern crate serde;
#[macro_use] extern crate serde_derive;
/// 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;
}
/// GET /_matrix/client/versions
pub mod version;

57
src/r0/account.rs Normal file
View File

@ -0,0 +1,57 @@
//! Endpoints for account registration and management.
/// POST /_matrix/client/r0/register
pub mod register {
pub const HTTP_METHOD: &'static str = "POST";
pub const PATH: &'static str = "/_matrix/client/r0/register";
/// The kind of account being registered.
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
pub enum RegistrationKind {
#[serde(rename="guest")]
Guest,
#[serde(rename="user")]
User,
}
/// The request type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Request {
pub bind_email: Option<bool>,
pub kind: Option<RegistrationKind>,
pub password: String,
pub username: Option<String>,
}
/// The response type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub access_token: String,
pub home_server: String,
pub user_id: String,
}
}
/// POST /_matrix/client/r0/account/password/email/requestToken
pub mod request_password_change_token {
}
/// POST /_matrix/client/r0/account/deactivate
pub mod deactivate {
}
/// POST /_matrix/client/r0/account/password
pub mod change_password {
pub const HTTP_METHOD: &'static str = "POST";
pub const PATH: &'static str = "/_matrix/client/r0/account/password";
/// The request type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Request {
pub new_password: String,
}
}
/// POST /_matrix/client/r0/register/email/requestToken
pub mod request_register_token {
}

1
src/r0/alias.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for room aliases.

1
src/r0/config.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for client configuration.

1
src/r0/contact.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for account contact information.

1
src/r0/context.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for event context.

1
src/r0/directory.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for the public room directory.

1
src/r0/filter.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for event filters.

1
src/r0/media.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for the media repository.

1
src/r0/membership.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for room membership.

1
src/r0/presence.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for user presence.

1
src/r0/profile.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for user profiles.

1
src/r0/push.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for push notifications.

1
src/r0/receipt.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for event receipts.

1
src/r0/redact.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for event redaction.

48
src/r0/room.rs Normal file
View File

@ -0,0 +1,48 @@
//! Endpoints for room creation.
/// POST /_matrix/client/r0/createRoom
pub mod create_room {
use ruma_identifiers::RoomId;
pub const HTTP_METHOD: &'static str = "POST";
pub const PATH: &'static str = "/_matrix/client/r0/createRoom";
/// Extra options to be added to the `m.room.create` event.
#[derive(Clone, Debug, Deserialize)]
pub struct CreationContent {
#[serde(rename="m.federate")]
pub federate: Option<bool>,
}
/// The request type.
#[derive(Clone, Debug, Deserialize)]
pub struct Request {
pub creation_content: Option<CreationContent>,
pub invite: Option<Vec<String>>,
pub name: Option<String>,
pub preset: Option<RoomPreset>,
pub room_alias_name: Option<String>,
pub topic: Option<String>,
pub visibility: Option<String>,
}
/// The response type.
#[derive(Debug, Serialize)]
pub struct Response {
room_id: RoomId,
}
/// A convenience parameter for setting a few default state events.
#[derive(Clone, Copy, Debug, Deserialize)]
pub enum RoomPreset {
/// `join_rules` is set to `invite` and `history_visibility` is set to `shared`.
#[serde(rename="private_chat")]
PrivateChat,
/// `join_rules` is set to `public` and `history_visibility` is set to `shared`.
#[serde(rename="public_chat")]
PublicChat,
/// Same as `PrivateChat`, but all initial invitees get the same power level as the creator.
#[serde(rename="trusted_private_chat")]
TrustedPrivateChat,
}
}

1
src/r0/search.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for event searches.

1
src/r0/send.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for sending events.

1
src/r0/server.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for server administration.

21
src/r0/session.rs Normal file
View File

@ -0,0 +1,21 @@
//! Endpoints for user session management.
/// POST /_matrix/client/r0/login
pub mod login {
pub const HTTP_METHOD: &'static str = "POST";
pub const PATH: &'static str = "/_matrix/client/r0/login";
/// The response type.
#[derive(Clone, Debug, Deserialize, Serialize)]
struct LoginResponse {
pub access_token: String,
pub home_server: String,
pub user_id: String,
}
}
/// POST /_matrix/client/r0/logout
pub mod logout {
pub const HTTP_METHOD: &'static str = "POST";
pub const PATH: &'static str = "/_matrix/client/r0/logout";
}

1
src/r0/sync.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for getting and synchronizing events.

1
src/r0/tag.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for tagging rooms.

1
src/r0/typing.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for typing notifications.

1
src/r0/voip.rs Normal file
View File

@ -0,0 +1 @@
//! Endpoints for Voice over IP.

9
src/version.rs Normal file
View File

@ -0,0 +1,9 @@
pub const HTTP_METHOD: &'static str = "GET";
pub const PATH: &'static str = "/versions";
/// The response type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
/// A list of Matrix client API protocol versions supported by the homeserver.
pub versions: Vec<String>,
}