1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::{
client::client::Client,
model::notifications::{GetNotificationsRequest, Notification, NotificationsWrapper},
};
/// Notifications.
///
/// [Splitwise API docs](https://dev.splitwise.com/#tag/notifications)
#[derive(Debug)]
pub struct NotificationsSvc<'c> {
client: &'c Client,
}
impl<'c> NotificationsSvc<'c> {
/// Creates an instance of `NotificationsSvc`.
pub fn new(client: &'c Client) -> Self {
Self { client }
}
/// Return a list of recent activity on the users account with the most
/// recent items first. `content` will be suitable for display in HTML and
/// uses only the `<strong>`, `<strike>`, `<small>`, `<br>` and `<font
/// color="#FFEE44">` tags.
///
/// The `type` value indicates what the notification is about. Notification
/// types may be added in the future without warning. Below is an
/// incomplete list of notification types.
///
/// [Splitwise API docs](https://dev.splitwise.com/#tag/notifications/paths/~1get_notifications/get)
pub async fn get_notifications(
&self,
request: GetNotificationsRequest,
) -> Result<Vec<Notification>, anyhow::Error> {
let mut url = self.client.base_url.join("get_notifications")?;
let query = serde_qs::to_string(&request)?;
url.set_query(Some(&query));
let response: NotificationsWrapper = self.client.get(url).await?;
Ok(response.notifications)
}
}
#[cfg(test)]
mod integration_tests {
use test_log::test;
use super::*;
#[test(tokio::test)]
async fn get_notifications_works() {
let request = GetNotificationsRequest::default();
Client::default()
.notifications()
.get_notifications(request)
.await
.unwrap();
}
}