Skip to content

Commit eec0500

Browse files
committed
Sentry API docs:
- Improve routing docs Add query examples for: - /v5/campaign/list - /v5/channel/list Improve other doc comments
1 parent cbe5c78 commit eec0500

File tree

8 files changed

+263
-46
lines changed

8 files changed

+263
-46
lines changed

primitives/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ postgres = ["bytes", "tokio-postgres", "deadpool-postgres"]
1616
# All Addresses and keystore files exist in the ganache-cli setup for testing with the EthereumAdapter
1717
test-util = []
1818

19+
[[example]]
20+
name = "channel_list_query"
21+
required-features = ["test-util"]
22+
23+
[[example]]
24+
name = "campaign_list_query"
25+
required-features = ["test-util"]
26+
1927
[dependencies]
2028
# (De)Serialization
2129
serde = { version = "^1.0", features = ['derive'] }

sentry/examples/campaign_list_query.rs renamed to primitives/examples/campaign_list_query.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use chrono::{TimeZone, Utc};
22
use primitives::{
33
sentry::campaign_list::{CampaignListQuery, ValidatorParam},
4-
test_util::{ADVERTISER, FOLLOWER, LEADER},
4+
test_util::{ADVERTISER, FOLLOWER, IDS, LEADER},
55
};
66

