Skip to content

Commit 6976b51

Browse files
committed
initial documentation
1 parent b3ab61c commit 6976b51

24 files changed

+378
-50
lines changed

Cargo.lock

Lines changed: 2 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

primitives/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ required-features = ["test-util"]
3232
name = "campaign_list_response"
3333
required-features = ["test-util"]
3434

35+
[[example]]
36+
name = "create_campaign"
37+
required-features = ["test-util"]
38+
3539
[dependencies]
3640
# (De)Serialization
3741
serde = { version = "1.0", features = ["derive"] }
3842
serde_json = "1.0"
39-
# TODO: Remove once we change `ChannelId` Serialize impl
40-
serde-hex = "0.1"
4143
serde_millis = "0.1"
4244
# Used prefixes on field for targeting::Input, and `campaign::Active`
4345
serde_with = "1"

primitives/examples/analytics_query.rs

Whitespace-only changes.

primitives/examples/analytics_response.rs

Whitespace-only changes.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
use primitives::{sentry::campaign_create::CreateCampaign, test_util::DUMMY_CAMPAIGN, CampaignId};
2+
use std::str::FromStr;
3+
use serde_json::json;
4+
5+
fn main() {
6+
// CreateCampaign in an HTTP request
7+
{
8+
let create_campaign = CreateCampaign::from_campaign_erased(DUMMY_CAMPAIGN.clone(), None);
9+
10+
let create_campaign_as_json_str = json!("{
11+
\"id\":null,
12+
\"channel\":{
13+
\"leader\":\"0x80690751969B234697e9059e04ed72195c3507fa\",
14+
\"follower\":\"0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7\",
15+
\"guardian\":\"0xe061E1EB461EaBE512759aa18A201B20Fe90631D\",
16+
\"token\":\"0x2BCaf6968aEC8A3b5126FBfAb5Fd419da6E8AD8E\",
17+
\"nonce\":\"987654321\"
18+
},
19+
\"creator\":\"0xaCBaDA2d5830d1875ae3D2de207A1363B316Df2F\",
20+
\"budget\":\"100000000000\",
21+
\"validators\":[
22+
{
23+
\"id\":\"0x80690751969B234697e9059e04ed72195c3507fa\",
24+
\"fee\":\"2000000\",
25+
\"url\":\"http://localhost:8005\"
26+
},
27+
{
28+
\"id\":\"0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7\",
29+
\"fee\":\"3000000\",
30+
\"url\":\"http://localhost:8006\"
31+
}
32+
],
33+
\"title\":\"Dummy Campaign\",
34+
\"pricingBounds\":{\"CLICK\":{\"min\":\"0\",\"max\":\"0\"},\"IMPRESSION\":{\"min\":\"1\",\"max\":\"10\"}},
35+
\"eventSubmission\":{\"allow\":[]},
36+
\"targetingRules\":[],
37+
\"created\":1612162800000,
38+
\"active_to\":4073414400000
39+
}");
40+
41+
let create_campaign_from_json = serde_json::from_str(create_campaign_as_json_str).expect("should deserialize");
42+
43+
assert_eq!(create_campaign, create_campaign_from_json);
44+
}
45+
46+
// CreateCampaign with a provided ID
47+
{
48+
let mut create_campaign = CreateCampaign::from_campaign_erased(DUMMY_CAMPAIGN.clone(), None);
49+
create_campaign.id = Some(CampaignId::from_str("0x936da01f9abd4d9d80c702af85c822a8").expect("Should be valid id"));
50+
51+
let create_campaign_as_json_str = "{
52+
\"id\":\"0x936da01f9abd4d9d80c702af85c822a8\",
53+
\"channel\":{
54+
\"leader\":\"0x80690751969B234697e9059e04ed72195c3507fa\",
55+
\"follower\":\"0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7\",
56+
\"guardian\":\"0xe061E1EB461EaBE512759aa18A201B20Fe90631D\",
57+
\"token\":\"0x2BCaf6968aEC8A3b5126FBfAb5Fd419da6E8AD8E\",
58+
\"nonce\":\"987654321\"
59+
},
60+
\"creator\":\"0xaCBaDA2d5830d1875ae3D2de207A1363B316Df2F\",
61+
\"budget\":\"100000000000\",
62+
\"validators\":[
63+
{
64+
\"id\":\"0x80690751969B234697e9059e04ed72195c3507fa\",
65+
\"fee\":\"2000000\",
66+
\"url\":\"http://localhost:8005\"
67+
},
68+
{
69+
\"id\":\"0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7\",
70+
\"fee\":\"3000000\",
71+
\"url\":\"http://localhost:8006\"
72+
}
73+
],
74+
\"title\":\"Dummy Campaign\",
75+
\"pricingBounds\":{\"CLICK\":{\"min\":\"0\",\"max\":\"0\"},\"IMPRESSION\":{\"min\":\"1\",\"max\":\"10\"}},
76+
\"eventSubmission\":{\"allow\":[]},
77+
\"targetingRules\":[],
78+
\"created\":1612162800000,
79+
\"active_to\":4073414400000
80+
}";
81+
82+
let create_campaign_from_json = serde_json::from_str(create_campaign_as_json_str).expect("should deserialize");
83+
84+
assert_eq!(create_campaign, create_campaign_from_json);
85+
}
86+
}

primitives/examples/modify_campaign.rs

Whitespace-only changes.

primitives/src/campaign_validator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Validator for Campaign {
7272
.find_chain_of(self.channel.token)
7373
.ok_or(Validation::UnlistedAsset)?;
7474

75-
// Check if the campaign budget is above the minimum deposit configured
75+
// Check if the campaign budget is above the minimum campaign budget configured
7676
if self
7777
.budget
7878
.to_precision(chain_context.token.precision.get())

primitives/src/sentry.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,12 @@ pub mod campaign_create {
802802

803803
/// All fields are present except the `CampaignId` which is randomly created
804804
/// This struct defines the Body of the request (in JSON)
805+
///
806+
/// # Examples
807+
///
808+
/// ```
809+
#[doc = include_str!("../examples/create_campaign.rs")]
810+
/// ```
805811
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
806812
#[serde(rename_all = "camelCase")]
807813
pub struct CreateCampaign {
@@ -889,7 +895,12 @@ pub mod campaign_modify {
889895
AdUnit, Campaign, EventSubmission, UnifiedNum,
890896
};
891897

892-
// All editable fields stored in one place, used for checking when a budget is changed
898+
/// All editable fields stored in one place, used for checking when a budget is changed
899+
///
900+
/// # Examples:
901+
/// ```
902+
#[doc = include_str!("../examples/modify_campaign.rs")]
903+
/// ```
893904
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
894905
pub struct ModifyCampaign {
895906
pub budget: Option<UnifiedNum>,

sentry/docs/analytics/examples.js

Whitespace-only changes.

sentry/docs/analytics/glossary.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[`AllowedKey`](`primitives::query::AllowedKey`)
2+
3+
[`Analytics`](`primitives::Analytics`)
4+
5+
[`Auth`](crate::Auth)
6+
7+
[`ResponseError`](`crate::response::ResponseError`)
8+
9+
[`AnalyticsQuery`](`primitives::AnalyticsQuery`)

0 commit comments

Comments
 (0)