Skip to content

Commit fb34b48

Browse files
authored
Merge pull request #516 from AmbireTech/sentry-api-documentation
Sentry API documentation improvements and examples
2 parents 32f0767 + cafb868 commit fb34b48

File tree

10 files changed

+593
-45
lines changed

10 files changed

+593
-45
lines changed

primitives/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ postgres = ["bytes", "tokio-postgres", "deadpool-postgres"]
2020
# All Addresses and keystore files exist in the ganache-cli setup for testing with the EthereumAdapter
2121
test-util = []
2222

23+
[[example]]
24+
name = "channel_list_query"
25+
required-features = ["test-util"]
26+
27+
[[example]]
28+
name = "campaign_list_query"
29+
required-features = ["test-util"]
30+
31+
[[example]]
32+
name = "campaign_list_response"
33+
required-features = ["test-util"]
34+
2335
[dependencies]
2436
# (De)Serialization
2537
serde = { version = "1.0", features = ["derive"] }
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
use chrono::{TimeZone, Utc};
2+
use primitives::{
3+
sentry::campaign_list::{CampaignListQuery, ValidatorParam},
4+
test_util::{ADVERTISER, FOLLOWER, IDS, LEADER},
5+
};
6+
7+
fn main() {
8+
// Empty query - default values only
9+
{
10+
let empty_query = "";
11+
let query: CampaignListQuery = serde_qs::from_str(empty_query).unwrap();
12+
13+
assert_eq!(0, query.page);
14+
assert!(
15+
Utc::now() >= query.active_to_ge,
16+
"By default `activeTo` is set to `Utc::now()`"
17+
);
18+
assert!(query.creator.is_none());
19+
assert!(query.validator.is_none());
20+
}
21+
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+
25+
// Query with `activeTo` only
26+
{
27+
let active_to_query = "activeTo=1624192200";
28+
let active_to = CampaignListQuery {
29+
page: 0,
30+
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
31+
creator: None,
32+
validator: None,
33+
};
34+
35+
assert_eq!(active_to, serde_qs::from_str(active_to_query).unwrap());
36+
}
37+
38+
// Query with `page` & `activeTo`
39+
{
40+
let with_page_query = "page=14&activeTo=1624192200";
41+
let with_page = CampaignListQuery {
42+
page: 14,
43+
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
44+
creator: None,
45+
validator: None,
46+
};
47+
48+
assert_eq!(with_page, serde_qs::from_str(with_page_query).unwrap());
49+
}
50+
51+
// Query with `creator`
52+
{
53+
let with_creator_query =
54+
"activeTo=1624192200&creator=0xDd589B43793934EF6Ad266067A0d1D4896b0dff0";
55+
56+
let with_creator = CampaignListQuery {
57+
page: 0,
58+
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
59+
creator: Some(*ADVERTISER),
60+
validator: None,
61+
};
62+
63+
assert_eq!(
64+
with_creator,
65+
serde_qs::from_str(with_creator_query).unwrap()
66+
);
67+
}
68+
69+
// Query with `validator`
70+
// You can either have `leader` or `validator` but not both!
71+
{
72+
let with_creator_validator_query =
73+
"activeTo=1624192200&validator=0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7";
74+
let with_creator_validator = CampaignListQuery {
75+
page: 0,
76+
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
77+
creator: None,
78+
validator: Some(ValidatorParam::Validator(IDS[&FOLLOWER])),
79+
};
80+
81+
assert_eq!(
82+
with_creator_validator,
83+
serde_qs::from_str(with_creator_validator_query).unwrap()
84+
);
85+
}
86+
87+
// Query with `leader`
88+
// You can either have `leader` or `validator` but not both!
89+
{
90+
let with_leader_query =
91+
"activeTo=1624192200&leader=0x80690751969B234697e9059e04ed72195c3507fa";
92+
93+
let with_leader = CampaignListQuery {
94+
page: 0,
95+
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
96+
creator: None,
97+
validator: Some(ValidatorParam::Leader(IDS[&LEADER])),
98+
};
99+
100+
assert_eq!(with_leader, serde_qs::from_str(with_leader_query).unwrap());
101+
}
102+
103+
// Query with all parameters and `validator`
104+
// You can either have `leader` or `validator` but not both!
105+
{
106+
let full_query = "page=14&activeTo=1624192200&creator=0xDd589B43793934EF6Ad266067A0d1D4896b0dff0&validator=0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7";
107+
let full_expected = CampaignListQuery {
108+
page: 14,
109+
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
110+
creator: Some(*ADVERTISER),
111+
validator: Some(ValidatorParam::Validator(IDS[&FOLLOWER])),
112+
};
113+
114+
assert_eq!(full_expected, serde_qs::from_str(full_query).unwrap());
115+
}
116+
}
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
use primitives::sentry::campaign_list::CampaignListResponse;
2+
use serde_json::{from_value, json};
3+
4+
fn main() {
5+
let json = json!({
6+
"campaigns": [
7+
{
8+
"id": "0x936da01f9abd4d9d80c702af85c822a8",
9+
"channel": {
10+
"leader": "0x80690751969B234697e9059e04ed72195c3507fa",
11+
"follower": "0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
12+
"guardian": "0xe061E1EB461EaBE512759aa18A201B20Fe90631D",
13+
"token": "0x2BCaf6968aEC8A3b5126FBfAb5Fd419da6E8AD8E",
14+
"nonce": "0"
15+
},
16+
"creator": "0xDd589B43793934EF6Ad266067A0d1D4896b0dff0",
17+
"budget": "15000000000",
18+
"validators": [
19+
{
20+
"id": "0x80690751969B234697e9059e04ed72195c3507fa",
21+
"fee": "500000000",
22+
"url": "http://localhost:8005/"
23+
},
24+
{
25+
"id": "0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
26+
"fee": "400000000",
27+
"url": "http://localhost:8006/"
28+
}
29+
],
30+
"title": "Dummy Campaign",
31+
"pricingBounds": {
32+
"CLICK": {
33+
"min": "6000000",
34+
"max": "10000000"
35+
},
36+
"IMPRESSION": {
37+
"min": "4000000",
38+
"max": "5000000"
39+
}
40+
},
41+
"eventSubmission": {
42+
"allow": []
43+
},
44+
"adUnits": [
45+
{
46+
"ipfs": "Qmasg8FrbuSQpjFu3kRnZF9beg8rEBFrqgi1uXDRwCbX5f",
47+
"type": "legacy_250x250",
48+
"mediaUrl": "ipfs://QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR",
49+
"mediaMime": "image/jpeg",
50+
"targetUrl": "https://www.adex.network/?stremio-test-banner-1",
51+
"owner": "0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
52+
"created": 1564390800000_u64,
53+
"title": "Dummy AdUnit 1",
54+
"description": "Dummy AdUnit description 1",
55+
"archived": false
56+
},
57+
{
58+
"ipfs": "QmVhRDGXoM3Fg3HZD5xwMuxtb9ZErwC8wHt8CjsfxaiUbZ",
59+
"type": "legacy_250x250",
60+
"mediaUrl": "ipfs://QmQB7uz7Gxfy7wqAnrnBcZFaVJLos8J9gn8mRcHQU6dAi1",
61+
"mediaMime": "image/jpeg",
62+
"targetUrl": "https://www.adex.network/?adex-campaign=true&pub=stremio",
63+
"owner": "0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
64+
"created": 1564390800000_u64,
65+
"title": "Dummy AdUnit 2",
66+
"description": "Dummy AdUnit description 2",
67+
"archived": false
68+
}
69+
],
70+
"targetingRules": [],
71+
"created": 1612162800000_u64,
72+
"active_to": 4073414400000_u64
73+
},
74+
{
75+
"id": "0x127b98248f4e4b73af409d10f62daeaa",
76+
"channel": {
77+
"leader": "0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
78+
"follower": "0x80690751969B234697e9059e04ed72195c3507fa",
79+
"guardian": "0x79D358a3194d737880B3eFD94ADccD246af9F535",
80+
"token": "0x2BCaf6968aEC8A3b5126FBfAb5Fd419da6E8AD8E",
81+
"nonce": "0"
82+
},
83+
"creator": "0xDd589B43793934EF6Ad266067A0d1D4896b0dff0",
84+
"budget": "2000000000",
85+
"validators": [
86+
{
87+
"id": "0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
88+
"fee": "10000000",
89+
"url": "http://localhost:8006/"
90+
},
91+
{
92+
"id": "0x80690751969B234697e9059e04ed72195c3507fa",
93+
"fee": "5000000",
94+
"url": "http://localhost:8005/"
95+
}
96+
],
97+
"title": "Dummy Campaign 2 in Chain #1337",
98+
"pricingBounds": {
99+
"CLICK": {
100+
"min": "300000000",
101+
"max": "500000000"
102+
},
103+
"IMPRESSION": {
104+
"min": "100000000",
105+
"max": "200000000"
106+
}
107+
},
108+
"eventSubmission": {
109+
"allow": []
110+
},
111+
"adUnits": [
112+
{
113+
"ipfs": "Qmasg8FrbuSQpjFu3kRnZF9beg8rEBFrqgi1uXDRwCbX5f",
114+
"type": "legacy_250x250",
115+
"mediaUrl": "ipfs://QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR",
116+
"mediaMime": "image/jpeg",
117+
"targetUrl": "https://www.adex.network/?stremio-test-banner-1",
118+
"owner": "0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
119+
"created": 1564390800000_u64,
120+
"title": "Dummy AdUnit 1",
121+
"description": "Dummy AdUnit description 1",
122+
"archived": false
123+
},
124+
{
125+
"ipfs": "QmVhRDGXoM3Fg3HZD5xwMuxtb9ZErwC8wHt8CjsfxaiUbZ",
126+
"type": "legacy_250x250",
127+
"mediaUrl": "ipfs://QmQB7uz7Gxfy7wqAnrnBcZFaVJLos8J9gn8mRcHQU6dAi1",
128+
"mediaMime": "image/jpeg",
129+
"targetUrl": "https://www.adex.network/?adex-campaign=true&pub=stremio",
130+
"owner": "0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
131+
"created": 1564390800000_u64,
132+
"title": "Dummy AdUnit 2",
133+
"description": "Dummy AdUnit description 2",
134+
"archived": false
135+
}
136+
],
137+
"targetingRules": [],
138+
"created": 1612162800000_u64,
139+
"active_to": 4073414400000_u64
140+
},
141+
{
142+
"id": "0xa78f3492481b41a688488a7aa1ff17df",
143+
"channel": {
144+
"leader": "0x80690751969B234697e9059e04ed72195c3507fa",
145+
"follower": "0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
146+
"guardian": "0x79D358a3194d737880B3eFD94ADccD246af9F535",
147+
"token": "0x12a28f2bfBFfDf5842657235cC058242f40fDEa6",
148+
"nonce": "1"
149+
},
150+
"creator": "0x541b401362Ea1D489D322579552B099e801F3632",
151+
"budget": "2000000000",
152+
"validators": [
153+
{
154+
"id": "0x80690751969B234697e9059e04ed72195c3507fa",
155+
"fee": "200000000",
156+
"url": "http://localhost:8005/"
157+
},
158+
{
159+
"id": "0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
160+
"fee": "175000000",
161+
"url": "http://localhost:8006/"
162+
}
163+
],
164+
"title": "Dummy Campaign 3 in Chain #1",
165+
"pricingBounds": {
166+
"CLICK": {
167+
"min": "3500000",
168+
"max": "6500000"
169+
},
170+
"IMPRESSION": {
171+
"min": "1500000",
172+
"max": "2500000"
173+
}
174+
},
175+
"eventSubmission": {
176+
"allow": []
177+
},
178+
"adUnits": [
179+
{
180+
"ipfs": "QmYwcpMjmqJfo9ot1jGe9rfXsszFV1WbEA59QS7dEVHfJi",
181+
"type": "legacy_250x250",
182+
"mediaUrl": "ipfs://QmQB7uz7Gxfy7wqAnrnBcZFaVJLos8J9gn8mRcHQU6dAi1",
183+
"mediaMime": "image/jpeg",
184+
"targetUrl": "https://www.adex.network/?adex-campaign=true",
185+
"owner": "0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
186+
"created": 1564390800000_u64,
187+
"title": "Dummy AdUnit 3",
188+
"description": "Dummy AdUnit description 3",
189+
"archived": false
190+
},
191+
{
192+
"ipfs": "QmTAF3FsFDS7Ru8WChoD9ofiHTH8gAQfR4mYSnwxqTDpJH",
193+
"type": "legacy_250x250",
194+
"mediaUrl": "ipfs://QmQAcfBJpDDuH99A4p3pFtUmQwamS8UYStP5HxHC7bgYXY",
195+
"mediaMime": "image/jpeg",
196+
"targetUrl": "https://adex.network",
197+
"owner": "0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
198+
"created": 1564390800000_u64,
199+
"title": "Dummy AdUnit 4",
200+
"description": "Dummy AdUnit description 4",
201+
"archived": false
202+
}
203+
],
204+
"targetingRules": [],
205+
"created": 1612162800000_u64,
206+
"active_to": 4073414400000_u64
207+
}
208+
],
209+
"totalPages": 1,
210+
"page": 0
211+
});
212+
213+
assert!(from_value::<CampaignListResponse>(json).is_ok());
214+
}

0 commit comments

Comments
 (0)