openrtb2/geo.rs
1/// 3.2.19 Object: Geo
2///
3/// This object encapsulates various methods for specifying a geographic location. When subordinate
4/// to a Device object, it indicates the location of the device which can also be interpreted as the
5/// user’s current location. When subordinate to a User object, it indicates the location of the
6/// user’s home base (i.e., not necessarily their current location).
7///
8/// The lat/lon attributes should only be passed if they conform to the accuracy depicted in the
9/// type attribute. For example, the centroid of a geographic region such as postal code should not
10/// be passed.
11#[derive(serde::Serialize, serde::Deserialize, Default, Debug, PartialEq, Clone)]
12pub struct Geo {
13 /// float
14 /// Latitude from -90.0 to +90.0, where negative is south.
15 #[serde(default, skip_serializing_if = "Option::is_none")]
16 pub lat: Option<f32>,
17
18 /// float
19 /// Longitude from -180.0 to +180.0, where negative is west.
20 #[serde(default, skip_serializing_if = "Option::is_none")]
21 pub lon: Option<f32>,
22
23 /// integer
24 /// Source of location data; recommended when passing lat/lon. Refer to List 5.20.
25 #[serde(default, skip_serializing_if = "Option::is_none")]
26 pub r#type: Option<crate::LocationType>,
27
28 /// integer
29 /// Estimated location accuracy in meters; recommended when lat/lon are specified and derived
30 /// from a device’s location services (i.e., type = 1). Note that this is the accuracy as
31 /// reported from the device. Consult OS specific documentation (e.g., Android, iOS) for exact
32 /// interpretation.
33 #[serde(default, skip_serializing_if = "Option::is_none")]
34 pub accuracy: Option<i32>,
35
36 /// integer
37 /// Number of seconds since this geolocation fix was established. Note that devices may cache
38 /// location data across multiple fetches. Ideally, this value should be from the time the
39 /// actual fix was taken.
40 #[serde(default, skip_serializing_if = "Option::is_none")]
41 pub lastfix: Option<i32>,
42
43 /// integer
44 /// Service or provider used to determine geolocation from IP address if applicable (i.e., type
45 /// = 2). Refer to List 5.23.
46 #[serde(default, skip_serializing_if = "Option::is_none")]
47 pub ipservice: Option<crate::IpLocationService>,
48
49 /// string
50 /// Country code using ISO-3166-1-alpha-3.
51 // TODO: ISO-3166-1-alpha-3.
52 #[serde(default, skip_serializing_if = "Option::is_none")]
53 pub country: Option<String>,
54
55 /// string
56 /// Region code using ISO-3166-2; 2-letter state code if USA.
57 // TODO: ISO-3166-2
58 #[serde(default, skip_serializing_if = "Option::is_none")]
59 pub region: Option<String>,
60
61 /// string
62 /// Region of a country using FIPS 10-4 notation. While OpenRTB supports this attribute, it has
63 /// been withdrawn by NIST in 2008.
64 // TODO: FIPS 10-4 notation
65 #[serde(default, skip_serializing_if = "Option::is_none")]
66 pub regionfips104: Option<String>,
67
68 /// string
69 /// Google metro code; similar to but not exactly Nielsen DMAs. See Appendix A for a link to
70 /// the codes.
71 // TODO: Google metro code http://code.google.com/apis/adwords/docs/appendix/metrocodes.html
72 #[serde(default, skip_serializing_if = "Option::is_none")]
73 pub metro: Option<String>,
74
75 /// string
76 /// City using United Nations Code for Trade & Transport Locations. See Appendix A for a link
77 /// to the codes.
78 // TODO: U.N. Code for Trade and Transport Locations
79 #[serde(default, skip_serializing_if = "Option::is_none")]
80 pub city: Option<String>,
81
82 /// string
83 /// Zip or postal code.
84 #[serde(default, skip_serializing_if = "Option::is_none")]
85 pub zip: Option<String>,
86
87 /// integer
88 /// Local time as the number +/- of minutes from UTC.
89 #[serde(default, skip_serializing_if = "Option::is_none")]
90 pub utcoffset: Option<i32>,
91
92 /// object
93 /// Placeholder for exchange-specific extensions to OpenRTB.
94 #[serde(default, skip_serializing_if = "Option::is_none")]
95 pub ext: Option<serde_json::Map<String, serde_json::Value>>,
96}
97
98#[cfg(test)]
99mod test {
100 use super::*;
101
102 #[test]
103 fn json() -> serde_json::Result<()> {
104 let json = "{}";
105 let o1 = Geo::default();
106 assert_eq!(serde_json::to_string(&o1)?, json);
107 assert_eq!(o1, serde_json::from_str::<Geo>(json)?);
108
109 Ok(())
110 }
111}