volcengine_rust_sdk/service/iam/api_get_login_profile_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:16:31
6 * @Description: get 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_user;
13
14/// Implementation of the `ApiRequest` trait for the `GetLoginProfileReq` struct.
15/// This implementation provides methods to convert the request into a hashmap and a request body.
16impl request::ApiRequest for iam_user::GetLoginProfileReq {
17 /// Converts the `GetLoginProfileReq` instance into a hashmap of string key - value pairs.
18 ///
19 /// # Returns
20 /// - A `HashMap<String, String>` containing the formatted request data.
21 fn to_hashmap(&self) -> HashMap<String, String> {
22 request::Request::format_request_to_hashmap(self)
23 }
24
25 /// Converts the `GetLoginProfileReq` instance into a byte vector representing the request body.
26 /// In this case, an empty vector is returned as the body.
27 ///
28 /// # Returns
29 /// - A `Vec<u8>` representing the request body.
30 fn to_body(&self) -> Vec<u8> {
31 Vec::new()
32 }
33}
34
35/// Implementation of the `ApiResponse` trait for the `GetLoginProfileResp` struct.
36/// This implementation provides a method to convert an HTTP response into the `GetLoginProfileResp` struct.
37impl response::ApiResponse for iam_user::GetLoginProfileResp {
38 /// Converts an HTTP response into the `GetLoginProfileResp` struct.
39 /// It also handles error cases and updates the response metadata if the HTTP status is not successful.
40 ///
41 /// # Arguments
42 /// - `&mut self`: A mutable reference to the `GetLoginProfileResp` instance.
43 /// - `http_response`: A `reqwest::Response` containing the HTTP response data.
44 ///
45 /// # Returns
46 /// - On success, returns `Ok(())`.
47 /// - On error, returns an `Error` struct indicating the reason for the failure, such as a parsing error.
48 async fn to_struct(&mut self, http_response: reqwest::Response) -> Result<(), error::Error> {
49 // Get the HTTP status code
50 let http_status = http_response.status();
51
52 // Parse the JSON response body
53 let parsed_response: volcengine_sdk_protobuf::protobuf::iam_user::GetLoginProfileResp =
54 http_response
55 .json()
56 .await
57 .map_err(error::Error::ErrParseResponse)?;
58
59 // Update the current object
60 *self = parsed_response;
61
62 // Check if it's an error request
63 if !http_status.is_success() {
64 // Check if `response_metadata` exists
65 if let Some(mut response_metadata) = self.response_metadata.take() {
66 // Ensure the `error` field exists
67 let response_metadata_error = response_metadata.error.get_or_insert_with(
68 volcengine_sdk_protobuf::protobuf::iam_user::ResponseMetadataErr::default,
69 );
70
71 // Set the `code_n` field
72 response_metadata_error.code_n = Some(http_status.as_u16().into());
73
74 // Update `response_metadata`
75 self.response_metadata = Some(response_metadata);
76 }
77 }
78
79 // Return result
80 Ok(())
81 }
82}