Skip to content

Sentry API documentation improvements and examples #516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ postgres = ["bytes", "tokio-postgres", "deadpool-postgres"]
# All Addresses and keystore files exist in the ganache-cli setup for testing with the EthereumAdapter
test-util = []

[[example]]
name = "channel_list_query"
required-features = ["test-util"]

[[example]]
name = "campaign_list_query"
required-features = ["test-util"]

[[example]]
name = "campaign_list_response"
required-features = ["test-util"]

[dependencies]
# (De)Serialization
serde = { version = "^1.0", features = ['derive'] }
Expand Down
116 changes: 116 additions & 0 deletions primitives/examples/campaign_list_query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
use chrono::{TimeZone, Utc};
use primitives::{
sentry::campaign_list::{CampaignListQuery, ValidatorParam},
test_util::{ADVERTISER, FOLLOWER, IDS, LEADER},
};

fn main() {
// Empty query - default values only
{
let empty_query = "";
let query: CampaignListQuery = serde_qs::from_str(empty_query).unwrap();

assert_eq!(0, query.page);
assert!(
Utc::now() >= query.active_to_ge,
"By default `activeTo` is set to `Utc::now()`"
);
assert!(query.creator.is_none());
assert!(query.validator.is_none());
}

// In the following examples we always use `activeTo`
// as it makes simpler examples for assertions rather than using the default `Utc::now()`

// Query with `activeTo` only
{
let active_to_query = "activeTo=1624192200";
let active_to = CampaignListQuery {
page: 0,
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
creator: None,
validator: None,
};

assert_eq!(active_to, serde_qs::from_str(active_to_query).unwrap());
}

// Query with `page` & `activeTo`
{
let with_page_query = "page=14&activeTo=1624192200";
let with_page = CampaignListQuery {
page: 14,
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
creator: None,
validator: None,
};

assert_eq!(with_page, serde_qs::from_str(with_page_query).unwrap());
}

// Query with `creator`
{
let with_creator_query =
"activeTo=1624192200&creator=0xDd589B43793934EF6Ad266067A0d1D4896b0dff0";

let with_creator = CampaignListQuery {
page: 0,
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
creator: Some(*ADVERTISER),
validator: None,
};

assert_eq!(
with_creator,
serde_qs::from_str(with_creator_query).unwrap()
);
}

// Query with `validator`
// You can either have `leader` or `validator` but not both!
{
let with_creator_validator_query =
"activeTo=1624192200&validator=0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7";
let with_creator_validator = CampaignListQuery {
page: 0,
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
creator: None,
validator: Some(ValidatorParam::Validator(IDS[&FOLLOWER])),
};

assert_eq!(
with_creator_validator,
serde_qs::from_str(with_creator_validator_query).unwrap()
);
}

// Query with `leader`
// You can either have `leader` or `validator` but not both!
{
let with_leader_query =
"activeTo=1624192200&leader=0x80690751969B234697e9059e04ed72195c3507fa";

let with_leader = CampaignListQuery {
page: 0,
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
creator: None,
validator: Some(ValidatorParam::Leader(IDS[&LEADER])),
};

assert_eq!(with_leader, serde_qs::from_str(with_leader_query).unwrap());
}

// Query with all parameters and `validator`
// You can either have `leader` or `validator` but not both!
{
let full_query = "page=14&activeTo=1624192200&creator=0xDd589B43793934EF6Ad266067A0d1D4896b0dff0&validator=0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7";
let full_expected = CampaignListQuery {
page: 14,
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
creator: Some(*ADVERTISER),
validator: Some(ValidatorParam::Validator(IDS[&FOLLOWER])),
};

assert_eq!(full_expected, serde_qs::from_str(full_query).unwrap());
}
}
214 changes: 214 additions & 0 deletions primitives/examples/campaign_list_response.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
use primitives::sentry::campaign_list::CampaignListResponse;
use serde_json::{from_value, json};

