1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Signal methods for [`IronflowClient`].
use ironflow_types::ApiResponse;
use crate::client::{IronflowClient, ListSignalsFilter};
use crate::error::Error;
use crate::types;
impl IronflowClient {
/// Send a signal, resuming every run waiting for its `(name, key)`.
///
/// The caller must be an admin, or use an API key with the `signals_send`
/// scope. Sending again with the same `idempotency_id` delivers nothing
/// and returns `duplicate: true`.
///
/// # Errors
///
/// Returns an error if the HTTP request fails, the signal is invalid
/// (empty name or key), the caller lacks the permission, or the response
/// cannot be deserialized.
///
/// # Examples
///
/// ```no_run
/// use ironflow_sdk::IronflowClient;
/// use ironflow_sdk::types::SendSignalRequest;
/// use serde_json::json;
///
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let client = IronflowClient::new("https://ironflow.example.com", "key");
/// let request: SendSignalRequest = serde_json::from_value(json!({
/// "name": "ci.pipeline_finished",
/// "key": "4f2a9c1",
/// "payload": {"status": "success"},
/// "idempotency_id": "delivery-42"
/// }))?;
/// let delivery = client.send_signal(&request).await?;
/// println!("{} runs resumed", delivery.data.resumed.len());
/// # Ok(())
/// # }
/// ```
pub async fn send_signal(
&self,
request: &types::SendSignalRequest,
) -> Result<ApiResponse<types::SignalDeliveryResponse>, Error> {
self.send_envelope(self.post("/api/v1/signals").json(request))
.await
}
/// List received signals, newest first, with filters and pagination.
///
/// # Errors
///
/// Returns an error if the HTTP request fails or the response cannot be deserialized.
///
/// # Examples
///
/// ```no_run
/// use ironflow_sdk::IronflowClient;
/// use ironflow_sdk::client::ListSignalsFilter;
///
/// # async fn example() -> Result<(), ironflow_sdk::Error> {
/// let client = IronflowClient::new("https://ironflow.example.com", "key");
/// let filter = ListSignalsFilter {
/// name: Some("ci.pipeline_finished".to_string()),
/// ..Default::default()
/// };
/// let signals = client.list_signals(&filter).await?;
/// # Ok(())
/// # }
/// ```
pub async fn list_signals(
&self,
filter: &ListSignalsFilter,
) -> Result<ApiResponse<Vec<types::SignalResponse>>, Error> {
self.send_envelope(self.get("/api/v1/signals").query(filter))
.await
}
}