From 02475e05ccd1aa15c6a6163834f28bfebbef796f Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Mon, 30 Nov 2026 11:47:36 +0100 Subject: RWGPS webhook and such --- server/src/rwgps.cppm | 82 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 4 deletions(-) (limited to 'server/src/rwgps.cppm') diff --git a/server/src/rwgps.cppm b/server/src/rwgps.cppm index 2ed124e..880ea3a 100644 --- a/server/src/rwgps.cppm +++ b/server/src/rwgps.cppm @@ -1,6 +1,7 @@ module; #include +#include export module routemon:rwgps; @@ -9,6 +10,7 @@ import :http.client; import :log; namespace net = boost::asio; +namespace json = boost::json; namespace routemon::rwgps { @@ -21,6 +23,62 @@ export struct route_summary std::string description; }; +enum class notification_cause +{ + unknown, + created, + updated, + deleted, + added, + removed, +}; + +enum class notification_item_type +{ + unknown, + trip, + route, + event, + event_participant, + club_member, + authorization, +}; + +enum notification_target_collection_type +{ + unknown, + pinned, +}; + +struct notification_target_collection +{ + std::int64_t id; + notification_target_collection_type type; + std::optional url; +}; + +struct notification +{ + // User that took the action + std::int64_t user_id; + notification_item_type item_type; + std::optional item_id; + // User that owns the item + std::optional item_user_id; + std::optional item_url; + notification_cause action; + std::optional collection; +}; + +struct webhook_request +{ + std::vector notifications = {}; +}; + +auto tag_invoke( + json::value_to_tag const&, json::value const& jv) + -> webhook_request; + struct pagination { std::size_t record_count; @@ -40,19 +98,35 @@ struct get_routes_response get_routes_meta meta; }; +export class credentials +{ + std::string api_key_; + std::string api_secret_; + std::string auth_token_; + +public: + credentials( + std::string&& api_key, std::string&& api_secret, + std::string&& auth_token); + ~credentials(); + + auto api_key() const -> std::string const&; + auto api_secret() const -> std::string const&; + auto auth_token() const -> std::string const&; +}; + export class client { log::logger l_; http::client hc_; - std::string api_key_; - std::string auth_token_; + std::shared_ptr creds_; auto get_routes_page(std::size_t page) -> get_routes_response; public: explicit client( - net::io_context& ioc, log::logger const& l, std::string api_key, - std::string auth_token); + net::io_context& ioc, log::logger const& l, + std::shared_ptr creds); auto get_all_routes() -> std::vector; }; -- cgit v1.3.1