77
fn main() {
@@ -19,6 +19,9 @@ fn main() {
1919
assert!(query.validator.is_none());
2020
}
2121

22+
// In the following examples we always use `activeTo`
23+
// as it makes simpler examples for assertions rather than using the default `Utc::now()`
24+
2225
// Query with `activeTo` only
2326
{
2427
let active_to_query = "activeTo=1624192200";
@@ -64,13 +67,15 @@ fn main() {
6467
}
6568

6669
// Query with `validator`
70+
// You can either have `leader` or `validator` but not both!
6771
{
68-
let with_creator_validator_query = "page=0&activeTo=1624192200&creator=0xDd589B43793934EF6Ad266067A0d1D4896b0dff0&validator=0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7";
72+
let with_creator_validator_query =
73+
"activeTo=1624192200&validator=0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7";
6974
let with_creator_validator = CampaignListQuery {
7075
page: 0,
7176
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
72-
creator: Some(*ADVERTISER),
73-
validator: Some(ValidatorParam::Validator((*FOLLOWER).into())),
77+
creator: None,
78+
validator: Some(ValidatorParam::Validator(IDS[&FOLLOWER])),
7479
};
7580

7681
assert_eq!(
@@ -80,16 +85,31 @@ fn main() {
8085
}
8186

8287
// Query with `leader`
88+
// You can either have `leader` or `validator` but not both!
8389
{
84-
let with_leader_query = "page=0&activeTo=1624192200&creator=0xDd589B43793934EF6Ad266067A0d1D4896b0dff0&leader=0x80690751969B234697e9059e04ed72195c3507fa";
90+
let with_leader_query = "activeTo=1624192200&leader=0x80690751969B234697e9059e04ed72195c3507fa";
8591

8692
let with_leader = CampaignListQuery {
8793
page: 0,
8894
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
89-
creator: Some(*ADVERTISER),
90-
validator: Some(ValidatorParam::Leader((*LEADER).into())),
95+
creator: None,
96+
validator: Some(ValidatorParam::Leader(IDS[&LEADER])),
9197
};
9298

9399
assert_eq!(with_leader, serde_qs::from_str(with_leader_query).unwrap());
94100
}
101+
102+
// Query with all parameters and `validator`
103+
// You can either have `leader` or `validator` but not both!
104+
{
105+
let full_query = "page=14&activeTo=1624192200&creator=0xDd589B43793934EF6Ad266067A0d1D4896b0dff0&validator=0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7";
106+
let full_expected = CampaignListQuery {
107+
page: 14,
108+
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
109+
creator: Some(*ADVERTISER),
110+
validator: Some(ValidatorParam::Validator(IDS[&FOLLOWER])),
111+
};
112+
113+
assert_eq!(full_expected, serde_qs::from_str(full_query).unwrap());
114+
}
95115
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use primitives::{
2+
sentry::channel_list::ChannelListQuery,
3+
test_util::{IDS, LEADER},
4+
ChainId,
5+
};
6+
7+
fn main() {
8+
// An empty query
9+
{
10+
let empty = "";
11+
let empty_expected = ChannelListQuery {
12+
page: 0,
13+
validator: None,
14+
chains: vec![],
15+
};
16+
17+
assert_eq!(empty_expected, serde_qs::from_str(empty).unwrap());
18+
}
19+
20+
// Query with `page`
21+
{
22+
let only_page = "page=14";
23+
let only_page_expected = ChannelListQuery {
24+
page: 14,
25+
validator: None,
26+
chains: vec![],
27+
};
28+
29+
assert_eq!(only_page_expected, serde_qs::from_str(only_page).unwrap());
30+
}
31+
32+
// Query with `validator`
33+
{
34+
let only_validator = "validator=0x80690751969B234697e9059e04ed72195c3507fa";
35+
let only_validator_expected = ChannelListQuery {
36+
page: 0,
37+
validator: Some(IDS[&LEADER]),
38+
chains: vec![],
39+
};
40+
41+
assert_eq!(
42+
only_validator_expected,
43+
serde_qs::from_str(only_validator).unwrap()
44+
);
45+
}
46+
47+
// Query with `chains`
48+
{
49+
let chains_query = "chains[]=1&chains[]=1337";
50+
let chains_expected = ChannelListQuery {
51+
page: 0,
52+
validator: None,
53+
chains: vec![ChainId::new(1), ChainId::new(1337)],
54+
};
55+
56+
assert_eq!(chains_expected, serde_qs::from_str(chains_query).unwrap());
57+
}
58+
59+
// Query with all parameters
60+
{
61+
let all_query =
62+
"page=14&validator=0x80690751969B234697e9059e04ed72195c3507fa&chains[]=1&chains[]=1337";
63+
let all_expected = ChannelListQuery {
64+
page: 14,
65+
validator: Some(IDS[&LEADER]),
66+
chains: vec![ChainId::new(1), ChainId::new(1337)],
67+
};
68+
69+
assert_eq!(all_expected, serde_qs::from_str(all_query).unwrap());
70+
}
71+
}

primitives/src/address.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,13 @@ impl TryFrom<&str> for Address {
111111
}
112112
}
113113

114-
/// When we have a string literal (&str) representation of the Address in the form of bytes.
114+
/// When we have a string literal (`&str`) representation of the `Address` in the form of bytes.
115115
/// Useful for creating static values from strings for testing, configuration, etc.
116116
///
117-
/// You can find a test setup example in the [`crate::test_util`] module.
117+
/// You can find a test setup example in the `crate::test_util` module (requires `test-util` feature).
118118
///
119119
/// # Example
120+
///
120121
/// ```
121122
/// use once_cell::sync::Lazy;
122123
/// use primitives::Address;

primitives/src/sentry.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,14 @@ pub mod channel_list {
653653
pub pagination: Pagination,
654654
}
655655

656-
#[derive(Debug, Serialize, Deserialize)]
656+
/// `GET /v5/channel/list` query
657+
///
658+
/// # Examples
659+
///
660+
/// ```
661+
#[doc = include_str!("../examples/channel_list_query.rs")]
662+
/// ```
663+
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
657664
pub struct ChannelListQuery {
658665
/// default is `u64::default()` = `0`
659666
#[serde(default)]
@@ -681,6 +688,13 @@ pub mod campaign_list {
681688
pub pagination: Pagination,
682689
}
683690

691+
/// `GET /v5/campaign/list` query
692+
///
693+
/// # Examples
694+
///
695+
/// ```
696+
#[doc = include_str!("../examples/campaign_list_query.rs")]
697+
/// ```
684698
#[derive(Debug, Serialize, Deserialize, PartialEq)]
685699
pub struct CampaignListQuery {
686700
/// default is `u64::default()` = `0`

0 commit comments

Comments
 (0)