1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateSplitTestError {
22 DefaultResponse(crate::models::Error),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DisableSplitTestError {
30 DefaultResponse(crate::models::Error),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum EnableSplitTestError {
38 DefaultResponse(crate::models::Error),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetSplitTestError {
46 DefaultResponse(crate::models::Error),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetSplitTestsError {
54 DefaultResponse(crate::models::Error),
55 UnknownValue(serde_json::Value),
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum UpdateSplitTestError {
62 DefaultResponse(crate::models::Error),
63 UnknownValue(serde_json::Value),
64}
65
66
67pub async fn create_split_test(configuration: &configuration::Configuration, site_id: &str, branch_tests: crate::models::SplitTestSetup) -> Result<crate::models::SplitTest, Error<CreateSplitTestError>> {
68
69 let local_var_client = &configuration.client;
70
71 let local_var_uri_str = format!("{}/sites/{site_id}/traffic_splits", configuration.base_path, site_id=crate::apis::urlencode(site_id));
72 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
73
74 if let Some(ref local_var_user_agent) = configuration.user_agent {
75 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
76 }
77 if let Some(ref local_var_token) = configuration.oauth_access_token {
78 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
79 };
80 local_var_req_builder = local_var_req_builder.json(&branch_tests);
81
82 let local_var_req = local_var_req_builder.build()?;
83 let local_var_resp = local_var_client.execute(local_var_req).await?;
84
85 let local_var_status = local_var_resp.status();
86 let local_var_content = local_var_resp.text().await?;
87
88 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
89 serde_json::from_str(&local_var_content).map_err(Error::from)
90 } else {
91 let local_var_entity: Option<CreateSplitTestError> = serde_json::from_str(&local_var_content).ok();
92 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
93 Err(Error::ResponseError(local_var_error))
94 }
95}
96
97pub async fn disable_split_test(configuration: &configuration::Configuration, site_id: &str, split_test_id: &str) -> Result<(), Error<DisableSplitTestError>> {
98
99 let local_var_client = &configuration.client;
100
101 let local_var_uri_str = format!("{}/sites/{site_id}/traffic_splits/{split_test_id}/unpublish", configuration.base_path, site_id=crate::apis::urlencode(site_id), split_test_id=crate::apis::urlencode(split_test_id));
102 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
103
104 if let Some(ref local_var_user_agent) = configuration.user_agent {
105 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
106 }
107 if let Some(ref local_var_token) = configuration.oauth_access_token {
108 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
109 };
110
111 let local_var_req = local_var_req_builder.build()?;
112 let local_var_resp = local_var_client.execute(local_var_req).await?;
113
114 let local_var_status = local_var_resp.status();
115 let local_var_content = local_var_resp.text().await?;
116
117 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
118 Ok(())
119 } else {
120 let local_var_entity: Option<DisableSplitTestError> = serde_json::from_str(&local_var_content).ok();
121 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
122 Err(Error::ResponseError(local_var_error))
123 }
124}
125
126pub async fn enable_split_test(configuration: &configuration::Configuration, site_id: &str, split_test_id: &str) -> Result<(), Error<EnableSplitTestError>> {
127
128 let local_var_client = &configuration.client;
129
130 let local_var_uri_str = format!("{}/sites/{site_id}/traffic_splits/{split_test_id}/publish", configuration.base_path, site_id=crate::apis::urlencode(site_id), split_test_id=crate::apis::urlencode(split_test_id));
131 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
132
133 if let Some(ref local_var_user_agent) = configuration.user_agent {
134 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
135 }
136 if let Some(ref local_var_token) = configuration.oauth_access_token {
137 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
138 };
139
140 let local_var_req = local_var_req_builder.build()?;
141 let local_var_resp = local_var_client.execute(local_var_req).await?;
142
143 let local_var_status = local_var_resp.status();
144 let local_var_content = local_var_resp.text().await?;
145
146 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
147 Ok(())
148 } else {
149 let local_var_entity: Option<EnableSplitTestError> = serde_json::from_str(&local_var_content).ok();
150 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
151 Err(Error::ResponseError(local_var_error))
152 }
153}
154
155pub async fn get_split_test(configuration: &configuration::Configuration, site_id: &str, split_test_id: &str) -> Result<crate::models::SplitTest, Error<GetSplitTestError>> {
156
157 let local_var_client = &configuration.client;
158
159 let local_var_uri_str = format!("{}/sites/{site_id}/traffic_splits/{split_test_id}", configuration.base_path, site_id=crate::apis::urlencode(site_id), split_test_id=crate::apis::urlencode(split_test_id));
160 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
161
162 if let Some(ref local_var_user_agent) = configuration.user_agent {
163 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
164 }
165 if let Some(ref local_var_token) = configuration.oauth_access_token {
166 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
167 };
168
169 let local_var_req = local_var_req_builder.build()?;
170 let local_var_resp = local_var_client.execute(local_var_req).await?;
171
172 let local_var_status = local_var_resp.status();
173 let local_var_content = local_var_resp.text().await?;
174
175 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
176 serde_json::from_str(&local_var_content).map_err(Error::from)
177 } else {
178 let local_var_entity: Option<GetSplitTestError> = serde_json::from_str(&local_var_content).ok();
179 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
180 Err(Error::ResponseError(local_var_error))
181 }
182}
183
184pub async fn get_split_tests(configuration: &configuration::Configuration, site_id: &str) -> Result<Vec<crate::models::SplitTest>, Error<GetSplitTestsError>> {
185
186 let local_var_client = &configuration.client;
187
188 let local_var_uri_str = format!("{}/sites/{site_id}/traffic_splits", configuration.base_path, site_id=crate::apis::urlencode(site_id));
189 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
190
191 if let Some(ref local_var_user_agent) = configuration.user_agent {
192 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
193 }
194 if let Some(ref local_var_token) = configuration.oauth_access_token {
195 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
196 };
197
198 let local_var_req = local_var_req_builder.build()?;
199 let local_var_resp = local_var_client.execute(local_var_req).await?;
200
201 let local_var_status = local_var_resp.status();
202 let local_var_content = local_var_resp.text().await?;
203
204 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
205 serde_json::from_str(&local_var_content).map_err(Error::from)
206 } else {
207 let local_var_entity: Option<GetSplitTestsError> = serde_json::from_str(&local_var_content).ok();
208 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
209 Err(Error::ResponseError(local_var_error))
210 }
211}
212
213pub async fn update_split_test(configuration: &configuration::Configuration, site_id: &str, split_test_id: &str, branch_tests: crate::models::SplitTestSetup) -> Result<crate::models::SplitTest, Error<UpdateSplitTestError>> {
214
215 let local_var_client = &configuration.client;
216
217 let local_var_uri_str = format!("{}/sites/{site_id}/traffic_splits/{split_test_id}", configuration.base_path, site_id=crate::apis::urlencode(site_id), split_test_id=crate::apis::urlencode(split_test_id));
218 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
219
220 if let Some(ref local_var_user_agent) = configuration.user_agent {
221 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
222 }
223 if let Some(ref local_var_token) = configuration.oauth_access_token {
224 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
225 };
226 local_var_req_builder = local_var_req_builder.json(&branch_tests);
227
228 let local_var_req = local_var_req_builder.build()?;
229 let local_var_resp = local_var_client.execute(local_var_req).await?;
230
231 let local_var_status = local_var_resp.status();
232 let local_var_content = local_var_resp.text().await?;
233
234 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
235 serde_json::from_str(&local_var_content).map_err(Error::from)
236 } else {
237 let local_var_entity: Option<UpdateSplitTestError> = serde_json::from_str(&local_var_content).ok();
238 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
239 Err(Error::ResponseError(local_var_error))
240 }
241}
242