vizio_openrtb/v2_5/
supply_chain.rs

1// Copyright (c) 2018 The openrtb-rust authors
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9use serde_utils;
10
11// This object represents both the links in the supply chain as well
12// as an indicator whether or not the supply chain is complete.
13#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
14pub struct SupplyChain {
15    // Flag indicating whether the chain contains all nodes
16    // involved in the transaction leading back to the owner
17    // of the site, app or other medium of the inventory,
18    // where 0 = no, 1 = yes.
19    #[serde(
20        default = "serde_utils::default_false",
21        skip_serializing_if = "serde_utils::is_false",
22        serialize_with = "serde_utils::bool_to_u8",
23        deserialize_with = "serde_utils::u8_to_bool"
24    )]
25    pub complete: bool,
26
27    // Array of SupplyChainNode objects in the order of the chain.
28    // In a complete supply chain, the first node represents
29    // the initial advertising system and seller ID involved
30    // in the transaction, i.e. the owner of the site, app,
31    // or other medium. In an incomplete supply chain, it represents
32    //  the first known node. The last node represents the entity
33    // sending this bid request.
34    pub nodes: Vec<SupplyChainNode>,
35
36    // Version of the supply chain specification in use, in the format
37    // of “major.minor”. For example, for version 1.0 of the spec,
38    // use the string “1.0”.
39    pub ver: String,
40
41    // Placeholder for advertising-system specific extensions to this object.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub ext: Option<serde_utils::Ext>,
44}
45
46// This object is associated with a SupplyChain object as an array of nodes.
47// These nodes define the identity of an entity participating in the supply
48// chain of a bid request.
49#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
50pub struct SupplyChainNode {
51    // The canonical domain name of the SSP, Exchange, Header Wrapper,
52    // etc system that bidders connect to. This may be the operational
53    // domain of the system, if that is different than the parent corporate
54    // domain, to facilitate WHOIS and reverse IP lookups to establish clear
55    // ownership of the delegate system. This should be the same value as used
56    // to identify sellers in an ads.txt file if one exists.
57    pub asi: String,
58
59    // The identifier associated with the seller or reseller account
60    // within the advertising system. This must contain the same value
61    // used in transactions (i.e. OpenRTB bid requests) in the field
62    // specified by the SSP/exchange. Typically, in OpenRTB,
63    // this is publisher.id. For OpenDirect it is typically the publisher’s
64    // organization ID.Should be limited to 64 characters in length.
65    pub sid: String,
66
67    // The OpenRTB RequestId of the request as issued by this seller.
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub rid: Option<String>,
70
71    // The name of the company (the legal entity) that is paid for
72    // inventory transacted under the given seller_id. This value
73    // is optional and should NOT be included if it exists in the
74    // advertising system’s sellers.json file.
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub name: Option<String>,
77
78    // The business domain name of the entity represented by this node.
79    // This value is optional and should NOT be included if it exists
80    // in the advertising system’s sellers.json file.
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub domain: Option<String>,
83
84    // Indicates whether this node will be involved in the flow of payment
85    // for the inventory. When set to 1, the advertising system in the asi
86    // field pays the seller in the sid field, who is responsible for paying
87    // the previous node in the chain. When set to 0, this node is not
88    // involved in the flow of payment for the inventory. For version 1.0
89    // of SupplyChain, this property should always be 1. It is explicitly
90    // required to be included as it is expected that future versions of
91    // the specification will introduce non-payment handling nodes.
92    // Implementers should ensure that they support this field and propagate
93    // it onwards when constructing SupplyChain objects in bid requests
94    // sent to a downstream advertising system.
95    #[serde(
96        default = "serde_utils::default_false",
97        skip_serializing_if = "serde_utils::is_false",
98        serialize_with = "serde_utils::bool_to_u8",
99        deserialize_with = "serde_utils::u8_to_bool"
100    )]
101    pub hp: bool,
102
103    // Placeholder for advertising-system specific extensions to this object.
104    #[serde(skip_serializing_if = "Option::is_none")]
105    pub ext: Option<serde_utils::Ext>,
106}
107
108#[test]
109fn serialization_skip_fields() {
110    let s = SupplyChain {
111        complete: true,
112        nodes: vec![SupplyChainNode {
113            asi: "directseller.com".to_string(),
114            sid: "00001".to_string(),
115            domain: None,
116            name: None,
117            rid: Some("BidRequest1".to_string()),
118            hp: true,
119            ext: None,
120        }],
121        ver: "1.0".to_string(),
122        ext: None,
123    };
124    let expected = r#"{"complete":1,"nodes":[{"asi":"directseller.com","sid":"00001","rid":"BidRequest1","hp":1}],"ver":"1.0"}"#;
125    let serialized = serde_json::to_string(&s).unwrap();
126
127    assert_eq!(expected, serialized)
128}