diff --git a/src/native/v1_2/request/asset.rs b/src/native/v1_2/request/asset.rs index 06580c7..26c959f 100644 --- a/src/native/v1_2/request/asset.rs +++ b/src/native/v1_2/request/asset.rs @@ -32,3 +32,29 @@ pub struct Asset { #[serde(skip_serializing_if = "Option::is_none")] pub ext: Option, } + +impl Asset { + pub fn new(id: u32, required: bool) -> Self { + Asset { + id, + required, + title: None, + image: None, + video: None, + data: None, + ext: None, + } + } + + pub fn new_title(id: u32, required: bool, title: Title) -> Self { + let mut asset = Asset::new(id, required); + asset.title = Some(title); + asset + } + + pub fn new_image(id: u32, required: bool, image: Image) -> Self { + let mut asset = Asset::new(id, required); + asset.image = Some(image); + asset + } +} diff --git a/src/native/v1_2/request/image.rs b/src/native/v1_2/request/image.rs index 1a458ec..8106ec8 100644 --- a/src/native/v1_2/request/image.rs +++ b/src/native/v1_2/request/image.rs @@ -2,7 +2,7 @@ use serde_utils; use super::image_type::ImageTypeID; -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)] pub struct Image { #[serde(rename = "type", skip_serializing_if = "Option::is_none")] pub type_id: Option, @@ -25,3 +25,9 @@ pub struct Image { #[serde(skip_serializing_if = "Option::is_none")] pub ext: Option, } + +impl Image { + pub fn new() -> Self { + Default::default() + } +} diff --git a/src/native/v1_2/request/request.rs b/src/native/v1_2/request/request.rs index ff0bb4b..a80ccbf 100644 --- a/src/native/v1_2/request/request.rs +++ b/src/native/v1_2/request/request.rs @@ -7,7 +7,7 @@ use super::context_type::ContextTypeID; use super::context_sub_type::ContextSubTypeID; use super::asset::Asset; -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)] pub struct Request { #[serde(rename = "ver", skip_serializing_if = "Option::is_none")] pub version: Option, @@ -39,3 +39,9 @@ pub struct Request { #[serde(skip_serializing_if = "Option::is_none")] pub ext: Option, } + +impl Request { + pub fn new() -> Self { + Default::default() + } +} diff --git a/src/native/v1_2/request/title.rs b/src/native/v1_2/request/title.rs index 3192a28..5e39257 100644 --- a/src/native/v1_2/request/title.rs +++ b/src/native/v1_2/request/title.rs @@ -8,3 +8,12 @@ pub struct Title { #[serde(skip_serializing_if = "Option::is_none")] pub ext: Option, } + +impl Title { + pub fn new(length: u32) -> Self { + Title { + length, + ext: None, + } + } +} diff --git a/src/v2_5/imp.rs b/src/v2_5/imp.rs index 2035ff4..00f291e 100644 --- a/src/v2_5/imp.rs +++ b/src/v2_5/imp.rs @@ -86,6 +86,28 @@ pub struct Imp { pub ext: Option, } +impl Imp { + pub fn new(id: String) -> Self { + Imp { + id, + metric: vec![], + banner: None, + video: None, + audio: None, + native: None, + pmp: None, + display_manager: None, + display_manager_ver: None, + interstitial: None, + tag_id: None, + bid_floor: None, + bid_floor_cur: None, + secure: None, + ext: None, + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/v2_5/native.rs b/src/v2_5/native.rs index 619b101..6563bd4 100644 --- a/src/v2_5/native.rs +++ b/src/v2_5/native.rs @@ -27,3 +27,15 @@ pub struct Native { #[serde(skip_serializing_if = "Option::is_none")] pub ext: Option, } + +impl Native { + pub fn new(request: String) -> Self { + Native { + request, + version: None, + api: vec![], + blocked_attrs: vec![], + ext: None, + } + } +}