From 4339999152f8514750b6c4836ca735019d37a143 Mon Sep 17 00:00:00 2001 From: Wim de With Date: Fri, 8 Nov 2019 15:15:53 +0100 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ Cargo.toml | 18 ++++++++++++++++++ LICENSE | 19 +++++++++++++++++++ README.md | 16 ++++++++++++++++ src/lib.rs | 13 +++++++++++++ src/v1.rs | 4 ++++ src/v1/event.rs | 3 +++ src/v1/event/push_events.rs | 28 ++++++++++++++++++++++++++++ src/v1/query.rs | 4 ++++ src/v1/query/query_room_alias.rs | 23 +++++++++++++++++++++++ src/v1/query/query_user_id.rs | 23 +++++++++++++++++++++++ 11 files changed, 153 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 src/lib.rs create mode 100644 src/v1.rs create mode 100644 src/v1/event.rs create mode 100644 src/v1/event/push_events.rs create mode 100644 src/v1/query.rs create mode 100644 src/v1/query/query_room_alias.rs create mode 100644 src/v1/query/query_user_id.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..fa8d85ac --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Cargo.lock +target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000..ebc42a60 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,18 @@ +[package] +authors = ["Wim de With "] +categories = ["api-bindings", "web-programming"] +description = "Types of the endpoints in the Matrix application service API." +keywords = ["matrix", "chat", "messaging", "ruma"] +license = "MIT" +name = "ruma-appservice-api" +readme = "README.md" +version = "0.1.0" +edition = "2018" + +[dependencies] +ruma-api = "0.11.0" +ruma-events = "0.15.1" +ruma-identifiers = "0.14.0" +serde = { version = "1.0.102", features = ["derive"] } +serde_json = "1.0.41" +url = { version = "2.1.0", features = ["serde"] } diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..da7c1156 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2019 Wim de With + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 00000000..6d2d8a7a --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# ruma-appservice-api + +**ruma-appservice-api** contains serializable types for the requests and responses for each endpoint in the [Matrix](https://matrix.org/) application service API specification. +These types can be shared by application service and server code. + +## Minimum Rust version + +ruma-appservice-api requires Rust 1.34.2 or later. + +## Status + +This project is currently experimental and is very likely to change drastically. + +## License + +[MIT](http://opensource.org/licenses/MIT) diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 00000000..a6372d51 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,13 @@ +//! Crate ruma_appservice_api contains serializable types for the requests and responses for each +//! endpoint in the [Matrix](https://matrix.org/) application service API specification. These +//! types can be shared by application service and server code. + +#![deny( + missing_copy_implementations, + missing_debug_implementations, + missing_docs +)] +// Since we support Rust 1.34.2, we can't apply this suggestion yet +#![allow(clippy::use_self)] + +pub mod v1; diff --git a/src/v1.rs b/src/v1.rs new file mode 100644 index 00000000..7536fb70 --- /dev/null +++ b/src/v1.rs @@ -0,0 +1,4 @@ +//! Endpoints for the r0.x.x versions of the application service API specification + +pub mod event; +pub mod query; diff --git a/src/v1/event.rs b/src/v1/event.rs new file mode 100644 index 00000000..8721e54f --- /dev/null +++ b/src/v1/event.rs @@ -0,0 +1,3 @@ +//! Endpoint for sending events. + +pub mod push_events; diff --git a/src/v1/event/push_events.rs b/src/v1/event/push_events.rs new file mode 100644 index 00000000..131acc57 --- /dev/null +++ b/src/v1/event/push_events.rs @@ -0,0 +1,28 @@ +//! [PUT /_matrix/app/v1/transactions/{txnId}](https://matrix.org/docs/spec/application_service/r0.1.2#put-matrix-app-v1-transactions-txnid) + +use ruma_api::ruma_api; +use ruma_events::collections::all; + +ruma_api! { + metadata { + description: "This API is called by the homeserver when it wants to push an event (or batch of events) to the application service.", + method: PUT, + name: "push_events", + path: "/_matrix/app/v1/transactions/:txn_id", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The transaction ID for this set of events. + /// + /// Homeservers generate these IDs and they are used to ensure idempotency of results. + #[ruma_api(path)] + pub txn_id: String, + /// A list of events. + #[ruma_api(body)] + pub events: Vec, + } + + response {} +} diff --git a/src/v1/query.rs b/src/v1/query.rs new file mode 100644 index 00000000..ee67d7b8 --- /dev/null +++ b/src/v1/query.rs @@ -0,0 +1,4 @@ +//! Endpoints for querying user IDs and room aliases + +pub mod query_room_alias; +pub mod query_user_id; diff --git a/src/v1/query/query_room_alias.rs b/src/v1/query/query_room_alias.rs new file mode 100644 index 00000000..ea0e17fe --- /dev/null +++ b/src/v1/query/query_room_alias.rs @@ -0,0 +1,23 @@ +//! [GET /_matrix/app/v1/rooms/{roomAlias}](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-rooms-roomalias) + +use ruma_api::ruma_api; +use ruma_identifiers::RoomAliasId; + +ruma_api! { + metadata { + description: "This endpoint is invoked by the homeserver on an application service to query the existence of a given room alias.", + method: GET, + name: "query_room_alias", + path: "/_matrix/app/v1/rooms/:room_alias", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The room alias being queried. + #[ruma_api(path)] + pub room_alias: RoomAliasId, + } + + response {} +} diff --git a/src/v1/query/query_user_id.rs b/src/v1/query/query_user_id.rs new file mode 100644 index 00000000..d45cccc3 --- /dev/null +++ b/src/v1/query/query_user_id.rs @@ -0,0 +1,23 @@ +//! [GET /_matrix/app/v1/users/{userId}](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-users-userid) + +use ruma_api::ruma_api; +use ruma_identifiers::UserId; + +ruma_api! { + metadata { + description: "This endpoint is invoked by the homeserver on an application service to query the existence of a given user ID.", + method: GET, + name: "query_user_id", + path: "/_matrix/app/v1/users/:user_id", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The user ID being queried. + #[ruma_api(path)] + pub user_id: UserId, + } + + response {} +}