Struct primitives::sentry::campaign_create::CreateCampaign
source · pub struct CreateCampaign {
pub id: Option<CampaignId>,
pub channel: Channel,
pub creator: Address,
pub budget: UnifiedNum,
pub validators: Validators,
pub title: Option<String>,
pub pricing_bounds: PricingBounds,
pub event_submission: Option<EventSubmission>,
pub ad_units: Vec<AdUnit>,
pub targeting_rules: Rules,
pub created: DateTime<Utc>,
pub active: Active,
}
Expand description
All fields are present except the CampaignId
which is randomly created
This struct defines the Body of the request (in JSON)
Examples
use primitives::{sentry::campaign_create::CreateCampaign, test_util::DUMMY_CAMPAIGN, CampaignId};
use serde_json::json;
use std::str::FromStr;
fn main() {
// CreateCampaign in an HTTP request.
// A CampaignId will be randomly generated for the newly created Campaign.
{
let create_campaign = CreateCampaign::from_campaign_erased(DUMMY_CAMPAIGN.clone(), None);
let _create_campaign_str =
serde_json::to_string(&create_campaign).expect("should serialize");
let create_campaign_json = json!({
"channel":{
"leader":"0x80690751969B234697e9059e04ed72195c3507fa",
"follower":"0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
"guardian":"0xe061E1EB461EaBE512759aa18A201B20Fe90631D",
"token":"0x2BCaf6968aEC8A3b5126FBfAb5Fd419da6E8AD8E",
"nonce":"987654321"
},
"creator":"0xaCBaDA2d5830d1875ae3D2de207A1363B316Df2F",
"budget":"100000000000",
"validators":[
{
"id":"0x80690751969B234697e9059e04ed72195c3507fa",
"fee":"3000",
"url":"http://localhost:8005"
},
{
"id":"0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
"fee":"2000",
"url":"http://localhost:8006"
}
],
"title":"Dummy Campaign",
"pricingBounds":{
"CLICK":{"min":"0","max":"0"},
"IMPRESSION":{"min":"1","max":"10"}
},
"eventSubmission":{"allow":[]},
"targetingRules":[],
"created":1612162800000_u64,
"activeTo":4073414400000_u64
});
let create_campaign_json =
serde_json::to_string(&create_campaign_json).expect("should serialize");
let deserialized: CreateCampaign =
serde_json::from_str(&create_campaign_json).expect("should deserialize");
assert_eq!(create_campaign, deserialized);
}
// CreateCampaign with a provided ID
{
let mut create_campaign =
CreateCampaign::from_campaign_erased(DUMMY_CAMPAIGN.clone(), None);
create_campaign.id = Some(
CampaignId::from_str("0x936da01f9abd4d9d80c702af85c822a8").expect("Should be valid id"),
);
let create_campaign_json = json!({
"id":"0x936da01f9abd4d9d80c702af85c822a8",
"channel":{
"leader":"0x80690751969B234697e9059e04ed72195c3507fa",
"follower":"0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
"guardian":"0xe061E1EB461EaBE512759aa18A201B20Fe90631D",
"token":"0x2BCaf6968aEC8A3b5126FBfAb5Fd419da6E8AD8E",
"nonce":"987654321"
},
"creator":"0xaCBaDA2d5830d1875ae3D2de207A1363B316Df2F",
"budget":"100000000000",
"validators":[
{
"id":"0x80690751969B234697e9059e04ed72195c3507fa",
"fee":"3000",
"url":"http://localhost:8005"
},
{
"id":"0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
"fee":"2000",
"url":"http://localhost:8006"
}
],
"title":"Dummy Campaign",
"pricingBounds":{"CLICK":{"min":"0","max":"0"},"IMPRESSION":{"min":"1","max":"10"}},
"eventSubmission":{"allow":[]},
"targetingRules":[],
"created":1612162800000_u64,
"activeTo":4073414400000_u64
});
let create_campaign_json =
serde_json::to_string(&create_campaign_json).expect("should serialize");
let deserialized: CreateCampaign =
serde_json::from_str(&create_campaign_json).expect("should deserialize");
assert_eq!(create_campaign, deserialized);
}
}
Fields
id: Option<CampaignId>
channel: Channel
creator: Address
budget: UnifiedNum
validators: Validators
title: Option<String>
pricing_bounds: PricingBounds
Event pricing bounds
event_submission: Option<EventSubmission>
EventSubmission object, applies to event submission (POST /channel/:id/events)
ad_units: Vec<AdUnit>
An array of AdUnit (optional)
targeting_rules: Rules
created: DateTime<Utc>
A millisecond timestamp of when the campaign was created
active: Active
A millisecond timestamp representing the time you want this campaign to become active (optional) Used by the AdViewManager & Targeting AIP#31
Implementations
sourceimpl CreateCampaign
impl CreateCampaign
sourcepub fn into_campaign(self) -> Campaign
pub fn into_campaign(self) -> Campaign
Creates a new Campaign
If CampaignId
was not provided with the request it will be generated using CampaignId::new()
sourcepub fn from_campaign_erased(campaign: Campaign, id: Option<CampaignId>) -> Self
pub fn from_campaign_erased(campaign: Campaign, id: Option<CampaignId>) -> Self
Creates a CreateCampaign
without using the [Campaign.id
].
You can either pass None
to randomly generate a new CampaignId
.
Or you can pass a CampaignId
to be used for the CreateCampaign
.
sourcepub fn from_campaign(campaign: Campaign) -> Self
pub fn from_campaign(campaign: Campaign) -> Self
This function will retains the original [Campaign.id
] (CampaignId
).
Trait Implementations
sourceimpl Clone for CreateCampaign
impl Clone for CreateCampaign
sourcefn clone(&self) -> CreateCampaign
fn clone(&self) -> CreateCampaign
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more