openrtb2/device.rs
1use serde::{Deserialize, Serialize};
2
3/// 3.2.18 Object: Device
4///
5/// This object provides information pertaining to the device through which the user is interacting.
6/// Device information includes its hardware, platform, location, and carrier data. The device can
7/// refer to a mobile handset, a desktop computer, set top box, or other digital device.
8#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Clone)]
9pub struct Device {
10 /// string; recommended
11 /// Browser user agent string.
12 #[serde(default, skip_serializing_if = "Option::is_none")]
13 pub ua: Option<String>,
14
15 /// object; recommended
16 /// Location of the device assumed to be the user’s current location defined by a Geo object
17 /// (Section 3.2.19).
18 #[serde(default, skip_serializing_if = "Option::is_none")]
19 pub geo: Option<crate::Geo>,
20
21 /// integer; recommended
22 /// Standard “Do Not Track” flag as set in the header by the browser, where 0 = tracking is
23 /// unrestricted, 1 = do not track.
24 #[serde(
25 default,
26 skip_serializing_if = "Option::is_none",
27 with = "crate::serde::i32_as_opt_bool"
28 )]
29 pub dnt: Option<bool>,
30
31 /// integer; recommended
32 /// “Limit Ad Tracking” signal commercially endorsed (e.g., iOS, Android), where 0 = tracking
33 /// is unrestricted, 1 = tracking must be limited per commercial guidelines.
34 #[serde(
35 default,
36 skip_serializing_if = "Option::is_none",
37 with = "crate::serde::i32_as_opt_bool"
38 )]
39 pub lmt: Option<bool>,
40
41 /// string; recommended
42 /// IPv4 address closest to device.
43 #[serde(default, skip_serializing_if = "Option::is_none")]
44 pub ip: Option<String>,
45
46 /// string
47 /// IP address closest to device as IPv6.
48 #[serde(default, skip_serializing_if = "Option::is_none")]
49 pub ipv6: Option<String>,
50
51 /// integer
52 /// The general type of device. Refer to List 5.21.
53 #[serde(default, skip_serializing_if = "Option::is_none")]
54 pub devicetype: Option<crate::DeviceType>,
55
56 /// string
57 /// Device make (e.g., “Apple”).
58 #[serde(default, skip_serializing_if = "Option::is_none")]
59 pub make: Option<String>,
60
61 /// string
62 /// Device model (e.g., “iPhone”).
63 #[serde(default, skip_serializing_if = "Option::is_none")]
64 pub model: Option<String>,
65
66 /// string
67 /// Device operating system (e.g., “iOS”).
68 #[serde(default, skip_serializing_if = "Option::is_none")]
69 pub os: Option<String>,
70
71 /// string
72 /// Device operating system version (e.g., “3.1.2”).
73 #[serde(default, skip_serializing_if = "Option::is_none")]
74 pub osv: Option<String>,
75
76 /// string
77 /// Hardware version of the device (e.g., “5S” for iPhone 5S).
78 #[serde(default, skip_serializing_if = "Option::is_none")]
79 pub hwv: Option<String>,
80
81 /// integer
82 /// Physical height of the screen in pixels.
83 #[serde(default, skip_serializing_if = "Option::is_none")]
84 pub h: Option<i32>,
85
86 /// integer
87 /// Physical width of the screen in pixels.
88 #[serde(default, skip_serializing_if = "Option::is_none")]
89 pub w: Option<i32>,
90
91 /// integer
92 /// Screen size as pixels per linear inch.
93 #[serde(default, skip_serializing_if = "Option::is_none")]
94 pub ppi: Option<i32>,
95
96 /// float
97 /// The ratio of physical pixels to device independent pixels.
98 #[serde(default, skip_serializing_if = "Option::is_none")]
99 pub pxratio: Option<i32>,
100
101 /// integer
102 /// Support for JavaScript, where 0 = no, 1 = yes.
103 #[serde(
104 default,
105 skip_serializing_if = "Option::is_none",
106 with = "crate::serde::i32_as_opt_bool"
107 )]
108 pub js: Option<bool>,
109
110 /// integer
111 /// Indicates if the geolocation API will be available to JavaScript code running in the
112 /// banner, where 0 = no, 1 = yes.
113 #[serde(
114 default,
115 skip_serializing_if = "Option::is_none",
116 with = "crate::serde::i32_as_opt_bool"
117 )]
118 pub geofetch: Option<bool>,
119
120 /// string
121 /// Version of Flash supported by the browser.
122 #[serde(default, skip_serializing_if = "Option::is_none")]
123 pub flashver: Option<String>,
124
125 /// string
126 /// Browser language using ISO-639-1-alpha-2.
127 // TODO: ISO-639-1-alpha-2
128 #[serde(default, skip_serializing_if = "Option::is_none")]
129 pub language: Option<String>,
130
131 /// string
132 /// Carrier or ISP (e.g., “VERIZON”) using exchange curated string names which should be
133 /// published to bidders a priori.
134 #[serde(default, skip_serializing_if = "Option::is_none")]
135 pub carrier: Option<String>,
136
137 /// string
138 /// Mobile carrier as the concatenated MCC-MNC code (e.g., “310-005” identifies Verizon
139 /// Wireless CDMA in the USA). Refer to https://en.wikipedia.org/wiki/Mobile_country_code for further
140 /// examples. Note that the dash between the MCC and MNC parts is required to remove parsing
141 /// ambiguity.
142 #[serde(default, skip_serializing_if = "Option::is_none")]
143 pub mccmnc: Option<String>,
144
145 /// integer
146 /// Network connection type. Refer to List 5.22.
147 #[serde(default, skip_serializing_if = "Option::is_none")]
148 pub connectiontype: Option<crate::ConnectionType>,
149
150 /// string
151 /// ID sanctioned for advertiser use in the clear (i.e., not hashed).
152 #[serde(default, skip_serializing_if = "Option::is_none")]
153 pub ifa: Option<String>,
154
155 /// string
156 /// Hardware device ID (e.g., IMEI); hashed via SHA1.
157 #[serde(default, skip_serializing_if = "Option::is_none")]
158 pub didsha1: Option<String>,
159
160 /// string
161 /// Hardware device ID (e.g., IMEI); hashed via MD5.
162 #[serde(default, skip_serializing_if = "Option::is_none")]
163 pub didmd5: Option<String>,
164
165 /// string
166 /// Platform device ID (e.g., Android ID); hashed via SHA1.
167 #[serde(default, skip_serializing_if = "Option::is_none")]
168 pub dpidsha1: Option<String>,
169
170 /// string
171 /// Platform device ID (e.g., Android ID); hashed via MD5.
172 #[serde(default, skip_serializing_if = "Option::is_none")]
173 pub dpidmd5: Option<String>,
174
175 /// string
176 /// MAC address of the device; hashed via SHA1.
177 #[serde(default, skip_serializing_if = "Option::is_none")]
178 pub macsha1: Option<String>,
179
180 /// string
181 /// MAC address of the device; hashed via MD5.
182 #[serde(default, skip_serializing_if = "Option::is_none")]
183 pub macmd5: Option<String>,
184
185 /// object
186 /// Placeholder for exchange-specific extensions to OpenRTB.
187 #[serde(default, skip_serializing_if = "Option::is_none")]
188 pub ext: Option<serde_json::Map<String, serde_json::Value>>,
189}
190
191#[cfg(test)]
192mod test {
193 use super::*;
194
195 #[test]
196 fn json() -> serde_json::Result<()> {
197 let json = "{}";
198 let o1 = Device::default();
199 assert_eq!(serde_json::to_string(&o1)?, json);
200 assert_eq!(o1, serde_json::from_str::<Device>(json)?);
201
202 Ok(())
203 }
204}