qiniu_apis/storage/
modify_object_status.rs

1// THIS FILE IS GENERATED BY api-generator, DO NOT EDIT DIRECTLY!
2//
3#[derive(Debug, Clone, Default)]
4#[doc = "调用 API 所用的路径参数"]
5pub struct PathParams {
6    r#entry: Option<std::borrow::Cow<'static, str>>,
7    r#status: Option<std::borrow::Cow<'static, str>>,
8    extended_segments: Vec<std::borrow::Cow<'static, str>>,
9}
10impl PathParams {
11    #[inline]
12    #[must_use]
13    #[doc = "追加新的路径段"]
14    pub fn push_segment(mut self, segment: impl Into<std::borrow::Cow<'static, str>>) -> Self {
15        self.extended_segments.push(segment.into());
16        self
17    }
18    fn build(self) -> Vec<std::borrow::Cow<'static, str>> {
19        let mut all_segments: Vec<_> = Default::default();
20        if let Some(segment) = self.r#entry {
21            all_segments.push(segment);
22        }
23        if let Some(segment) = self.r#status {
24            all_segments.push(std::borrow::Cow::Borrowed("status"));
25            all_segments.push(segment);
26        }
27        all_segments.extend(self.extended_segments);
28        all_segments
29    }
30}
31impl PathParams {
32    #[inline]
33    #[must_use]
34    #[doc = "指定目标对象空间与目标对象名称"]
35    pub fn set_entry_as_str(mut self, value: impl Into<std::borrow::Cow<'static, str>>) -> Self {
36        self.r#entry = Some(qiniu_utils::base64::urlsafe(value.into().as_bytes()).into());
37        self
38    }
39    #[inline]
40    #[must_use]
41    #[doc = "`0` 表示启用;`1` 表示禁用"]
42    pub fn set_status_as_i8(mut self, value: i8) -> Self {
43        self.r#status = Some(value.to_string().into());
44        self
45    }
46    #[inline]
47    #[must_use]
48    #[doc = "`0` 表示启用;`1` 表示禁用"]
49    pub fn set_status_as_i16(mut self, value: i16) -> Self {
50        self.r#status = Some(value.to_string().into());
51        self
52    }
53    #[inline]
54    #[must_use]
55    #[doc = "`0` 表示启用;`1` 表示禁用"]
56    pub fn set_status_as_i32(mut self, value: i32) -> Self {
57        self.r#status = Some(value.to_string().into());
58        self
59    }
60    #[inline]
61    #[must_use]
62    #[doc = "`0` 表示启用;`1` 表示禁用"]
63    pub fn set_status_as_i64(mut self, value: i64) -> Self {
64        self.r#status = Some(value.to_string().into());
65        self
66    }
67    #[inline]
68    #[must_use]
69    #[doc = "`0` 表示启用;`1` 表示禁用"]
70    pub fn set_status_as_isize(mut self, value: isize) -> Self {
71        self.r#status = Some(value.to_string().into());
72        self
73    }
74    #[inline]
75    #[must_use]
76    #[doc = "`0` 表示启用;`1` 表示禁用"]
77    pub fn set_status_as_u8(mut self, value: u8) -> Self {
78        self.r#status = Some(value.to_string().into());
79        self
80    }
81    #[inline]
82    #[must_use]
83    #[doc = "`0` 表示启用;`1` 表示禁用"]
84    pub fn set_status_as_u16(mut self, value: u16) -> Self {
85        self.r#status = Some(value.to_string().into());
86        self
87    }
88    #[inline]
89    #[must_use]
90    #[doc = "`0` 表示启用;`1` 表示禁用"]
91    pub fn set_status_as_u32(mut self, value: u32) -> Self {
92        self.r#status = Some(value.to_string().into());
93        self
94    }
95    #[inline]
96    #[must_use]
97    #[doc = "`0` 表示启用;`1` 表示禁用"]
98    pub fn set_status_as_u64(mut self, value: u64) -> Self {
99        self.r#status = Some(value.to_string().into());
100        self
101    }
102    #[inline]
103    #[must_use]
104    #[doc = "`0` 表示启用;`1` 表示禁用"]
105    pub fn set_status_as_usize(mut self, value: usize) -> Self {
106        self.r#status = Some(value.to_string().into());
107        self
108    }
109}
110#[derive(Clone, Debug, serde :: Serialize, serde :: Deserialize)]
111#[serde(transparent)]
112#[doc = "获取 API 所用的响应体参数"]
113pub struct ResponseBody(serde_json::Value);
114impl ResponseBody {
115    #[allow(dead_code)]
116    pub(crate) fn new(value: serde_json::Value) -> Self {
117        Self(value)
118    }
119}
120impl Default for ResponseBody {
121    #[inline]
122    fn default() -> Self {
123        Self(serde_json::Value::Object(Default::default()))
124    }
125}
126impl From<ResponseBody> for serde_json::Value {
127    #[inline]
128    fn from(val: ResponseBody) -> Self {
129        val.0
130    }
131}
132impl AsRef<serde_json::Value> for ResponseBody {
133    #[inline]
134    fn as_ref(&self) -> &serde_json::Value {
135        &self.0
136    }
137}
138impl AsMut<serde_json::Value> for ResponseBody {
139    #[inline]
140    fn as_mut(&mut self) -> &mut serde_json::Value {
141        &mut self.0
142    }
143}
144#[doc = "API 调用客户端"]
145#[derive(Debug, Clone)]
146pub struct Client<'client>(&'client qiniu_http_client::HttpClient);
147impl<'client> Client<'client> {
148    pub(super) fn new(http_client: &'client qiniu_http_client::HttpClient) -> Self {
149        Self(http_client)
150    }
151}
152impl<'client> Client<'client> {
153    #[inline]
154    #[doc = "创建一个新的阻塞请求,该方法的异步版本为 [`Self::new_async_request`]"]
155    pub fn new_request<E: qiniu_http_client::EndpointsProvider + 'client>(
156        &self,
157        endpoints_provider: E,
158        path_params: PathParams,
159        credential: impl qiniu_http_client::credential::CredentialProvider + Clone + 'client,
160    ) -> SyncRequestBuilder<'client, E> {
161        RequestBuilder({
162            let mut builder = self.0.post(&[qiniu_http_client::ServiceName::Rs], endpoints_provider);
163            builder.authorization(qiniu_http_client::Authorization::v2(credential));
164            builder.idempotent(qiniu_http_client::Idempotent::Always);
165            builder.path(crate::base_utils::join_path("/chstatus", "", path_params.build()));
166            builder.accept_json();
167            builder
168        })
169    }
170    #[inline]
171    #[cfg(feature = "async")]
172    #[doc = "创建一个新的异步请求"]
173    pub fn new_async_request<E: qiniu_http_client::EndpointsProvider + 'client>(
174        &self,
175        endpoints_provider: E,
176        path_params: PathParams,
177        credential: impl qiniu_http_client::credential::CredentialProvider + Clone + 'client,
178    ) -> AsyncRequestBuilder<'client, E> {
179        RequestBuilder({
180            let mut builder = self
181                .0
182                .async_post(&[qiniu_http_client::ServiceName::Rs], endpoints_provider);
183            builder.authorization(qiniu_http_client::Authorization::v2(credential));
184            builder.idempotent(qiniu_http_client::Idempotent::Always);
185            builder.path(crate::base_utils::join_path("/chstatus", "", path_params.build()));
186            builder.accept_json();
187            builder
188        })
189    }
190}
191#[derive(Debug)]
192#[doc = "API 请求构造器"]
193pub struct RequestBuilder<'req, B, E>(qiniu_http_client::RequestBuilder<'req, B, E>);
194#[doc = "API 阻塞请求构造器"]
195pub type SyncRequestBuilder<'req, E> = RequestBuilder<'req, qiniu_http_client::SyncRequestBody<'req>, E>;
196#[cfg(feature = "async")]
197#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
198#[doc = "API 异步请求构造器"]
199pub type AsyncRequestBuilder<'req, E> = RequestBuilder<'req, qiniu_http_client::AsyncRequestBody<'req>, E>;
200impl<'req, B, E> RequestBuilder<'req, B, E> {
201    #[inline]
202    #[doc = "设置是否使用 HTTPS"]
203    pub fn use_https(&mut self, use_https: bool) -> &mut Self {
204        self.0.use_https(use_https);
205        self
206    }
207    #[inline]
208    #[doc = "设置 HTTP 协议版本"]
209    pub fn version(&mut self, version: qiniu_http_client::http::Version) -> &mut Self {
210        self.0.version(version);
211        self
212    }
213    #[inline]
214    #[doc = "设置 HTTP 请求头"]
215    pub fn headers(
216        &mut self,
217        headers: impl Into<std::borrow::Cow<'req, qiniu_http_client::http::HeaderMap>>,
218    ) -> &mut Self {
219        self.0.headers(headers);
220        self
221    }
222    #[inline]
223    #[doc = "添加 HTTP 请求头"]
224    pub fn set_header(
225        &mut self,
226        header_name: impl qiniu_http_client::http::header::IntoHeaderName,
227        header_value: impl Into<qiniu_http_client::http::HeaderValue>,
228    ) -> &mut Self {
229        self.0.set_header(header_name, header_value);
230        self
231    }
232    #[inline]
233    #[doc = "设置查询参数"]
234    pub fn query(&mut self, query: impl Into<std::borrow::Cow<'req, str>>) -> &mut Self {
235        self.0.query(query);
236        self
237    }
238    #[inline]
239    #[doc = "设置查询参数"]
240    pub fn query_pairs(&mut self, query_pairs: impl Into<Vec<qiniu_http_client::QueryPair<'req>>>) -> &mut Self {
241        self.0.query_pairs(query_pairs);
242        self
243    }
244    #[inline]
245    #[doc = "追加查询参数"]
246    pub fn append_query_pair(
247        &mut self,
248        query_pair_key: impl Into<qiniu_http_client::QueryPairKey<'req>>,
249        query_pair_value: impl Into<qiniu_http_client::QueryPairValue<'req>>,
250    ) -> &mut Self {
251        self.0.append_query_pair(query_pair_key, query_pair_value);
252        self
253    }
254    #[inline]
255    #[doc = "设置扩展信息"]
256    pub fn extensions(&mut self, extensions: qiniu_http_client::http::Extensions) -> &mut Self {
257        self.0.extensions(extensions);
258        self
259    }
260    #[doc = "添加扩展信息"]
261    #[inline]
262    pub fn add_extension<T: Send + Sync + 'static>(&mut self, val: T) -> &mut Self {
263        self.0.add_extension(val);
264        self
265    }
266    #[inline]
267    #[doc = "上传进度回调函数"]
268    pub fn on_uploading_progress(
269        &mut self,
270        callback: impl Fn(
271                &dyn qiniu_http_client::SimplifiedCallbackContext,
272                qiniu_http_client::http::TransferProgressInfo,
273            ) -> anyhow::Result<()>
274            + Send
275            + Sync
276            + 'req,
277    ) -> &mut Self {
278        self.0.on_uploading_progress(callback);
279        self
280    }
281    #[inline]
282    #[doc = "设置响应状态码回调函数"]
283    pub fn on_receive_response_status(
284        &mut self,
285        callback: impl Fn(
286                &dyn qiniu_http_client::SimplifiedCallbackContext,
287                qiniu_http_client::http::StatusCode,
288            ) -> anyhow::Result<()>
289            + Send
290            + Sync
291            + 'req,
292    ) -> &mut Self {
293        self.0.on_receive_response_status(callback);
294        self
295    }
296    #[inline]
297    #[doc = "设置响应 HTTP 头回调函数"]
298    pub fn on_receive_response_header(
299        &mut self,
300        callback: impl Fn(
301                &dyn qiniu_http_client::SimplifiedCallbackContext,
302                &qiniu_http_client::http::HeaderName,
303                &qiniu_http_client::http::HeaderValue,
304            ) -> anyhow::Result<()>
305            + Send
306            + Sync
307            + 'req,
308    ) -> &mut Self {
309        self.0.on_receive_response_header(callback);
310        self
311    }
312    #[inline]
313    #[doc = "设置域名解析前回调函数"]
314    pub fn on_to_resolve_domain(
315        &mut self,
316        callback: impl Fn(&mut dyn qiniu_http_client::CallbackContext, &str) -> anyhow::Result<()> + Send + Sync + 'req,
317    ) -> &mut Self {
318        self.0.on_to_resolve_domain(callback);
319        self
320    }
321    #[inline]
322    #[doc = "设置域名解析成功回调函数"]
323    pub fn on_domain_resolved(
324        &mut self,
325        callback: impl Fn(
326                &mut dyn qiniu_http_client::CallbackContext,
327                &str,
328                &qiniu_http_client::ResolveAnswers,
329            ) -> anyhow::Result<()>
330            + Send
331            + Sync
332            + 'req,
333    ) -> &mut Self {
334        self.0.on_domain_resolved(callback);
335        self
336    }
337    #[inline]
338    #[doc = "设置 IP 地址选择前回调函数"]
339    pub fn on_to_choose_ips(
340        &mut self,
341        callback: impl Fn(&mut dyn qiniu_http_client::CallbackContext, &[qiniu_http_client::IpAddrWithPort]) -> anyhow::Result<()>
342            + Send
343            + Sync
344            + 'req,
345    ) -> &mut Self {
346        self.0.on_to_choose_ips(callback);
347        self
348    }
349    #[inline]
350    #[doc = "设置 IP 地址选择成功回调函数"]
351    pub fn on_ips_chosen(
352        &mut self,
353        callback: impl Fn(
354                &mut dyn qiniu_http_client::CallbackContext,
355                &[qiniu_http_client::IpAddrWithPort],
356                &[qiniu_http_client::IpAddrWithPort],
357            ) -> anyhow::Result<()>
358            + Send
359            + Sync
360            + 'req,
361    ) -> &mut Self {
362        self.0.on_ips_chosen(callback);
363        self
364    }
365    #[inline]
366    #[doc = "设置 HTTP 请求签名前回调函数"]
367    pub fn on_before_request_signed(
368        &mut self,
369        callback: impl Fn(&mut dyn qiniu_http_client::ExtendedCallbackContext) -> anyhow::Result<()> + Send + Sync + 'req,
370    ) -> &mut Self {
371        self.0.on_before_request_signed(callback);
372        self
373    }
374    #[inline]
375    #[doc = "设置 HTTP 请求前回调函数"]
376    pub fn on_after_request_signed(
377        &mut self,
378        callback: impl Fn(&mut dyn qiniu_http_client::ExtendedCallbackContext) -> anyhow::Result<()> + Send + Sync + 'req,
379    ) -> &mut Self {
380        self.0.on_after_request_signed(callback);
381        self
382    }
383    #[inline]
384    #[doc = "设置响应成功回调函数"]
385    pub fn on_response(
386        &mut self,
387        callback: impl Fn(
388                &mut dyn qiniu_http_client::ExtendedCallbackContext,
389                &qiniu_http_client::http::ResponseParts,
390            ) -> anyhow::Result<()>
391            + Send
392            + Sync
393            + 'req,
394    ) -> &mut Self {
395        self.0.on_response(callback);
396        self
397    }
398    #[inline]
399    #[doc = "设置响应错误回调函数"]
400    pub fn on_error(
401        &mut self,
402        callback: impl Fn(
403                &mut dyn qiniu_http_client::ExtendedCallbackContext,
404                &mut qiniu_http_client::ResponseError,
405            ) -> anyhow::Result<()>
406            + Send
407            + Sync
408            + 'req,
409    ) -> &mut Self {
410        self.0.on_error(callback);
411        self
412    }
413    #[inline]
414    #[doc = "设置退避前回调函数"]
415    pub fn on_before_backoff(
416        &mut self,
417        callback: impl Fn(&mut dyn qiniu_http_client::ExtendedCallbackContext, std::time::Duration) -> anyhow::Result<()>
418            + Send
419            + Sync
420            + 'req,
421    ) -> &mut Self {
422        self.0.on_before_backoff(callback);
423        self
424    }
425    #[inline]
426    #[doc = "设置退避后回调函数"]
427    pub fn on_after_backoff(
428        &mut self,
429        callback: impl Fn(&mut dyn qiniu_http_client::ExtendedCallbackContext, std::time::Duration) -> anyhow::Result<()>
430            + Send
431            + Sync
432            + 'req,
433    ) -> &mut Self {
434        self.0.on_after_backoff(callback);
435        self
436    }
437    #[inline]
438    #[doc = "获取 HTTP 请求构建器部分参数"]
439    pub fn parts(&self) -> &qiniu_http_client::RequestBuilderParts<'req> {
440        self.0.parts()
441    }
442    #[inline]
443    #[doc = "获取 HTTP 请求构建器部分参数的可变引用"]
444    pub fn parts_mut(&mut self) -> &mut qiniu_http_client::RequestBuilderParts<'req> {
445        self.0.parts_mut()
446    }
447}
448impl<'req, E: qiniu_http_client::EndpointsProvider + Clone + 'req> SyncRequestBuilder<'req, E> {
449    #[doc = "阻塞发起 HTTP 请求"]
450    pub fn call(&mut self) -> qiniu_http_client::ApiResult<qiniu_http_client::Response<ResponseBody>> {
451        let request = &mut self.0;
452        let response = request.call()?;
453        let parsed = response.parse_json()?;
454        Ok(parsed)
455    }
456}
457#[cfg(feature = "async")]
458impl<'req, E: qiniu_http_client::EndpointsProvider + Clone + 'req> AsyncRequestBuilder<'req, E> {
459    #[doc = "异步发起 HTTP 请求"]
460    pub async fn call(&mut self) -> qiniu_http_client::ApiResult<qiniu_http_client::Response<ResponseBody>> {
461        let request = &mut self.0;
462        let response = request.call().await?;
463        let parsed = response.parse_json().await?;
464        Ok(parsed)
465    }
466}