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 mut config: TaskPushNotificationConfig,
34 ) -> ClientResult<TaskPushNotificationConfig> {
35 const METHOD: &str = "CreateTaskPushNotificationConfig";
36
37 config.tenant = self.tenant_or_default(config.tenant.take());
38 let params_value = serde_json::to_value(&config).map_err(ClientError::Serialization)?;
39
40 let mut req = ClientRequest::new(METHOD, params_value);
41 self.interceptors.run_before(&mut req).await?;
42
43 let result = self.send_intercepted(METHOD, &mut req).await?;
44
45 let resp = ClientResponse {
46 method: METHOD.to_owned(),
47 result,
48 status_code: 200,
49 };
50 self.interceptors.run_after(&resp).await?;
51
52 serde_json::from_value::<TaskPushNotificationConfig>(resp.result)
53 .map_err(ClientError::Serialization)
54 }
55
56 pub async fn get_push_config(
64 &self,
65 task_id: impl Into<String>,
66 id: impl Into<String>,
67 ) -> ClientResult<TaskPushNotificationConfig> {
68 const METHOD: &str = "GetTaskPushNotificationConfig";
69
70 let params = GetPushConfigParams {
71 tenant: self.tenant_or_default(None),
72 task_id: task_id.into(),
73 id: id.into(),
74 };
75 let params_value = serde_json::to_value(¶ms).map_err(ClientError::Serialization)?;
76
77 let mut req = ClientRequest::new(METHOD, params_value);
78 self.interceptors.run_before(&mut req).await?;
79
80 let result = self.send_intercepted(METHOD, &mut req).await?;
81
82 let resp = ClientResponse {
83 method: METHOD.to_owned(),
84 result,
85 status_code: 200,
86 };
87 self.interceptors.run_after(&resp).await?;
88
89 serde_json::from_value::<TaskPushNotificationConfig>(resp.result)
90 .map_err(ClientError::Serialization)
91 }
92
93 pub async fn list_push_configs(
101 &self,
102 mut params: ListPushConfigsParams,
103 ) -> ClientResult<ListPushConfigsResponse> {
104 const METHOD: &str = "ListTaskPushNotificationConfigs";
105
106 params.tenant = self.tenant_or_default(params.tenant.take());
107 let params_value = serde_json::to_value(¶ms).map_err(ClientError::Serialization)?;
108 let mut req = ClientRequest::new(METHOD, params_value);
109 self.interceptors.run_before(&mut req).await?;
110
111 let result = self.send_intercepted(METHOD, &mut req).await?;
112
113 let resp = ClientResponse {
114 method: METHOD.to_owned(),
115 result,
116 status_code: 200,
117 };
118 self.interceptors.run_after(&resp).await?;
119
120 serde_json::from_value::<ListPushConfigsResponse>(resp.result)
121 .map_err(ClientError::Serialization)
122 }
123
124 pub async fn delete_push_config(
137 &self,
138 task_id: impl Into<String>,
139 id: impl Into<String>,
140 ) -> ClientResult<()> {
141 const METHOD: &str = "DeleteTaskPushNotificationConfig";
142
143 let params = DeletePushConfigParams {
144 tenant: self.tenant_or_default(None),
145 task_id: task_id.into(),
146 id: id.into(),
147 };
148 let params_value = serde_json::to_value(¶ms).map_err(ClientError::Serialization)?;
149
150 let mut req = ClientRequest::new(METHOD, params_value);
151 self.interceptors.run_before(&mut req).await?;
152
153 let result = self.send_intercepted(METHOD, &mut req).await?;
154
155 let resp = ClientResponse {
156 method: METHOD.to_owned(),
157 result,
158 status_code: 200,
159 };
160 self.interceptors.run_after(&resp).await?;
161
162 Ok(())
163 }
164}