amazon_spapi/apis/
app_integrations_2024_04_01.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateNotificationError {
22 Status400(models::app_integrations_2024_04_01::ErrorList),
23 Status401(models::app_integrations_2024_04_01::ErrorList),
24 Status403(models::app_integrations_2024_04_01::ErrorList),
25 Status404(models::app_integrations_2024_04_01::ErrorList),
26 Status413(models::app_integrations_2024_04_01::ErrorList),
27 Status415(models::app_integrations_2024_04_01::ErrorList),
28 Status429(models::app_integrations_2024_04_01::ErrorList),
29 Status500(models::app_integrations_2024_04_01::ErrorList),
30 Status503(models::app_integrations_2024_04_01::ErrorList),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum DeleteNotificationsError {
38 Status400(models::app_integrations_2024_04_01::ErrorList),
39 Status413(models::app_integrations_2024_04_01::ErrorList),
40 Status403(models::app_integrations_2024_04_01::ErrorList),
41 Status404(models::app_integrations_2024_04_01::ErrorList),
42 Status415(models::app_integrations_2024_04_01::ErrorList),
43 Status429(models::app_integrations_2024_04_01::ErrorList),
44 Status500(models::app_integrations_2024_04_01::ErrorList),
45 Status503(models::app_integrations_2024_04_01::ErrorList),
46 UnknownValue(serde_json::Value),
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum RecordActionFeedbackError {
53 Status400(models::app_integrations_2024_04_01::ErrorList),
54 Status413(models::app_integrations_2024_04_01::ErrorList),
55 Status401(models::app_integrations_2024_04_01::ErrorList),
56 Status403(models::app_integrations_2024_04_01::ErrorList),
57 Status404(models::app_integrations_2024_04_01::ErrorList),
58 Status415(models::app_integrations_2024_04_01::ErrorList),
59 Status429(models::app_integrations_2024_04_01::ErrorList),
60 Status500(models::app_integrations_2024_04_01::ErrorList),
61 Status503(models::app_integrations_2024_04_01::ErrorList),
62 UnknownValue(serde_json::Value),
63}
64
65
66pub async fn create_notification(configuration: &configuration::Configuration, body: models::app_integrations_2024_04_01::CreateNotificationRequest) -> Result<models::app_integrations_2024_04_01::CreateNotificationResponse, Error<CreateNotificationError>> {
68 let p_body = body;
70
71 let uri_str = format!("{}/appIntegrations/2024-04-01/notifications", configuration.base_path);
72 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
73
74 if let Some(ref user_agent) = configuration.user_agent {
75 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
76 }
77 req_builder = req_builder.json(&p_body);
78
79 let req = req_builder.build()?;
80 let resp = configuration.client.execute(req).await?;
81
82 let status = resp.status();
83 let content_type = resp
84 .headers()
85 .get("content-type")
86 .and_then(|v| v.to_str().ok())
87 .unwrap_or("application/octet-stream");
88 let content_type = super::ContentType::from(content_type);
89
90 if !status.is_client_error() && !status.is_server_error() {
91 let content = resp.text().await?;
92 match content_type {
93 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
94 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::app_integrations_2024_04_01::CreateNotificationResponse`"))),
95 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::app_integrations_2024_04_01::CreateNotificationResponse`")))),
96 }
97 } else {
98 let content = resp.text().await?;
99 let entity: Option<CreateNotificationError> = serde_json::from_str(&content).ok();
100 Err(Error::ResponseError(ResponseContent { status, content, entity }))
101 }
102}
103
104pub async fn delete_notifications(configuration: &configuration::Configuration, body: models::app_integrations_2024_04_01::DeleteNotificationsRequest) -> Result<(), Error<DeleteNotificationsError>> {
106 let p_body = body;
108
109 let uri_str = format!("{}/appIntegrations/2024-04-01/notifications/deletion", configuration.base_path);
110 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
111
112 if let Some(ref user_agent) = configuration.user_agent {
113 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
114 }
115 req_builder = req_builder.json(&p_body);
116
117 let req = req_builder.build()?;
118 let resp = configuration.client.execute(req).await?;
119
120 let status = resp.status();
121
122 if !status.is_client_error() && !status.is_server_error() {
123 Ok(())
124 } else {
125 let content = resp.text().await?;
126 let entity: Option<DeleteNotificationsError> = serde_json::from_str(&content).ok();
127 Err(Error::ResponseError(ResponseContent { status, content, entity }))
128 }
129}
130
131pub async fn record_action_feedback(configuration: &configuration::Configuration, notification_id: &str, body: models::app_integrations_2024_04_01::RecordActionFeedbackRequest) -> Result<(), Error<RecordActionFeedbackError>> {
133 let p_notification_id = notification_id;
135 let p_body = body;
136
137 let uri_str = format!("{}/appIntegrations/2024-04-01/notifications/{notificationId}/feedback", configuration.base_path, notificationId=crate::apis::urlencode(p_notification_id));
138 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
139
140 if let Some(ref user_agent) = configuration.user_agent {
141 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
142 }
143 req_builder = req_builder.json(&p_body);
144
145 let req = req_builder.build()?;
146 let resp = configuration.client.execute(req).await?;
147
148 let status = resp.status();
149
150 if !status.is_client_error() && !status.is_server_error() {
151 Ok(())
152 } else {
153 let content = resp.text().await?;
154 let entity: Option<RecordActionFeedbackError> = serde_json::from_str(&content).ok();
155 Err(Error::ResponseError(ResponseContent { status, content, entity }))
156 }
157}
158