smarty_rust_sdk/sdk/
options.rs1use reqwest::Proxy;
2use url::Url;
3
4use crate::sdk::authentication::Authenticate;
5
6pub struct OptionsBuilder {
18 license: String,
19 num_retries: u64,
20 logging_enabled: bool,
21 headers: Vec<(String, String)>,
22 authentication: Option<Box<dyn Authenticate>>,
23
24 url: Option<Url>,
25
26 proxy: Option<Proxy>,
27}
28
29#[allow(clippy::new_without_default)]
31impl OptionsBuilder {
32 pub fn new(authentication: Option<Box<dyn Authenticate>>) -> Self {
34 Self {
35 license: "".to_string(),
36 num_retries: 10,
37 logging_enabled: false,
38 headers: vec![],
39 authentication,
40
41 url: None,
42
43 proxy: None,
44 }
45 }
46
47 pub fn build(self) -> Options {
50 Options {
51 license: self.license,
52 num_retries: self.num_retries,
53 logging_enabled: self.logging_enabled,
54 headers: self.headers,
55 authentication: self.authentication,
56
57 url: self.url,
58
59 proxy: self.proxy,
60 }
61 }
62
63 pub fn with_license(mut self, license: &str) -> Self {
65 self.license = license.to_string();
66 self
67 }
68
69 pub fn with_retries(mut self, num_retries: u64) -> Self {
71 self.num_retries = num_retries;
72 self
73 }
74
75 pub fn with_logging(mut self) -> Self {
77 self.logging_enabled = true;
78 self
79 }
80
81 pub fn with_headers(mut self, headers: Vec<(String, String)>) -> Self {
83 self.headers = headers;
84 self
85 }
86
87 pub fn with_url(mut self, url: Url) -> Self {
89 self.url = Some(url);
90 self
91 }
92
93 pub fn with_proxy(mut self, proxy: Proxy) -> Self {
95 self.proxy = Some(proxy);
96 self
97 }
98}
99
100pub struct Options {
106 pub(crate) license: String,
107
108 pub(crate) num_retries: u64,
110
111 pub(crate) logging_enabled: bool,
113
114 pub(crate) headers: Vec<(String, String)>,
116
117 pub(crate) authentication: Option<Box<dyn Authenticate>>,
119
120 pub(crate) url: Option<Url>,
122
123 pub(crate) proxy: Option<Proxy>,
125}
126
127impl Clone for Options {
128 fn clone(&self) -> Self {
129 Self {
130 license: self.license.clone(),
131 num_retries: self.num_retries,
132 logging_enabled: self.logging_enabled,
133 headers: self.headers.clone(),
134 authentication: self.authentication.as_ref().map(|x| x.clone_box()),
135 url: self.url.clone(),
136 proxy: self.proxy.clone(),
137 }
138 }
139}