fn main() {
let json = json!({
"campaigns": [
{
"id": "0x936da01f9abd4d9d80c702af85c822a8",
"channel": {
"leader": "0x80690751969B234697e9059e04ed72195c3507fa",
"follower": "0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
"guardian": "0xe061E1EB461EaBE512759aa18A201B20Fe90631D",
"token": "0x2BCaf6968aEC8A3b5126FBfAb5Fd419da6E8AD8E",
"nonce": "0"
},
"creator": "0xDd589B43793934EF6Ad266067A0d1D4896b0dff0",
"budget": "15000000000",
"validators": [
{
"id": "0x80690751969B234697e9059e04ed72195c3507fa",
"fee": "500000000",
"url": "http://localhost:8005/"
},
{
"id": "0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
"fee": "400000000",
"url": "http://localhost:8006/"
}
],
"title": "Dummy Campaign",
"pricingBounds": {
"CLICK": {
"min": "6000000",
"max": "10000000"
},
"IMPRESSION": {
"min": "4000000",
"max": "5000000"
}
},
"eventSubmission": {
"allow": []
},
"adUnits": [
{
"ipfs": "Qmasg8FrbuSQpjFu3kRnZF9beg8rEBFrqgi1uXDRwCbX5f",
"type": "legacy_250x250",
"mediaUrl": "ipfs://QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR",
"mediaMime": "image/jpeg",
"targetUrl": "https://www.adex.network/?stremio-test-banner-1",
"owner": "0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
"created": 1564390800000_u64,
"title": "Dummy AdUnit 1",
"description": "Dummy AdUnit description 1",
"archived": false
},
{
"ipfs": "QmVhRDGXoM3Fg3HZD5xwMuxtb9ZErwC8wHt8CjsfxaiUbZ",
"type": "legacy_250x250",
"mediaUrl": "ipfs://QmQB7uz7Gxfy7wqAnrnBcZFaVJLos8J9gn8mRcHQU6dAi1",
"mediaMime": "image/jpeg",
"targetUrl": "https://www.adex.network/?adex-campaign=true&pub=stremio",
"owner": "0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
"created": 1564390800000_u64,
"title": "Dummy AdUnit 2",
"description": "Dummy AdUnit description 2",
"archived": false
}
],
"targetingRules": [],
"created": 1612162800000_u64,
"active_to": 4073414400000_u64
},
{
"id": "0x127b98248f4e4b73af409d10f62daeaa",
"channel": {
"leader": "0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
"follower": "0x80690751969B234697e9059e04ed72195c3507fa",
"guardian": "0x79D358a3194d737880B3eFD94ADccD246af9F535",
"token": "0x2BCaf6968aEC8A3b5126FBfAb5Fd419da6E8AD8E",
"nonce": "0"
},
"creator": "0xDd589B43793934EF6Ad266067A0d1D4896b0dff0",
"budget": "2000000000",
"validators": [
{
"id": "0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
"fee": "10000000",
"url": "http://localhost:8006/"
},
{
"id": "0x80690751969B234697e9059e04ed72195c3507fa",
"fee": "5000000",
"url": "http://localhost:8005/"
}
],
"title": "Dummy Campaign 2 in Chain #1337",
"pricingBounds": {
"CLICK": {
"min": "300000000",
"max": "500000000"
},
"IMPRESSION": {
"min": "100000000",
"max": "200000000"
}
},
"eventSubmission": {
"allow": []
},
"adUnits": [
{
"ipfs": "Qmasg8FrbuSQpjFu3kRnZF9beg8rEBFrqgi1uXDRwCbX5f",
"type": "legacy_250x250",
"mediaUrl": "ipfs://QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR",
"mediaMime": "image/jpeg",
"targetUrl": "https://www.adex.network/?stremio-test-banner-1",
"owner": "0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
"created": 1564390800000_u64,
"title": "Dummy AdUnit 1",
"description": "Dummy AdUnit description 1",
"archived": false
},
{
"ipfs": "QmVhRDGXoM3Fg3HZD5xwMuxtb9ZErwC8wHt8CjsfxaiUbZ",
"type": "legacy_250x250",
"mediaUrl": "ipfs://QmQB7uz7Gxfy7wqAnrnBcZFaVJLos8J9gn8mRcHQU6dAi1",
"mediaMime": "image/jpeg",
"targetUrl": "https://www.adex.network/?adex-campaign=true&pub=stremio",
"owner": "0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
"created": 1564390800000_u64,
"title": "Dummy AdUnit 2",
"description": "Dummy AdUnit description 2",
"archived": false
}
],
"targetingRules": [],
"created": 1612162800000_u64,
"active_to": 4073414400000_u64
},
{
"id": "0xa78f3492481b41a688488a7aa1ff17df",
"channel": {
"leader": "0x80690751969B234697e9059e04ed72195c3507fa",
"follower": "0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
"guardian": "0x79D358a3194d737880B3eFD94ADccD246af9F535",
"token": "0x12a28f2bfBFfDf5842657235cC058242f40fDEa6",
"nonce": "1"
},
"creator": "0x541b401362Ea1D489D322579552B099e801F3632",
"budget": "2000000000",
"validators": [
{
"id": "0x80690751969B234697e9059e04ed72195c3507fa",
"fee": "200000000",
"url": "http://localhost:8005/"
},
{
"id": "0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
"fee": "175000000",
"url": "http://localhost:8006/"
}
],
"title": "Dummy Campaign 3 in Chain #1",
"pricingBounds": {
"CLICK": {
"min": "3500000",
"max": "6500000"
},
"IMPRESSION": {
"min": "1500000",
"max": "2500000"
}
},
"eventSubmission": {
"allow": []
},
"adUnits": [
{
"ipfs": "QmYwcpMjmqJfo9ot1jGe9rfXsszFV1WbEA59QS7dEVHfJi",
"type": "legacy_250x250",
"mediaUrl": "ipfs://QmQB7uz7Gxfy7wqAnrnBcZFaVJLos8J9gn8mRcHQU6dAi1",
"mediaMime": "image/jpeg",
"targetUrl": "https://www.adex.network/?adex-campaign=true",
"owner": "0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
"created": 1564390800000_u64,
"title": "Dummy AdUnit 3",
"description": "Dummy AdUnit description 3",
"archived": false
},
{
"ipfs": "QmTAF3FsFDS7Ru8WChoD9ofiHTH8gAQfR4mYSnwxqTDpJH",
"type": "legacy_250x250",
"mediaUrl": "ipfs://QmQAcfBJpDDuH99A4p3pFtUmQwamS8UYStP5HxHC7bgYXY",
"mediaMime": "image/jpeg",
"targetUrl": "https://adex.network",
"owner": "0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
"created": 1564390800000_u64,
"title": "Dummy AdUnit 4",
"description": "Dummy AdUnit description 4",
"archived": false
}
],
"targetingRules": [],
"created": 1612162800000_u64,
"active_to": 4073414400000_u64
}
],
"totalPages": 1,
"page": 0
});

assert!(from_value::<CampaignListResponse>(json).is_ok());
}
Loading