volcengine_rust_sdk/service/iam/api_list_policy_model.rs
1/*
2 * @Author: Jerry.Yang
3 * @Date: 2024-10-25 15:10:33
4 * @LastEditors: Jerry.Yang
5 * @LastEditTime: 2025-02-05 18:36:59
6 * @Description: create login profile model
7 */
8use crate::volcengine::error::error;
9use crate::volcengine::request::request::RequestVolcengine;
10use crate::volcengine::request::{request, response};
11use std::collections::HashMap;
12use volcengine_sdk_protobuf::protobuf::iam_policy;
13
14/// Implementation of the `ApiRequest` trait for the `ListPoliciesReq` struct.
15/// This implementation enables the `ListPoliciesReq` struct to be transformed into a format
16/// suitable for making API requests. It provides methods to convert the request into a hashmap
17/// and a request body.
18impl request::ApiRequest for iam_policy::ListPoliciesReq {
19 /// Converts the `ListPoliciesReq` instance into a hashmap of string key - value pairs.
20 /// This hashmap can be used to construct query parameters or form data for an API request.
21 ///
22 /// # Returns
23 /// - A `HashMap<String, String>` containing the formatted request data.
24 fn to_hashmap(&self) -> HashMap<String, String> {
25 request::Request::format_request_to_hashmap(self)
26 }
27
28 /// Converts the `ListPoliciesReq` instance into a byte vector representing the request body.
29 /// In this case, an empty vector is returned, indicating that there is no specific body data
30 /// for this request.
31 ///
32 /// # Returns
33 /// - A `Vec<u8>` representing the request body.
34 fn to_body(&self) -> Vec<u8> {
35 Vec::new()
36 }
37}
38
39/// Implementation of the `ApiResponse` trait for the `ListPoliciesResp` struct.
40/// This implementation is responsible for converting an HTTP response into the `ListPoliciesResp` struct.
41/// It parses the JSON response body and updates the current instance with the parsed data.
42impl response::ApiResponse for iam_policy::ListPoliciesResp {
43 /// Converts an HTTP response into the `ListPoliciesResp` struct.
44 /// It first parses the JSON response body, then updates the current `ListPoliciesResp` instance
45 /// with the parsed data. If there is an error during parsing, it returns an `Error` struct.
46 ///
47 /// # Arguments
48 /// - `&mut self`: A mutable reference to the `ListPoliciesResp` instance.
49 /// - `http_response`: A `reqwest::Response` containing the HTTP response data.
50 ///
51 /// # Returns
52 /// - On success, returns `Ok(())`.
53 /// - On error, returns an `Error` struct indicating the reason for the failure,
54 /// such as a parsing error.
55 async fn to_struct(&mut self, http_response: reqwest::Response) -> Result<(), error::Error> {
56 // Parse the JSON response body into a `ListPoliciesResp` struct.
57 // If the parsing fails, map the error to an `ErrParseResponse` error type.
58 let parsed_response: volcengine_sdk_protobuf::protobuf::iam_policy::ListPoliciesResp =
59 http_response
60 .json()
61 .await
62 .map_err(|e| error::Error::ErrParseResponse(e))?;
63
64 // Update the current `ListPoliciesResp` instance with the parsed response data.
65 *self = parsed_response;
66
67 // Return `Ok(())` to indicate successful conversion of the HTTP response to the struct.
68 Ok(())
69 }
70}