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
//! Event journal reads: snapshots, replay pages and the live subscription.
use std::sync::Arc;
use super::{Events, PublicEvents, page::limit_query};
use crate::{
Result,
events::EventStream,
model::{EventPage, PrivateSnapshot, PublicSnapshot},
transport::{Call, ops},
types::Cursor,
};
impl PublicEvents<'_> {
/// The public books at a journal cursor (`GET /v1/snapshot`).
pub async fn snapshot(&self) -> Result<PublicSnapshot> {
self.inner.send(Call::new(&ops::GET_SNAPSHOT), None).await
}
/// The public events after `after`, at most `limit` (1 to 500; server default 100)
/// (`GET /v1/events`).
pub async fn page(&self, after: Cursor, limit: Option<u16>) -> Result<EventPage> {
let call = limit_query(Call::new(&ops::GET_EVENTS).query("after", after), limit);
self.inner.send(call, None).await
}
/// The public journal as a live [`EventStream`]. Lazy: nothing is sent before the first
/// poll. The stream owns what it needs, so it outlives the handle.
pub fn subscribe(&self) -> EventStream {
EventStream::new(Arc::clone(self.inner), None)
}
}
impl Events<'_> {
/// The reader's orders, fills and quote identities at a journal cursor
/// (`GET /v1/me/snapshot`).
pub async fn snapshot(&self) -> Result<PrivateSnapshot> {
self.inner.send(Call::new(&ops::GET_MY_SNAPSHOT), self.auth).await
}
/// The reader's events after `after`, at most `limit` (1 to 500; server default 100)
/// (`GET /v1/me/events`).
pub async fn page(&self, after: Cursor, limit: Option<u16>) -> Result<EventPage> {
let call = limit_query(Call::new(&ops::GET_MY_EVENTS).query("after", after), limit);
self.inner.send(call, self.auth).await
}
/// The reader's journal as a live [`EventStream`]. Lazy: nothing is sent before the first
/// poll. The stream owns what it needs, so it outlives the handle; it follows renewals of a
/// session's token and ends on sign-out.
pub fn subscribe(&self) -> EventStream {
EventStream::new(Arc::clone(self.inner), self.auth.cloned())
}
}
#[cfg(test)]
mod tests;