From 4339999152f8514750b6c4836ca735019d37a143 Mon Sep 17 00:00:00 2001 From: Wim de With Date: Fri, 8 Nov 2019 15:15:53 +0100 Subject: [PATCH 01/13] 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 {} +} From 531bbb64290cc4a32d900c0d89592d84d2170060 Mon Sep 17 00:00:00 2001 From: Wim de With Date: Mon, 11 Nov 2019 11:04:52 +0100 Subject: [PATCH 02/13] Configure Travis --- .travis.yml | 38 ++++++++++++++++++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 40 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..071cf057 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,38 @@ +language: "rust" +cache: "cargo" +rust: + - 1.34.2 + - stable + - beta + - nightly +jobs: + allow_failures: + - rust: nightly + fast_finish: true + +before_script: + - rustup component add rustfmt + - | + if [ "$TRAVIS_RUST_VERSION" != "1.34.2" ]; then + rustup component add clippy + fi + - | + if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then + cargo install --force cargo-audit + fi + - cargo generate-lockfile +script: + - | + if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then + cargo audit + fi + - cargo fmt -- --check + - | + if [ "$TRAVIS_RUST_VERSION" != "1.34.2" ]; then + cargo clippy --all-targets --all-features -- -D warnings + fi + - cargo build --verbose + - cargo test --verbose +if: "type != push OR (tag IS blank AND branch = master)" +notifications: + email: false diff --git a/README.md b/README.md index 6d2d8a7a..885284b2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # ruma-appservice-api +[![Build Status](https://travis-ci.org/ruma/ruma-appservice-api.svg?branch=master)](https://travis-ci.org/ruma/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. From 7a2b14fe1509135dbb09572c802e83c664bb435f Mon Sep 17 00:00:00 2001 From: Wim de With Date: Mon, 11 Nov 2019 11:07:17 +0100 Subject: [PATCH 03/13] Add homepage and repository URLs to Cargo.toml --- Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index ebc42a60..62fd9623 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,10 +2,12 @@ authors = ["Wim de With "] categories = ["api-bindings", "web-programming"] description = "Types of the endpoints in the Matrix application service API." +homepage = "https://github.com/ruma/ruma-appservice-api" keywords = ["matrix", "chat", "messaging", "ruma"] license = "MIT" name = "ruma-appservice-api" readme = "README.md" +repository = "https://github.com/ruma/ruma-appservice-api" version = "0.1.0" edition = "2018" From fa771877f777368cfdce8ed3857e12ed047c849c Mon Sep 17 00:00:00 2001 From: Wim de With Date: Mon, 11 Nov 2019 11:07:45 +0100 Subject: [PATCH 04/13] Fix wording in Cargo.toml description --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 62fd9623..d11909da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Wim de With "] categories = ["api-bindings", "web-programming"] -description = "Types of the endpoints in the Matrix application service API." +description = "Types for the endpoints in the Matrix application service API." homepage = "https://github.com/ruma/ruma-appservice-api" keywords = ["matrix", "chat", "messaging", "ruma"] license = "MIT" From c3aa9bd95285a88ccd904cec3972a151c87b8ddf Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Mon, 11 Nov 2019 21:02:34 -0800 Subject: [PATCH 05/13] Update Travis CI configure and include IRC notifications. --- .travis.yml | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index 071cf057..3221d1c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,38 +1,20 @@ language: "rust" cache: "cargo" -rust: - - 1.34.2 - - stable - - beta - - nightly -jobs: - allow_failures: - - rust: nightly - fast_finish: true - before_script: - - rustup component add rustfmt - - | - if [ "$TRAVIS_RUST_VERSION" != "1.34.2" ]; then - rustup component add clippy - fi - - | - if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then - cargo install --force cargo-audit - fi - - cargo generate-lockfile + - "rustup component add rustfmt" + - "rustup component add clippy" + - "cargo install --force cargo-audit" + - "cargo generate-lockfile" script: - - | - if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then - cargo audit - fi - - cargo fmt -- --check - - | - if [ "$TRAVIS_RUST_VERSION" != "1.34.2" ]; then - cargo clippy --all-targets --all-features -- -D warnings - fi - - cargo build --verbose - - cargo test --verbose + - "cargo audit" + - "cargo fmt --all -- --check" + - "cargo clippy --all-targets --all-features -- -D warnings" + - "cargo build --verbose" + - "cargo test --verbose" if: "type != push OR (tag IS blank AND branch = master)" notifications: email: false + irc: + channels: + - secure: "Z4Bo39O8Zl/xGJ3A3P08sKO12YMpQOMwwWou9oZxYGnaVQM/1hlpgMrPKtif4v+681SGMuUoA97P0Tr93oSSGqyJalN2dcft9vOiFa1Izo5nVuJ1+8trTRxV+3oE7X30ixh/jWg4oXPrfLbKMv1Bp7htjffNQQcsh2RrPjmhK3PtuqTLeY0OFm6uKIa/4fmz2d2PV+V2GRhFvI4b4HRLAQDRbFrD3MUReSqqWCpAdnyswKOVZMcCNZHuBpPdZK+lARopZsruN5LcDi787CRel79K+Cmqif1jyGgwQusjrP2c4Bjdi6SGCy2V5TNMYgYrp1ox/gLaHNC3A1aHZYmbHXI908aANbt860Y/1N0ax3CbEkUFFSfiEjnw816BTJ61/kccMEUN6nYpbj/hkyNApCXYlp65+FAx2NaQCV6obvWh7ymF3Mp8v1OvidEKbhvDqhuGQ62ZZGWVUpzKAe0QRQ2NFFPm53nOrcVHdR4ZMKdGrsgAgpvX1d92JmChqlZbEjbCZRs+KHj1Bkfwkousu9+VNLQatc+VwiqXXHnOi9jCVecqmtLnioP3UvYBEQKsh2gv5GhUwluqrSMNfy3H51Zg/lLMHQHUZw5XZgb7nenCBcrmSl4h75+z1lUdkE5UQn3WcjVOVsbwS/qpHHJ+CRKnpcSBqIE1pb0BFdI5/MU=" + use_notice: true From 55dfe98d44344ed7a35c03c3022253bcc4332a91 Mon Sep 17 00:00:00 2001 From: Wim de With Date: Thu, 21 Nov 2019 14:41:16 +0100 Subject: [PATCH 06/13] Update ruma-api to 0.11.2 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d11909da..4b3b23fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ version = "0.1.0" edition = "2018" [dependencies] -ruma-api = "0.11.0" +ruma-api = "0.11.2" ruma-events = "0.15.1" ruma-identifiers = "0.14.0" serde = { version = "1.0.102", features = ["derive"] } From 038ae89d05dc246d4666566857d50f82a8610f02 Mon Sep 17 00:00:00 2001 From: Wim de With Date: Thu, 21 Nov 2019 14:43:47 +0100 Subject: [PATCH 07/13] Add thirdparty network endpoints --- src/v1.rs | 1 + src/v1/thirdparty.rs | 73 +++++++++++++++++++ .../thirdparty/get_location_for_protocol.rs | 34 +++++++++ .../thirdparty/get_location_for_room_alias.rs | 29 ++++++++ src/v1/thirdparty/get_protocol.rs | 28 +++++++ src/v1/thirdparty/get_user_for_protocol.rs | 34 +++++++++ src/v1/thirdparty/get_user_for_user_id.rs | 29 ++++++++ 7 files changed, 228 insertions(+) create mode 100644 src/v1/thirdparty.rs create mode 100644 src/v1/thirdparty/get_location_for_protocol.rs create mode 100644 src/v1/thirdparty/get_location_for_room_alias.rs create mode 100644 src/v1/thirdparty/get_protocol.rs create mode 100644 src/v1/thirdparty/get_user_for_protocol.rs create mode 100644 src/v1/thirdparty/get_user_for_user_id.rs diff --git a/src/v1.rs b/src/v1.rs index 7536fb70..75499ade 100644 --- a/src/v1.rs +++ b/src/v1.rs @@ -2,3 +2,4 @@ pub mod event; pub mod query; +pub mod thirdparty; diff --git a/src/v1/thirdparty.rs b/src/v1/thirdparty.rs new file mode 100644 index 00000000..18fe481b --- /dev/null +++ b/src/v1/thirdparty.rs @@ -0,0 +1,73 @@ +//! Endpoints for third party lookups + +pub mod get_location_for_protocol; +pub mod get_location_for_room_alias; +pub mod get_protocol; +pub mod get_user_for_protocol; +pub mod get_user_for_user_id; + +use std::collections::HashMap; + +use ruma_identifiers::{RoomAliasId, UserId}; + +use serde::{Deserialize, Serialize}; + +/// Metadata about a third party protocol. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Protocol { + /// Fields which may be used to identify a third party user. + pub user_fields: Vec, + /// Fields which may be used to identify a third party location. + pub location_fields: Vec, + /// A content URI representing an icon for the third party protocol. + pub icon: String, + /// The type definitions for the fields defined in `user_fields` and `location_fields`. + pub field_types: HashMap, + /// A list of objects representing independent instances of configuration. + pub instances: Vec, +} + +/// Metadata about an instance of a third party protocol. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ProtocolInstance { + /// A human-readable description for the protocol, such as the name. + pub desc: String, + /// An optional content URI representing the protocol. + #[serde(skip_serializing_if = "Option::is_none")] + pub icon: Option, + /// Preset values for `fields` the client may use to search by. + pub fields: HashMap, + /// A unique identifier across all instances. + pub network_id: String, +} + +/// A type definition for a field used to identify third party users or locations. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct FieldType { + /// A regular expression for validation of a field's value. + pub regexp: String, + /// A placeholder serving as a valid example of the field value. + pub placeholder: String, +} + +/// A third party network location. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Location { + /// An alias for a matrix room. + pub alias: RoomAliasId, + /// The protocol ID that the third party location is a part of. + pub protocol: String, + /// Information used to identify this third party location. + pub fields: HashMap, +} + +/// A third party network user. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct User { + /// A matrix user ID representing a third party user. + pub userid: UserId, + /// The protocol ID that the third party user is a part of. + pub protocol: String, + /// Information used to identify this third party user. + pub fields: HashMap, +} diff --git a/src/v1/thirdparty/get_location_for_protocol.rs b/src/v1/thirdparty/get_location_for_protocol.rs new file mode 100644 index 00000000..f39154b3 --- /dev/null +++ b/src/v1/thirdparty/get_location_for_protocol.rs @@ -0,0 +1,34 @@ +//! [GET /_matrix/app/v1/thirdparty/location/{protocol}](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-thirdparty-location-protocol) + +use std::collections::HashMap; + +use ruma_api::ruma_api; + +use super::Location; + +ruma_api! { + metadata { + description: "Fetches third party locations for a protocol.", + method: GET, + name: "get_location_for_protocol", + path: "/_matrix/app/v1/thirdparty/location/:protocol", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The protocol used to communicate to the third party network. + #[ruma_api(path)] + pub protocol: String, + /// One or more custom fields to help identify the third party location. + // The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352. + #[ruma_api(query_map)] + pub fields: HashMap, + } + + response { + /// List of matched third party locations. + #[ruma_api(body)] + pub locations: Vec, + } +} diff --git a/src/v1/thirdparty/get_location_for_room_alias.rs b/src/v1/thirdparty/get_location_for_room_alias.rs new file mode 100644 index 00000000..270e2661 --- /dev/null +++ b/src/v1/thirdparty/get_location_for_room_alias.rs @@ -0,0 +1,29 @@ +//! [GET /_matrix/app/v1/thirdparty/location](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-thirdparty-location) + +use ruma_api::ruma_api; +use ruma_identifiers::RoomAliasId; + +use super::Location; + +ruma_api! { + metadata { + description: "Retrieve an array of third party network locations from a Matrix room alias.", + method: GET, + name: "get_location_for_room_alias", + path: "/_matrix/app/v1/thirdparty/location", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The Matrix room alias to look up. + #[ruma_api(query)] + pub alias: RoomAliasId, + } + + response { + /// List of matched third party locations. + #[ruma_api(body)] + pub locations: Vec, + } +} diff --git a/src/v1/thirdparty/get_protocol.rs b/src/v1/thirdparty/get_protocol.rs new file mode 100644 index 00000000..726336c6 --- /dev/null +++ b/src/v1/thirdparty/get_protocol.rs @@ -0,0 +1,28 @@ +//! [GET /_matrix/app/v1/thirdparty/protocol/{protocol}](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-thirdparty-protocol-protocol) + +use ruma_api::ruma_api; + +use super::Protocol; + +ruma_api! { + metadata { + description: "Fetches the metadata from the homeserver about a particular third party protocol.", + method: GET, + name: "get_protocol", + path: "/_matrix/app/v1/thirdparty/protocol/:protocol", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The name of the protocol. + #[ruma_api(path)] + pub protocol: String, + } + + response { + /// Metadata about the protocol. + #[ruma_api(body)] + pub protocol: Protocol, + } +} diff --git a/src/v1/thirdparty/get_user_for_protocol.rs b/src/v1/thirdparty/get_user_for_protocol.rs new file mode 100644 index 00000000..1fe4aebb --- /dev/null +++ b/src/v1/thirdparty/get_user_for_protocol.rs @@ -0,0 +1,34 @@ +//! [GET /_matrix/app/v1/thirdparty/user/{protocol}](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-thirdparty-user-protocol) + +use std::collections::HashMap; + +use ruma_api::ruma_api; + +use super::User; + +ruma_api! { + metadata { + description: "Fetches third party users for a protocol.", + method: GET, + name: "get_user_for_protocol", + path: "/_matrix/app/v1/thirdparty/user/:protocol", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The protocol used to communicate to the third party network. + #[ruma_api(path)] + pub protocol: String, + /// One or more custom fields that are passed to the AS to help identify the user. + // The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352. + #[ruma_api(query_map)] + pub fields: HashMap, + } + + response { + /// List of matched third party users. + #[ruma_api(body)] + pub users: Vec, + } +} diff --git a/src/v1/thirdparty/get_user_for_user_id.rs b/src/v1/thirdparty/get_user_for_user_id.rs new file mode 100644 index 00000000..7ac655ef --- /dev/null +++ b/src/v1/thirdparty/get_user_for_user_id.rs @@ -0,0 +1,29 @@ +//! [GET /_matrix/app/v1/thirdparty/user](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-thirdparty-user) + +use ruma_api::ruma_api; +use ruma_identifiers::UserId; + +use super::User; + +ruma_api! { + metadata { + description: "Retrieve an array of third party users from a Matrix User ID.", + method: GET, + name: "get_user_for_user_id", + path: "/_matrix/app/v1/thirdparty/user", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The Matrix User ID to look up. + #[ruma_api(query)] + pub userid: UserId, + } + + response { + /// List of matched third party users. + #[ruma_api(body)] + pub users: Vec, + } +} From f5bfee3f8d9b70c25db5d1261d47155a5d0084e3 Mon Sep 17 00:00:00 2001 From: Wim de With Date: Mon, 25 Nov 2019 23:37:05 +0100 Subject: [PATCH 08/13] Bump MSRV and run CI on multiple Rust versions --- .travis.yml | 40 +++++++++++++++++++++++++++++++--------- README.md | 2 +- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3221d1c7..3519fea0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,38 @@ language: "rust" cache: "cargo" +rust: + - 1.36.0 + - stable + - beta + - nightly +jobs: + allow_failures: + - rust: nightly + fast_finish: true + before_script: - - "rustup component add rustfmt" - - "rustup component add clippy" - - "cargo install --force cargo-audit" - - "cargo generate-lockfile" + - rustup component add rustfmt + - | + if [ "$TRAVIS_RUST_VERSION" != "1.36.0" ]; then + rustup component add clippy + fi + - | + if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then + cargo install --force cargo-audit + fi + - cargo generate-lockfile script: - - "cargo audit" - - "cargo fmt --all -- --check" - - "cargo clippy --all-targets --all-features -- -D warnings" - - "cargo build --verbose" - - "cargo test --verbose" + - | + if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then + cargo audit + fi + - cargo fmt -- --check + - | + if [ "$TRAVIS_RUST_VERSION" != "1.36.0" ]; then + cargo clippy --all-targets --all-features -- -D warnings + fi + - cargo build --verbose + - cargo test --verbose if: "type != push OR (tag IS blank AND branch = master)" notifications: email: false diff --git a/README.md b/README.md index 885284b2..f54043e3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ These types can be shared by application service and server code. ## Minimum Rust version -ruma-appservice-api requires Rust 1.34.2 or later. +ruma-appservice-api requires Rust 1.36.0 or later. ## Status From f7d6cf9b3fe3bbafa6d1b45ee1ac9b65706000b7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 24 Apr 2020 22:19:30 +0200 Subject: [PATCH 09/13] Replace travis CI with builds.sr.ht --- .builds/beta.yml | 27 +++++++++++++++++++++++++++ .builds/msrv.yml | 16 ++++++++++++++++ .builds/nightly.yml | 32 ++++++++++++++++++++++++++++++++ .builds/stable.yml | 29 +++++++++++++++++++++++++++++ .travis.yml | 42 ------------------------------------------ README.md | 2 -- 6 files changed, 104 insertions(+), 44 deletions(-) create mode 100644 .builds/beta.yml create mode 100644 .builds/msrv.yml create mode 100644 .builds/nightly.yml create mode 100644 .builds/stable.yml delete mode 100644 .travis.yml diff --git a/.builds/beta.yml b/.builds/beta.yml new file mode 100644 index 00000000..ec105e03 --- /dev/null +++ b/.builds/beta.yml @@ -0,0 +1,27 @@ +image: archlinux +packages: + - rustup +sources: + - https://github.com/ruma/ruma-appservice-api +tasks: + - rustup: | + # We specify --profile minimal because we'd otherwise download docs + rustup toolchain install beta --profile minimal -c rustfmt -c clippy + rustup default beta + - test: | + cd ruma-appservice-api + + # We don't want the build to stop on individual failure of independent + # tools, so capture tool exit codes and set the task exit code manually + set +e + + cargo fmt -- --check + fmt_exit=$? + + cargo clippy --all-targets --all-features -- -D warnings + clippy_exit=$? + + cargo test --verbose + test_exit=$? + + exit $(( $fmt_exit || $clippy_exit || $test_exit )) diff --git a/.builds/msrv.yml b/.builds/msrv.yml new file mode 100644 index 00000000..d919db99 --- /dev/null +++ b/.builds/msrv.yml @@ -0,0 +1,16 @@ +image: archlinux +packages: + - rustup +sources: + - https://github.com/ruma/ruma-appservice-api +tasks: + - rustup: | + # We specify --profile minimal because we'd otherwise download docs + rustup toolchain install 1.38.0 --profile minimal + rustup default 1.38.0 + - test: | + cd ruma-appservice-api + + # Only make sure the code builds with the MSRV. Tests can require later + # Rust versions, don't compile or run them. + cargo build --verbose diff --git a/.builds/nightly.yml b/.builds/nightly.yml new file mode 100644 index 00000000..72c98254 --- /dev/null +++ b/.builds/nightly.yml @@ -0,0 +1,32 @@ +image: archlinux +packages: + - rustup +sources: + - https://github.com/ruma/ruma-appservice-api +tasks: + - rustup: | + rustup toolchain install nightly --profile minimal + rustup default nightly + + # Try installing rustfmt & clippy for nightly, but don't fail the build + # if they are not available + rustup component add rustfmt || true + rustup component add clippy || true + - test: | + cd ruma-appservice-api + + # We don't want the build to stop on individual failure of independent + # tools, so capture tool exit codes and set the task exit code manually + set +e + + if ( rustup component list | grep -q rustfmt ); then + cargo fmt -- --check + fi + fmt_exit=$? + + if ( rustup component list | grep -q clippy ); then + cargo clippy --all-targets --all-features -- -D warnings + fi + clippy_exit=$? + + exit $(( $fmt_exit || $clippy_exit )) diff --git a/.builds/stable.yml b/.builds/stable.yml new file mode 100644 index 00000000..28b8f0ff --- /dev/null +++ b/.builds/stable.yml @@ -0,0 +1,29 @@ +image: archlinux +packages: + - rustup +sources: + - https://github.com/ruma/ruma-appservice-api +tasks: + - rustup: | + # We specify --profile minimal because we'd otherwise download docs + rustup toolchain install stable --profile minimal -c rustfmt -c clippy + rustup default stable + - test: | + cd ruma-appservice-api + + # We don't want the build to stop on individual failure of independent + # tools, so capture tool exit codes and set the task exit code manually + set +e + + cargo fmt -- --check + fmt_exit=$? + + cargo clippy --all-targets --all-features -- -D warnings + clippy_exit=$? + + cargo test --verbose + test_exit=$? + + exit $(( $fmt_exit || $clippy_exit || $test_exit )) + # TODO: Add audit task once cargo-audit binary releases are available. + # See https://github.com/RustSec/cargo-audit/issues/66 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3519fea0..00000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -language: "rust" -cache: "cargo" -rust: - - 1.36.0 - - stable - - beta - - nightly -jobs: - allow_failures: - - rust: nightly - fast_finish: true - -before_script: - - rustup component add rustfmt - - | - if [ "$TRAVIS_RUST_VERSION" != "1.36.0" ]; then - rustup component add clippy - fi - - | - if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then - cargo install --force cargo-audit - fi - - cargo generate-lockfile -script: - - | - if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then - cargo audit - fi - - cargo fmt -- --check - - | - if [ "$TRAVIS_RUST_VERSION" != "1.36.0" ]; then - cargo clippy --all-targets --all-features -- -D warnings - fi - - cargo build --verbose - - cargo test --verbose -if: "type != push OR (tag IS blank AND branch = master)" -notifications: - email: false - irc: - channels: - - secure: "Z4Bo39O8Zl/xGJ3A3P08sKO12YMpQOMwwWou9oZxYGnaVQM/1hlpgMrPKtif4v+681SGMuUoA97P0Tr93oSSGqyJalN2dcft9vOiFa1Izo5nVuJ1+8trTRxV+3oE7X30ixh/jWg4oXPrfLbKMv1Bp7htjffNQQcsh2RrPjmhK3PtuqTLeY0OFm6uKIa/4fmz2d2PV+V2GRhFvI4b4HRLAQDRbFrD3MUReSqqWCpAdnyswKOVZMcCNZHuBpPdZK+lARopZsruN5LcDi787CRel79K+Cmqif1jyGgwQusjrP2c4Bjdi6SGCy2V5TNMYgYrp1ox/gLaHNC3A1aHZYmbHXI908aANbt860Y/1N0ax3CbEkUFFSfiEjnw816BTJ61/kccMEUN6nYpbj/hkyNApCXYlp65+FAx2NaQCV6obvWh7ymF3Mp8v1OvidEKbhvDqhuGQ62ZZGWVUpzKAe0QRQ2NFFPm53nOrcVHdR4ZMKdGrsgAgpvX1d92JmChqlZbEjbCZRs+KHj1Bkfwkousu9+VNLQatc+VwiqXXHnOi9jCVecqmtLnioP3UvYBEQKsh2gv5GhUwluqrSMNfy3H51Zg/lLMHQHUZw5XZgb7nenCBcrmSl4h75+z1lUdkE5UQn3WcjVOVsbwS/qpHHJ+CRKnpcSBqIE1pb0BFdI5/MU=" - use_notice: true diff --git a/README.md b/README.md index f54043e3..fc1b9d25 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # ruma-appservice-api -[![Build Status](https://travis-ci.org/ruma/ruma-appservice-api.svg?branch=master)](https://travis-ci.org/ruma/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. From a742ef47df52c1186ff8f37324f1d944cf4988dd Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 7 May 2020 20:30:26 +0200 Subject: [PATCH 10/13] Use BTreeMap instead of HashMap --- src/v1/thirdparty.rs | 10 +++++----- src/v1/thirdparty/get_location_for_protocol.rs | 4 ++-- src/v1/thirdparty/get_user_for_protocol.rs | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/v1/thirdparty.rs b/src/v1/thirdparty.rs index 18fe481b..16e40245 100644 --- a/src/v1/thirdparty.rs +++ b/src/v1/thirdparty.rs @@ -6,7 +6,7 @@ pub mod get_protocol; pub mod get_user_for_protocol; pub mod get_user_for_user_id; -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_identifiers::{RoomAliasId, UserId}; @@ -22,7 +22,7 @@ pub struct Protocol { /// A content URI representing an icon for the third party protocol. pub icon: String, /// The type definitions for the fields defined in `user_fields` and `location_fields`. - pub field_types: HashMap, + pub field_types: BTreeMap, /// A list of objects representing independent instances of configuration. pub instances: Vec, } @@ -36,7 +36,7 @@ pub struct ProtocolInstance { #[serde(skip_serializing_if = "Option::is_none")] pub icon: Option, /// Preset values for `fields` the client may use to search by. - pub fields: HashMap, + pub fields: BTreeMap, /// A unique identifier across all instances. pub network_id: String, } @@ -58,7 +58,7 @@ pub struct Location { /// The protocol ID that the third party location is a part of. pub protocol: String, /// Information used to identify this third party location. - pub fields: HashMap, + pub fields: BTreeMap, } /// A third party network user. @@ -69,5 +69,5 @@ pub struct User { /// The protocol ID that the third party user is a part of. pub protocol: String, /// Information used to identify this third party user. - pub fields: HashMap, + pub fields: BTreeMap, } diff --git a/src/v1/thirdparty/get_location_for_protocol.rs b/src/v1/thirdparty/get_location_for_protocol.rs index f39154b3..6c791fd3 100644 --- a/src/v1/thirdparty/get_location_for_protocol.rs +++ b/src/v1/thirdparty/get_location_for_protocol.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/app/v1/thirdparty/location/{protocol}](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-thirdparty-location-protocol) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -23,7 +23,7 @@ ruma_api! { /// One or more custom fields to help identify the third party location. // The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352. #[ruma_api(query_map)] - pub fields: HashMap, + pub fields: BTreeMap, } response { diff --git a/src/v1/thirdparty/get_user_for_protocol.rs b/src/v1/thirdparty/get_user_for_protocol.rs index 1fe4aebb..f9fb14a2 100644 --- a/src/v1/thirdparty/get_user_for_protocol.rs +++ b/src/v1/thirdparty/get_user_for_protocol.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/app/v1/thirdparty/user/{protocol}](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-thirdparty-user-protocol) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -23,7 +23,7 @@ ruma_api! { /// One or more custom fields that are passed to the AS to help identify the user. // The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352. #[ruma_api(query_map)] - pub fields: HashMap, + pub fields: BTreeMap, } response { From 8770e914f64951e9e04d40e4151a58696ebf82b7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 7 May 2020 20:30:47 +0200 Subject: [PATCH 11/13] Update dependencies --- Cargo.toml | 12 ++++++------ src/v1/event/push_events.rs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4b3b23fd..6aa3f802 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,9 +12,9 @@ version = "0.1.0" edition = "2018" [dependencies] -ruma-api = "0.11.2" -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"] } +ruma-api = "0.16.0" +ruma-events = "0.21.0" +ruma-identifiers = "0.16.1" +serde = { version = "1.0.106", features = ["derive"] } +serde_json = "1.0.52" +url = { version = "2.1.1", features = ["serde"] } diff --git a/src/v1/event/push_events.rs b/src/v1/event/push_events.rs index 131acc57..bef1ec46 100644 --- a/src/v1/event/push_events.rs +++ b/src/v1/event/push_events.rs @@ -1,7 +1,7 @@ //! [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; +use ruma_events::{collections::all, EventJson}; ruma_api! { metadata { @@ -21,7 +21,7 @@ ruma_api! { pub txn_id: String, /// A list of events. #[ruma_api(body)] - pub events: Vec, + pub events: Vec>, } response {} From 74d1b833cd786705a12f5e03b7820573f3e2296d Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 7 May 2020 20:31:59 +0200 Subject: [PATCH 12/13] Add change log --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..69afd520 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# 0.1.0 + +Initial release. From 890cf1397304892fd690e74205c1055d6f49455a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 7 May 2020 20:36:57 +0200 Subject: [PATCH 13/13] Bump MSRV (due to bytes dependency) --- .builds/msrv.yml | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.builds/msrv.yml b/.builds/msrv.yml index d919db99..635bffdb 100644 --- a/.builds/msrv.yml +++ b/.builds/msrv.yml @@ -6,8 +6,8 @@ sources: tasks: - rustup: | # We specify --profile minimal because we'd otherwise download docs - rustup toolchain install 1.38.0 --profile minimal - rustup default 1.38.0 + rustup toolchain install 1.39.0 --profile minimal + rustup default 1.39.0 - test: | cd ruma-appservice-api diff --git a/README.md b/README.md index fc1b9d25..7d010ee5 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ These types can be shared by application service and server code. ## Minimum Rust version -ruma-appservice-api requires Rust 1.36.0 or later. +ruma-appservice-api requires Rust 1.39.0 or later. ## Status