Skip to main content

rustenium_cdp_definitions/browser_protocol/cache_storage/
command_builders.rs

1use super::commands::*;
2impl DeleteCache {
3    pub fn builder() -> DeleteCacheBuilder {
4        <DeleteCacheBuilder as Default>::default()
5    }
6}
7#[derive(Default, Clone)]
8pub struct DeleteCacheBuilder {
9    cache_id: Option<super::types::CacheId>,
10}
11impl DeleteCacheBuilder {
12    pub fn cache_id(mut self, cache_id: impl Into<super::types::CacheId>) -> Self {
13        self.cache_id = Some(cache_id.into());
14        self
15    }
16    pub fn build(self) -> Result<DeleteCache, String> {
17        Ok(DeleteCache {
18            method: DeleteCacheMethod::DeleteCache,
19            params: DeleteCacheParams {
20                cache_id: self.cache_id.ok_or_else(|| {
21                    format!("Field `{}` is mandatory.", std::stringify!(cache_id))
22                })?,
23            },
24        })
25    }
26}
27impl DeleteEntry {
28    pub fn builder() -> DeleteEntryBuilder {
29        <DeleteEntryBuilder as Default>::default()
30    }
31}
32#[derive(Default, Clone)]
33pub struct DeleteEntryBuilder {
34    cache_id: Option<super::types::CacheId>,
35    request: Option<String>,
36}
37impl DeleteEntryBuilder {
38    pub fn cache_id(mut self, cache_id: impl Into<super::types::CacheId>) -> Self {
39        self.cache_id = Some(cache_id.into());
40        self
41    }
42    pub fn request(mut self, request: impl Into<String>) -> Self {
43        self.request = Some(request.into());
44        self
45    }
46    pub fn build(self) -> Result<DeleteEntry, String> {
47        Ok(DeleteEntry {
48            method: DeleteEntryMethod::DeleteEntry,
49            params: DeleteEntryParams {
50                cache_id: self.cache_id.ok_or_else(|| {
51                    format!("Field `{}` is mandatory.", std::stringify!(cache_id))
52                })?,
53                request: self
54                    .request
55                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(request)))?,
56            },
57        })
58    }
59}
60impl RequestCacheNames {
61    pub fn builder() -> RequestCacheNamesBuilder {
62        <RequestCacheNamesBuilder as Default>::default()
63    }
64}
65#[derive(Default, Clone)]
66pub struct RequestCacheNamesBuilder {
67    security_origin: Option<String>,
68    storage_key: Option<String>,
69    storage_bucket: Option<crate::browser_protocol::storage::types::StorageBucket>,
70}
71impl RequestCacheNamesBuilder {
72    pub fn security_origin(mut self, security_origin: impl Into<String>) -> Self {
73        self.security_origin = Some(security_origin.into());
74        self
75    }
76    pub fn storage_key(mut self, storage_key: impl Into<String>) -> Self {
77        self.storage_key = Some(storage_key.into());
78        self
79    }
80    pub fn storage_bucket(
81        mut self,
82        storage_bucket: impl Into<crate::browser_protocol::storage::types::StorageBucket>,
83    ) -> Self {
84        self.storage_bucket = Some(storage_bucket.into());
85        self
86    }
87    pub fn build(self) -> RequestCacheNames {
88        RequestCacheNames {
89            method: RequestCacheNamesMethod::RequestCacheNames,
90            params: RequestCacheNamesParams {
91                security_origin: self.security_origin,
92                storage_key: self.storage_key,
93                storage_bucket: self.storage_bucket,
94            },
95        }
96    }
97}
98impl RequestCachedResponse {
99    pub fn builder() -> RequestCachedResponseBuilder {
100        <RequestCachedResponseBuilder as Default>::default()
101    }
102}
103#[derive(Default, Clone)]
104pub struct RequestCachedResponseBuilder {
105    cache_id: Option<super::types::CacheId>,
106    request_url: Option<String>,
107    request_headers: Option<Vec<super::types::Header>>,
108}
109impl RequestCachedResponseBuilder {
110    pub fn cache_id(mut self, cache_id: impl Into<super::types::CacheId>) -> Self {
111        self.cache_id = Some(cache_id.into());
112        self
113    }
114    pub fn request_url(mut self, request_url: impl Into<String>) -> Self {
115        self.request_url = Some(request_url.into());
116        self
117    }
118    pub fn request_header(mut self, request_header: impl Into<super::types::Header>) -> Self {
119        let v = self.request_headers.get_or_insert(Vec::new());
120        v.push(request_header.into());
121        self
122    }
123    pub fn request_headers<I, S>(mut self, request_headers: I) -> Self
124    where
125        I: IntoIterator<Item = S>,
126        S: Into<super::types::Header>,
127    {
128        let v = self.request_headers.get_or_insert(Vec::new());
129        for val in request_headers {
130            v.push(val.into());
131        }
132        self
133    }
134    pub fn build(self) -> Result<RequestCachedResponse, String> {
135        Ok(RequestCachedResponse {
136            method: RequestCachedResponseMethod::RequestCachedResponse,
137            params: RequestCachedResponseParams {
138                cache_id: self.cache_id.ok_or_else(|| {
139                    format!("Field `{}` is mandatory.", std::stringify!(cache_id))
140                })?,
141                request_url: self.request_url.ok_or_else(|| {
142                    format!("Field `{}` is mandatory.", std::stringify!(request_url))
143                })?,
144                request_headers: self.request_headers.ok_or_else(|| {
145                    format!("Field `{}` is mandatory.", std::stringify!(request_headers))
146                })?,
147            },
148        })
149    }
150}
151impl RequestEntries {
152    pub fn builder() -> RequestEntriesBuilder {
153        <RequestEntriesBuilder as Default>::default()
154    }
155}
156#[derive(Default, Clone)]
157pub struct RequestEntriesBuilder {
158    cache_id: Option<super::types::CacheId>,
159    skip_count: Option<i64>,
160    page_size: Option<i64>,
161    path_filter: Option<String>,
162}
163impl RequestEntriesBuilder {
164    pub fn cache_id(mut self, cache_id: impl Into<super::types::CacheId>) -> Self {
165        self.cache_id = Some(cache_id.into());
166        self
167    }
168    pub fn skip_count(mut self, skip_count: impl Into<i64>) -> Self {
169        self.skip_count = Some(skip_count.into());
170        self
171    }
172    pub fn page_size(mut self, page_size: impl Into<i64>) -> Self {
173        self.page_size = Some(page_size.into());
174        self
175    }
176    pub fn path_filter(mut self, path_filter: impl Into<String>) -> Self {
177        self.path_filter = Some(path_filter.into());
178        self
179    }
180    pub fn build(self) -> Result<RequestEntries, String> {
181        Ok(RequestEntries {
182            method: RequestEntriesMethod::RequestEntries,
183            params: RequestEntriesParams {
184                cache_id: self.cache_id.ok_or_else(|| {
185                    format!("Field `{}` is mandatory.", std::stringify!(cache_id))
186                })?,
187                skip_count: self.skip_count,
188                page_size: self.page_size,
189                path_filter: self.path_filter,
190            },
191        })
192    }
193}