Skip to main content

hermes_ebay_sell_account/apis/
program_api.rs

1/*
2 * Account v1 API
3 *
4 * The <b>Account API</b> gives sellers the ability to configure their eBay seller accounts, including the seller's policies (eBay business policies and seller-defined custom policies), opt in and out of eBay seller programs, configure sales tax tables, and get account information.  <br><br>For details on the availability of the methods in this API, see <a href=\"/api-docs/sell/account/overview.html#requirements\">Account API requirements and restrictions</a>.
5 *
6 * The version of the OpenAPI document: v1.9.2
7 * Contact: your-email@example.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_opted_in_programs`]
19#[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/// struct for typed errors of method [`opt_in_to_program`]
29#[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/// struct for typed errors of method [`opt_out_of_program`]
40#[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
51/// This method gets a list of the seller programs that the seller has opted-in to.
52pub 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
89/// This method opts the seller in to an eBay seller program. Refer to the <a href=\"/api-docs/sell/account/overview.html#opt-in\" target=\"_blank\">Account API overview</a> for information about available eBay seller programs.<br><br><span class=\"tablenote\"><b>Note:</b> It can take up to 24-hours for eBay to process your request to opt-in to a Seller Program. Use the <a href=\"/api-docs/sell/account/resources/program/methods/getOptedInPrograms\" target=\"_blank\">getOptedInPrograms</a> call to check the status of your request after the processing period has passed.</span>
90pub async fn opt_in_to_program(configuration: &configuration::Configuration, content_type: &str, program: models::Program) -> Result<serde_json::Value, Error<OptInToProgramError>> {
91    // add a prefix to parameters to efficiently prevent name collisions
92    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
132/// This method opts the seller out of a seller program in which they are currently opted in to. A seller can retrieve a list of the seller programs they are opted-in to using the <b>getOptedInPrograms</b> method.
133pub async fn opt_out_of_program(configuration: &configuration::Configuration, content_type: &str, program: models::Program) -> Result<serde_json::Value, Error<OptOutOfProgramError>> {
134    // add a prefix to parameters to efficiently prevent name collisions
135    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