a2a_protocol_client/methods/
push_config.rs1use a2a_protocol_types::{
12 DeletePushConfigParams, GetPushConfigParams, ListPushConfigsParams, ListPushConfigsResponse,
13 TaskPushNotificationConfig,
14};
15
16use crate::client::A2aClient;
17use crate::error::{ClientError, ClientResult};
18use crate::interceptor::{ClientRequest, ClientResponse};
19
20impl A2aClient {
21 pub async fn set_push_config(
32 &self,
33 config: TaskPushNotificationConfig,
34 ) -> ClientResult<TaskPushNotificationConfig> {
35 const METHOD: &str = "CreateTaskPushNotificationConfig";
36
37 let params_value = serde_json::to_value(&config).map_err(ClientError::Serialization)?;
38
39 let mut req = ClientRequest::new(METHOD, params_value);
40 self.interceptors.run_before(&mut req).await?;
41
42 let result = self
43 .transport
44 .send_request(METHOD, req.params, &req.extra_headers)
45 .await?;
46
47 let resp = ClientResponse {
48 method: METHOD.to_owned(),
49 result,
50 status_code: 200,
51 };
52 self.interceptors.run_after(&resp).await?;
53
54 serde_json::from_value::<TaskPushNotificationConfig>(resp.result)
55 .map_err(ClientError::Serialization)
56 }
57
58 pub async fn get_push_config(
66 &self,
67 task_id: impl Into<String>,
68 id: impl Into<String>,
69 ) -> ClientResult<TaskPushNotificationConfig> {
70 const METHOD: &str = "GetTaskPushNotificationConfig";
71
72 let params = GetPushConfigParams {
73 tenant: None,
74 task_id: task_id.into(),
75 id: id.into(),
76 };
77 let params_value = serde_json::to_value(¶ms).map_err(ClientError::Serialization)?;
78
79 let mut req = ClientRequest::new(METHOD, params_value);
80 self.interceptors.run_before(&mut req).await?;
81
82 let result = self
83 .transport
84 .send_request(METHOD, req.params, &req.extra_headers)
85 .await?;
86
87 let resp = ClientResponse {
88 method: METHOD.to_owned(),
89 result,
90 status_code: 200,
91 };
92 self.interceptors.run_after(&resp).await?;
93
94 serde_json::from_value::<TaskPushNotificationConfig>(resp.result)
95 .map_err(ClientError::Serialization)
96 }
97
98 pub async fn list_push_configs(
106 &self,
107 params: ListPushConfigsParams,
108 ) -> ClientResult<ListPushConfigsResponse> {
109 const METHOD: &str = "ListTaskPushNotificationConfigs";
110
111 let params_value = serde_json::to_value(¶ms).map_err(ClientError::Serialization)?;
112 let mut req = ClientRequest::new(METHOD, params_value);
113 self.interceptors.run_before(&mut req).await?;
114
115 let result = self
116 .transport
117 .send_request(METHOD, req.params, &req.extra_headers)
118 .await?;
119
120 let resp = ClientResponse {
121 method: METHOD.to_owned(),
122 result,
123 status_code: 200,
124 };
125 self.interceptors.run_after(&resp).await?;
126
127 serde_json::from_value::<ListPushConfigsResponse>(resp.result)
128 .map_err(ClientError::Serialization)
129 }
130
131 pub async fn delete_push_config(
139 &self,
140 task_id: impl Into<String>,
141 id: impl Into<String>,
142 ) -> ClientResult<()> {
143 const METHOD: &str = "DeleteTaskPushNotificationConfig";
144
145 let params = DeletePushConfigParams {
146 tenant: None,
147 task_id: task_id.into(),
148 id: id.into(),
149 };
150 let params_value = serde_json::to_value(¶ms).map_err(ClientError::Serialization)?;
151
152 let mut req = ClientRequest::new(METHOD, params_value);
153 self.interceptors.run_before(&mut req).await?;
154
155 let result = self
156 .transport
157 .send_request(METHOD, req.params, &req.extra_headers)
158 .await?;
159
160 let resp = ClientResponse {
161 method: METHOD.to_owned(),
162 result,
163 status_code: 200,
164 };
165 self.interceptors.run_after(&resp).await?;
166
167 Ok(())
168 }
169}