autogen_squareup/apis/
snippets_api.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 DeleteSnippetError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum RetrieveSnippetError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum UpsertSnippetError {
36 UnknownValue(serde_json::Value),
37}
38
39
40pub async fn delete_snippet(configuration: &configuration::Configuration, site_id: &str) -> Result<models::DeleteSnippetResponse, Error<DeleteSnippetError>> {
42 let p_site_id = site_id;
44
45 let uri_str = format!("{}/v2/sites/{site_id}/snippet", configuration.base_path, site_id=crate::apis::urlencode(p_site_id));
46 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
47
48 if let Some(ref user_agent) = configuration.user_agent {
49 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
50 }
51 if let Some(ref token) = configuration.oauth_access_token {
52 req_builder = req_builder.bearer_auth(token.to_owned());
53 };
54
55 let req = req_builder.build()?;
56 let resp = configuration.client.execute(req).await?;
57
58 let status = resp.status();
59 let content_type = resp
60 .headers()
61 .get("content-type")
62 .and_then(|v| v.to_str().ok())
63 .unwrap_or("application/octet-stream");
64 let content_type = super::ContentType::from(content_type);
65
66 if !status.is_client_error() && !status.is_server_error() {
67 let content = resp.text().await?;
68 match content_type {
69 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
70 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteSnippetResponse`"))),
71 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::DeleteSnippetResponse`")))),
72 }
73 } else {
74 let content = resp.text().await?;
75 let entity: Option<DeleteSnippetError> = serde_json::from_str(&content).ok();
76 Err(Error::ResponseError(ResponseContent { status, content, entity }))
77 }
78}
79
80pub async fn retrieve_snippet(configuration: &configuration::Configuration, site_id: &str) -> Result<models::RetrieveSnippetResponse, Error<RetrieveSnippetError>> {
82 let p_site_id = site_id;
84
85 let uri_str = format!("{}/v2/sites/{site_id}/snippet", configuration.base_path, site_id=crate::apis::urlencode(p_site_id));
86 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
87
88 if let Some(ref user_agent) = configuration.user_agent {
89 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
90 }
91 if let Some(ref token) = configuration.oauth_access_token {
92 req_builder = req_builder.bearer_auth(token.to_owned());
93 };
94
95 let req = req_builder.build()?;
96 let resp = configuration.client.execute(req).await?;
97
98 let status = resp.status();
99 let content_type = resp
100 .headers()
101 .get("content-type")
102 .and_then(|v| v.to_str().ok())
103 .unwrap_or("application/octet-stream");
104 let content_type = super::ContentType::from(content_type);
105
106 if !status.is_client_error() && !status.is_server_error() {
107 let content = resp.text().await?;
108 match content_type {
109 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
110 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RetrieveSnippetResponse`"))),
111 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::RetrieveSnippetResponse`")))),
112 }
113 } else {
114 let content = resp.text().await?;
115 let entity: Option<RetrieveSnippetError> = serde_json::from_str(&content).ok();
116 Err(Error::ResponseError(ResponseContent { status, content, entity }))
117 }
118}
119
120pub async fn upsert_snippet(configuration: &configuration::Configuration, site_id: &str, upsert_snippet_request: models::UpsertSnippetRequest) -> Result<models::UpsertSnippetResponse, Error<UpsertSnippetError>> {
122 let p_site_id = site_id;
124 let p_upsert_snippet_request = upsert_snippet_request;
125
126 let uri_str = format!("{}/v2/sites/{site_id}/snippet", configuration.base_path, site_id=crate::apis::urlencode(p_site_id));
127 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
128
129 if let Some(ref user_agent) = configuration.user_agent {
130 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
131 }
132 if let Some(ref token) = configuration.oauth_access_token {
133 req_builder = req_builder.bearer_auth(token.to_owned());
134 };
135 req_builder = req_builder.json(&p_upsert_snippet_request);
136
137 let req = req_builder.build()?;
138 let resp = configuration.client.execute(req).await?;
139
140 let status = resp.status();
141 let content_type = resp
142 .headers()
143 .get("content-type")
144 .and_then(|v| v.to_str().ok())
145 .unwrap_or("application/octet-stream");
146 let content_type = super::ContentType::from(content_type);
147
148 if !status.is_client_error() && !status.is_server_error() {
149 let content = resp.text().await?;
150 match content_type {
151 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
152 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpsertSnippetResponse`"))),
153 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::UpsertSnippetResponse`")))),
154 }
155 } else {
156 let content = resp.text().await?;
157 let entity: Option<UpsertSnippetError> = serde_json::from_str(&content).ok();
158 Err(Error::ResponseError(ResponseContent { status, content, entity }))
159 }
160}
161