aws_lambda_events/event/iot_1_click/
mod.rs

1use serde::{Deserialize, Serialize};
2#[cfg(feature = "catch-all-fields")]
3use serde_json::Value;
4use std::collections::HashMap;
5
6use crate::custom_serde::deserialize_lambda_map;
7
8/// `IoTOneClickEvent` represents a click event published by clicking button type
9/// device.
10#[non_exhaustive]
11#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
12#[serde(rename_all = "camelCase")]
13pub struct IoTOneClickEvent {
14    pub device_event: IoTOneClickDeviceEvent,
15    pub device_info: IoTOneClickDeviceInfo,
16    pub placement_info: IoTOneClickPlacementInfo,
17    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
18    /// Enabled with Cargo feature `catch-all-fields`.
19    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
20    #[cfg(feature = "catch-all-fields")]
21    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
22    #[serde(flatten)]
23    pub other: serde_json::Map<String, Value>,
24}
25
26#[non_exhaustive]
27#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
28#[serde(rename_all = "camelCase")]
29pub struct IoTOneClickDeviceEvent {
30    pub button_clicked: IoTOneClickButtonClicked,
31    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
32    /// Enabled with Cargo feature `catch-all-fields`.
33    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
34    #[cfg(feature = "catch-all-fields")]
35    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
36    #[serde(flatten)]
37    pub other: serde_json::Map<String, Value>,
38}
39
40#[non_exhaustive]
41#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
42#[serde(rename_all = "camelCase")]
43pub struct IoTOneClickButtonClicked {
44    #[serde(default)]
45    pub click_type: Option<String>,
46    #[serde(default)]
47    pub reported_time: Option<String>,
48    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
49    /// Enabled with Cargo feature `catch-all-fields`.
50    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
51    #[cfg(feature = "catch-all-fields")]
52    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
53    #[serde(flatten)]
54    pub other: serde_json::Map<String, Value>,
55}
56
57#[non_exhaustive]
58#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
59#[serde(rename_all = "camelCase")]
60pub struct IoTOneClickDeviceInfo {
61    #[serde(deserialize_with = "deserialize_lambda_map")]
62    #[serde(default)]
63    pub attributes: HashMap<String, String>,
64    #[serde(default)]
65    pub type_: Option<String>,
66    #[serde(default)]
67    pub device_id: Option<String>,
68    pub remaining_life: f64,
69    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
70    /// Enabled with Cargo feature `catch-all-fields`.
71    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
72    #[cfg(feature = "catch-all-fields")]
73    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
74    #[serde(flatten)]
75    pub other: serde_json::Map<String, Value>,
76}
77
78#[non_exhaustive]
79#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
80#[serde(rename_all = "camelCase")]
81pub struct IoTOneClickPlacementInfo {
82    #[serde(default)]
83    pub project_name: Option<String>,
84    #[serde(default)]
85    pub placement_name: Option<String>,
86    #[serde(deserialize_with = "deserialize_lambda_map")]
87    #[serde(default)]
88    pub attributes: HashMap<String, String>,
89    #[serde(deserialize_with = "deserialize_lambda_map")]
90    #[serde(default)]
91    pub devices: HashMap<String, String>,
92    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
93    /// Enabled with Cargo feature `catch-all-fields`.
94    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
95    #[cfg(feature = "catch-all-fields")]
96    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
97    #[serde(flatten)]
98    pub other: serde_json::Map<String, Value>,
99}
100
101#[cfg(test)]
102mod test {
103    use super::*;
104
105    #[test]
106    #[cfg(feature = "iot_1_click")]
107    fn example_iot_1_click_event() {
108        let data = include_bytes!("../../fixtures/example-iot_1_click-event.json");
109        let parsed: IoTOneClickEvent = serde_json::from_slice(data).unwrap();
110        let output: String = serde_json::to_string(&parsed).unwrap();
111        let reparsed: IoTOneClickEvent = serde_json::from_slice(output.as_bytes()).unwrap();
112        assert_eq!(parsed, reparsed);
113    }
114}