diff options
| author | Rutger Broekhoff | 2026-11-30 11:47:36 +0100 |
|---|---|---|
| committer | Rutger Broekhoff | 2026-11-30 11:47:36 +0100 |
| commit | 02475e05ccd1aa15c6a6163834f28bfebbef796f (patch) | |
| tree | 6bc6f453f07dc76f763310e1e5eade9a3e1115b7 /server/src/rwgps.cppm | |
| parent | 5732f6c14618f50ffaf315b93795340219a67c66 (diff) | |
| download | routemon-02475e05ccd1aa15c6a6163834f28bfebbef796f.tar.gz routemon-02475e05ccd1aa15c6a6163834f28bfebbef796f.zip | |
RWGPS webhook and such
Diffstat (limited to 'server/src/rwgps.cppm')
| -rw-r--r-- | server/src/rwgps.cppm | 82 |
1 files changed, 78 insertions, 4 deletions
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 @@ | |||
| 1 | module; | 1 | module; |
| 2 | 2 | ||
| 3 | #include <boost/asio/io_context.hpp> | 3 | #include <boost/asio/io_context.hpp> |
| 4 | #include <boost/json/conversion.hpp> | ||
| 4 | 5 | ||
| 5 | export module routemon:rwgps; | 6 | export module routemon:rwgps; |
| 6 | 7 | ||
| @@ -9,6 +10,7 @@ import :http.client; | |||
| 9 | import :log; | 10 | import :log; |
| 10 | 11 | ||
| 11 | namespace net = boost::asio; | 12 | namespace net = boost::asio; |
| 13 | namespace json = boost::json; | ||
| 12 | 14 | ||
| 13 | namespace routemon::rwgps { | 15 | namespace routemon::rwgps { |
| 14 | 16 | ||
| @@ -21,6 +23,62 @@ export struct route_summary | |||
| 21 | std::string description; | 23 | std::string description; |
| 22 | }; | 24 | }; |
| 23 | 25 | ||
| 26 | enum class notification_cause | ||
| 27 | { | ||
| 28 | unknown, | ||
| 29 | created, | ||
| 30 | updated, | ||
| 31 | deleted, | ||
| 32 | added, | ||
| 33 | removed, | ||
| 34 | }; | ||
| 35 | |||
| 36 | enum class notification_item_type | ||
| 37 | { | ||
| 38 | unknown, | ||
| 39 | trip, | ||
| 40 | route, | ||
| 41 | event, | ||
| 42 | event_participant, | ||
| 43 | club_member, | ||
| 44 | authorization, | ||
| 45 | }; | ||
| 46 | |||
| 47 | enum notification_target_collection_type | ||
| 48 | { | ||
| 49 | unknown, | ||
| 50 | pinned, | ||
| 51 | }; | ||
| 52 | |||
| 53 | struct notification_target_collection | ||
| 54 | { | ||
| 55 | std::int64_t id; | ||
| 56 | notification_target_collection_type type; | ||
| 57 | std::optional<std::string> url; | ||
| 58 | }; | ||
| 59 | |||
| 60 | struct notification | ||
| 61 | { | ||
| 62 | // User that took the action | ||
| 63 | std::int64_t user_id; | ||
| 64 | notification_item_type item_type; | ||
| 65 | std::optional<std::int64_t> item_id; | ||
| 66 | // User that owns the item | ||
| 67 | std::optional<std::int64_t> item_user_id; | ||
| 68 | std::optional<std::string> item_url; | ||
| 69 | notification_cause action; | ||
| 70 | std::optional<notification_target_collection> collection; | ||
| 71 | }; | ||
| 72 | |||
| 73 | struct webhook_request | ||
| 74 | { | ||
| 75 | std::vector<notification> notifications = {}; | ||
| 76 | }; | ||
| 77 | |||
| 78 | auto tag_invoke( | ||
| 79 | json::value_to_tag<webhook_request> const&, json::value const& jv) | ||
| 80 | -> webhook_request; | ||
| 81 | |||
| 24 | struct pagination | 82 | struct pagination |
| 25 | { | 83 | { |
| 26 | std::size_t record_count; | 84 | std::size_t record_count; |
| @@ -40,19 +98,35 @@ struct get_routes_response | |||
| 40 | get_routes_meta meta; | 98 | get_routes_meta meta; |
| 41 | }; | 99 | }; |
| 42 | 100 | ||
| 101 | export class credentials | ||
| 102 | { | ||
| 103 | std::string api_key_; | ||
| 104 | std::string api_secret_; | ||
| 105 | std::string auth_token_; | ||
| 106 | |||
| 107 | public: | ||
| 108 | credentials( | ||
| 109 | std::string&& api_key, std::string&& api_secret, | ||
| 110 | std::string&& auth_token); | ||
| 111 | ~credentials(); | ||
| 112 | |||
| 113 | auto api_key() const -> std::string const&; | ||
| 114 | auto api_secret() const -> std::string const&; | ||
| 115 | auto auth_token() const -> std::string const&; | ||
| 116 | }; | ||
| 117 | |||
| 43 | export class client | 118 | export class client |
| 44 | { | 119 | { |
| 45 | log::logger l_; | 120 | log::logger l_; |
| 46 | http::client hc_; | 121 | http::client hc_; |
| 47 | std::string api_key_; | 122 | std::shared_ptr<credentials> creds_; |
| 48 | std::string auth_token_; | ||
| 49 | 123 | ||
| 50 | auto get_routes_page(std::size_t page) -> get_routes_response; | 124 | auto get_routes_page(std::size_t page) -> get_routes_response; |
| 51 | 125 | ||
| 52 | public: | 126 | public: |
| 53 | explicit client( | 127 | explicit client( |
| 54 | net::io_context& ioc, log::logger const& l, std::string api_key, | 128 | net::io_context& ioc, log::logger const& l, |
| 55 | std::string auth_token); | 129 | std::shared_ptr<credentials> creds); |
| 56 | 130 | ||
| 57 | auto get_all_routes() -> std::vector<route_summary>; | 131 | auto get_all_routes() -> std::vector<route_summary>; |
| 58 | }; | 132 | }; |