allora_runtime/spec/
http_outbound_adapter_spec.rs1use serde::Deserialize;
2
3#[derive(Debug, Clone, Deserialize)]
4pub struct HttpOutboundAdapterSpecRootV1 {
5 pub version: u32,
6 #[serde(rename = "http-outbound-adapter")]
7 pub http_outbound_adapter: HttpOutboundAdapterSpecBlock,
8}
9
10#[derive(Debug, Clone, Deserialize)]
11pub struct HttpOutboundAdapterSpecBlock {
12 pub id: Option<String>,
13 pub host: String,
14 pub port: u16,
15 #[serde(rename = "base-path")]
16 pub base_path: Option<String>,
17 pub path: Option<String>,
18 pub method: Option<String>,
19 #[serde(rename = "use-out-msg")]
20 pub use_out_msg: Option<bool>,
21}
22
23#[derive(Debug, Clone)]
24pub struct HttpOutboundAdapterSpec(HttpOutboundAdapterSpecBlock);
25
26impl HttpOutboundAdapterSpec {
27 pub(crate) fn from_block(b: HttpOutboundAdapterSpecBlock) -> Self {
28 Self(b)
29 }
30 pub fn new(
31 host: &str,
32 port: u16,
33 base_path: &str,
34 path: Option<&str>,
35 method: Option<&str>,
36 id: Option<&str>,
37 use_out_msg: bool,
38 ) -> Self {
39 let blk = HttpOutboundAdapterSpecBlock {
40 id: id.map(|s| s.to_string()),
41 host: host.to_string(),
42 port,
43 base_path: Some(base_path.to_string()),
44 path: path.map(|p| p.to_string()),
45 method: method.map(|m| m.to_string()),
46 use_out_msg: Some(use_out_msg),
47 };
48 Self(blk)
49 }
50 pub fn with_id(
51 id: &str,
52 host: &str,
53 port: u16,
54 base_path: &str,
55 path: Option<&str>,
56 method: Option<&str>,
57 use_out_msg: bool,
58 ) -> Self {
59 Self::new(host, port, base_path, path, method, Some(id), use_out_msg)
60 }
61 pub fn id(&self) -> Option<&str> {
62 self.0.id.as_deref()
63 }
64 pub fn host(&self) -> &str {
65 &self.0.host
66 }
67 pub fn port(&self) -> u16 {
68 self.0.port
69 }
70 pub fn base_path(&self) -> &str {
71 self.0.base_path.as_deref().unwrap_or("/")
72 }
73 pub fn path(&self) -> Option<&str> {
74 self.0.path.as_deref()
75 }
76 pub fn method(&self) -> Option<&str> {
77 self.0.method.as_deref()
78 }
79 pub fn use_out_msg(&self) -> bool {
80 self.0.use_out_msg.unwrap_or(true)
81 }
82}