summaryrefslogtreecommitdiffstats
path: root/server/src/rwgps.cppm
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/rwgps.cppm')
-rw-r--r--server/src/rwgps.cppm82
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 @@
1module; 1module;
2 2
3#include <boost/asio/io_context.hpp> 3#include <boost/asio/io_context.hpp>
4#include <boost/json/conversion.hpp>
4 5
5export module routemon:rwgps; 6export module routemon:rwgps;
6 7
@@ -9,6 +10,7 @@ import :http.client;
9import :log; 10import :log;
10 11
11namespace net = boost::asio; 12namespace net = boost::asio;
13namespace json = boost::json;
12 14
13namespace routemon::rwgps { 15namespace routemon::rwgps {
14 16
@@ -21,6 +23,62 @@ export struct route_summary
21 std::string description; 23 std::string description;
22}; 24};
23 25
26enum class notification_cause
27{
28 unknown,
29 created,
30 updated,
31 deleted,
32 added,
33 removed,
34};
35
36enum class notification_item_type
37{
38 unknown,
39 trip,
40 route,
41 event,
42 event_participant,
43 club_member,
44 authorization,
45};
46
47enum notification_target_collection_type
48{
49 unknown,
50 pinned,
51};
52
53struct notification_target_collection
54{
55 std::int64_t id;
56 notification_target_collection_type type;
57 std::optional<std::string> url;
58};
59
60struct 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
73struct webhook_request
74{
75 std::vector<notification> notifications = {};
76};
77
78auto tag_invoke(
79 json::value_to_tag<webhook_request> const&, json::value const& jv)
80 -> webhook_request;
81
24struct pagination 82struct 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
101export class credentials
102{
103 std::string api_key_;
104 std::string api_secret_;
105 std::string auth_token_;
106
107public:
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
43export class client 118export 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
52public: 126public:
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};