hermes_ebay_sell_account/apis/
program_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 GetOptedInProgramsError {
22 Status400(),
23 Status404(),
24 Status500(),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum OptInToProgramError {
32 Status400(),
33 Status404(),
34 Status409(),
35 Status500(),
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum OptOutOfProgramError {
43 Status400(),
44 Status404(),
45 Status409(),
46 Status500(),
47 UnknownValue(serde_json::Value),
48}
49
50
51pub async fn get_opted_in_programs(configuration: &configuration::Configuration, ) -> Result<models::Programs, Error<GetOptedInProgramsError>> {
53
54 let uri_str = format!("{}/program/get_opted_in_programs", configuration.base_path);
55 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
56
57 if let Some(ref user_agent) = configuration.user_agent {
58 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
59 }
60 if let Some(ref token) = configuration.oauth_access_token {
61 req_builder = req_builder.bearer_auth(token.to_owned());
62 };
63
64 let req = req_builder.build()?;
65 let resp = configuration.client.execute(req).await?;
66
67 let status = resp.status();
68 let content_type = resp
69 .headers()
70 .get("content-type")
71 .and_then(|v| v.to_str().ok())
72 .unwrap_or("application/octet-stream");
73 let content_type = super::ContentType::from(content_type);
74
75 if !status.is_client_error() && !status.is_server_error() {
76 let content = resp.text().await?;
77 match content_type {
78 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
79 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Programs`"))),
80 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::Programs`")))),
81 }
82 } else {
83 let content = resp.text().await?;
84 let entity: Option<GetOptedInProgramsError> = serde_json::from_str(&content).ok();
85 Err(Error::ResponseError(ResponseContent { status, content, entity }))
86 }
87}
88
89pub async fn opt_in_to_program(configuration: &configuration::Configuration, content_type: &str, program: models::Program) -> Result<serde_json::Value, Error<OptInToProgramError>> {
91 let p_content_type = content_type;
93 let p_program = program;
94
95 let uri_str = format!("{}/program/opt_in", configuration.base_path);
96 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
97
98 if let Some(ref user_agent) = configuration.user_agent {
99 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
100 }
101 req_builder = req_builder.header("Content-Type", p_content_type.to_string());
102 if let Some(ref token) = configuration.oauth_access_token {
103 req_builder = req_builder.bearer_auth(token.to_owned());
104 };
105 req_builder = req_builder.json(&p_program);
106
107 let req = req_builder.build()?;
108 let resp = configuration.client.execute(req).await?;
109
110 let status = resp.status();
111 let content_type = resp
112 .headers()
113 .get("content-type")
114 .and_then(|v| v.to_str().ok())
115 .unwrap_or("application/octet-stream");
116 let content_type = super::ContentType::from(content_type);
117
118 if !status.is_client_error() && !status.is_server_error() {
119 let content = resp.text().await?;
120 match content_type {
121 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
122 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
123 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
124 }
125 } else {
126 let content = resp.text().await?;
127 let entity: Option<OptInToProgramError> = serde_json::from_str(&content).ok();
128 Err(Error::ResponseError(ResponseContent { status, content, entity }))
129 }
130}
131
132pub async fn opt_out_of_program(configuration: &configuration::Configuration, content_type: &str, program: models::Program) -> Result<serde_json::Value, Error<OptOutOfProgramError>> {
134 let p_content_type = content_type;
136 let p_program = program;
137
138 let uri_str = format!("{}/program/opt_out", configuration.base_path);
139 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
140
141 if let Some(ref user_agent) = configuration.user_agent {
142 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
143 }
144 req_builder = req_builder.header("Content-Type", p_content_type.to_string());
145 if let Some(ref token) = configuration.oauth_access_token {
146 req_builder = req_builder.bearer_auth(token.to_owned());
147 };
148 req_builder = req_builder.json(&p_program);
149
150 let req = req_builder.build()?;
151 let resp = configuration.client.execute(req).await?;
152
153 let status = resp.status();
154 let content_type = resp
155 .headers()
156 .get("content-type")
157 .and_then(|v| v.to_str().ok())
158 .unwrap_or("application/octet-stream");
159 let content_type = super::ContentType::from(content_type);
160
161 if !status.is_client_error() && !status.is_server_error() {
162 let content = resp.text().await?;
163 match content_type {
164 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
165 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
166 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
167 }
168 } else {
169 let content = resp.text().await?;
170 let entity: Option<OptOutOfProgramError> = serde_json::from_str(&content).ok();
171 Err(Error::ResponseError(ResponseContent { status, content, entity }))
172 }
173}
174