Skip to main content

rustenium_cdp_definitions/browser_protocol/service_worker/
command_builders.rs

1use super::commands::*;
2impl DeliverPushMessage {
3    pub fn builder() -> DeliverPushMessageBuilder {
4        <DeliverPushMessageBuilder as Default>::default()
5    }
6}
7#[derive(Default, Clone)]
8pub struct DeliverPushMessageBuilder {
9    origin: Option<String>,
10    registration_id: Option<super::types::RegistrationId>,
11    data: Option<String>,
12}
13impl DeliverPushMessageBuilder {
14    pub fn origin(mut self, origin: impl Into<String>) -> Self {
15        self.origin = Some(origin.into());
16        self
17    }
18    pub fn registration_id(
19        mut self,
20        registration_id: impl Into<super::types::RegistrationId>,
21    ) -> Self {
22        self.registration_id = Some(registration_id.into());
23        self
24    }
25    pub fn data(mut self, data: impl Into<String>) -> Self {
26        self.data = Some(data.into());
27        self
28    }
29    pub fn build(self) -> Result<DeliverPushMessage, String> {
30        Ok(DeliverPushMessage {
31            method: DeliverPushMessageMethod::DeliverPushMessage,
32            params: DeliverPushMessageParams {
33                origin: self
34                    .origin
35                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(origin)))?,
36                registration_id: self.registration_id.ok_or_else(|| {
37                    format!("Field `{}` is mandatory.", std::stringify!(registration_id))
38                })?,
39                data: self
40                    .data
41                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(data)))?,
42            },
43        })
44    }
45}
46#[derive(Debug, Clone, Default)]
47pub struct DisableBuilder;
48impl DisableBuilder {
49    pub fn new() -> Self {
50        Self
51    }
52    pub fn build(self) -> Disable {
53        Disable {
54            method: DisableMethod::Disable,
55            params: DisableParams {},
56        }
57    }
58}
59impl Disable {
60    pub fn builder() -> DisableBuilder {
61        DisableBuilder
62    }
63}
64impl DispatchSyncEvent {
65    pub fn builder() -> DispatchSyncEventBuilder {
66        <DispatchSyncEventBuilder as Default>::default()
67    }
68}
69#[derive(Default, Clone)]
70pub struct DispatchSyncEventBuilder {
71    origin: Option<String>,
72    registration_id: Option<super::types::RegistrationId>,
73    tag: Option<String>,
74    last_chance: Option<bool>,
75}
76impl DispatchSyncEventBuilder {
77    pub fn origin(mut self, origin: impl Into<String>) -> Self {
78        self.origin = Some(origin.into());
79        self
80    }
81    pub fn registration_id(
82        mut self,
83        registration_id: impl Into<super::types::RegistrationId>,
84    ) -> Self {
85        self.registration_id = Some(registration_id.into());
86        self
87    }
88    pub fn tag(mut self, tag: impl Into<String>) -> Self {
89        self.tag = Some(tag.into());
90        self
91    }
92    pub fn last_chance(mut self, last_chance: impl Into<bool>) -> Self {
93        self.last_chance = Some(last_chance.into());
94        self
95    }
96    pub fn build(self) -> Result<DispatchSyncEvent, String> {
97        Ok(DispatchSyncEvent {
98            method: DispatchSyncEventMethod::DispatchSyncEvent,
99            params: DispatchSyncEventParams {
100                origin: self
101                    .origin
102                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(origin)))?,
103                registration_id: self.registration_id.ok_or_else(|| {
104                    format!("Field `{}` is mandatory.", std::stringify!(registration_id))
105                })?,
106                tag: self
107                    .tag
108                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(tag)))?,
109                last_chance: self.last_chance.ok_or_else(|| {
110                    format!("Field `{}` is mandatory.", std::stringify!(last_chance))
111                })?,
112            },
113        })
114    }
115}
116impl DispatchPeriodicSyncEvent {
117    pub fn builder() -> DispatchPeriodicSyncEventBuilder {
118        <DispatchPeriodicSyncEventBuilder as Default>::default()
119    }
120}
121#[derive(Default, Clone)]
122pub struct DispatchPeriodicSyncEventBuilder {
123    origin: Option<String>,
124    registration_id: Option<super::types::RegistrationId>,
125    tag: Option<String>,
126}
127impl DispatchPeriodicSyncEventBuilder {
128    pub fn origin(mut self, origin: impl Into<String>) -> Self {
129        self.origin = Some(origin.into());
130        self
131    }
132    pub fn registration_id(
133        mut self,
134        registration_id: impl Into<super::types::RegistrationId>,
135    ) -> Self {
136        self.registration_id = Some(registration_id.into());
137        self
138    }
139    pub fn tag(mut self, tag: impl Into<String>) -> Self {
140        self.tag = Some(tag.into());
141        self
142    }
143    pub fn build(self) -> Result<DispatchPeriodicSyncEvent, String> {
144        Ok(DispatchPeriodicSyncEvent {
145            method: DispatchPeriodicSyncEventMethod::DispatchPeriodicSyncEvent,
146            params: DispatchPeriodicSyncEventParams {
147                origin: self
148                    .origin
149                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(origin)))?,
150                registration_id: self.registration_id.ok_or_else(|| {
151                    format!("Field `{}` is mandatory.", std::stringify!(registration_id))
152                })?,
153                tag: self
154                    .tag
155                    .ok_or_else(|| format!("Field `{}` is mandatory.", std::stringify!(tag)))?,
156            },
157        })
158    }
159}
160#[derive(Debug, Clone, Default)]
161pub struct EnableBuilder;
162impl EnableBuilder {
163    pub fn new() -> Self {
164        Self
165    }
166    pub fn build(self) -> Enable {
167        Enable {
168            method: EnableMethod::Enable,
169            params: EnableParams {},
170        }
171    }
172}
173impl Enable {
174    pub fn builder() -> EnableBuilder {
175        EnableBuilder
176    }
177}
178impl SetForceUpdateOnPageLoad {
179    pub fn builder() -> SetForceUpdateOnPageLoadBuilder {
180        <SetForceUpdateOnPageLoadBuilder as Default>::default()
181    }
182}
183#[derive(Default, Clone)]
184pub struct SetForceUpdateOnPageLoadBuilder {
185    force_update_on_page_load: Option<bool>,
186}
187impl SetForceUpdateOnPageLoadBuilder {
188    pub fn force_update_on_page_load(mut self, force_update_on_page_load: impl Into<bool>) -> Self {
189        self.force_update_on_page_load = Some(force_update_on_page_load.into());
190        self
191    }
192    pub fn build(self) -> Result<SetForceUpdateOnPageLoad, String> {
193        Ok(SetForceUpdateOnPageLoad {
194            method: SetForceUpdateOnPageLoadMethod::SetForceUpdateOnPageLoad,
195            params: SetForceUpdateOnPageLoadParams {
196                force_update_on_page_load: self.force_update_on_page_load.ok_or_else(|| {
197                    format!(
198                        "Field `{}` is mandatory.",
199                        std::stringify!(force_update_on_page_load)
200                    )
201                })?,
202            },
203        })
204    }
205}
206impl SkipWaiting {
207    pub fn builder() -> SkipWaitingBuilder {
208        <SkipWaitingBuilder as Default>::default()
209    }
210}
211#[derive(Default, Clone)]
212pub struct SkipWaitingBuilder {
213    scope_url: Option<String>,
214}
215impl SkipWaitingBuilder {
216    pub fn scope_url(mut self, scope_url: impl Into<String>) -> Self {
217        self.scope_url = Some(scope_url.into());
218        self
219    }
220    pub fn build(self) -> Result<SkipWaiting, String> {
221        Ok(SkipWaiting {
222            method: SkipWaitingMethod::SkipWaiting,
223            params: SkipWaitingParams {
224                scope_url: self.scope_url.ok_or_else(|| {
225                    format!("Field `{}` is mandatory.", std::stringify!(scope_url))
226                })?,
227            },
228        })
229    }
230}
231impl StartWorker {
232    pub fn builder() -> StartWorkerBuilder {
233        <StartWorkerBuilder as Default>::default()
234    }
235}
236#[derive(Default, Clone)]
237pub struct StartWorkerBuilder {
238    scope_url: Option<String>,
239}
240impl StartWorkerBuilder {
241    pub fn scope_url(mut self, scope_url: impl Into<String>) -> Self {
242        self.scope_url = Some(scope_url.into());
243        self
244    }
245    pub fn build(self) -> Result<StartWorker, String> {
246        Ok(StartWorker {
247            method: StartWorkerMethod::StartWorker,
248            params: StartWorkerParams {
249                scope_url: self.scope_url.ok_or_else(|| {
250                    format!("Field `{}` is mandatory.", std::stringify!(scope_url))
251                })?,
252            },
253        })
254    }
255}
256#[derive(Debug, Clone, Default)]
257pub struct StopAllWorkersBuilder;
258impl StopAllWorkersBuilder {
259    pub fn new() -> Self {
260        Self
261    }
262    pub fn build(self) -> StopAllWorkers {
263        StopAllWorkers {
264            method: StopAllWorkersMethod::StopAllWorkers,
265            params: StopAllWorkersParams {},
266        }
267    }
268}
269impl StopAllWorkers {
270    pub fn builder() -> StopAllWorkersBuilder {
271        StopAllWorkersBuilder
272    }
273}
274impl StopWorker {
275    pub fn builder() -> StopWorkerBuilder {
276        <StopWorkerBuilder as Default>::default()
277    }
278}
279#[derive(Default, Clone)]
280pub struct StopWorkerBuilder {
281    version_id: Option<String>,
282}
283impl StopWorkerBuilder {
284    pub fn version_id(mut self, version_id: impl Into<String>) -> Self {
285        self.version_id = Some(version_id.into());
286        self
287    }
288    pub fn build(self) -> Result<StopWorker, String> {
289        Ok(StopWorker {
290            method: StopWorkerMethod::StopWorker,
291            params: StopWorkerParams {
292                version_id: self.version_id.ok_or_else(|| {
293                    format!("Field `{}` is mandatory.", std::stringify!(version_id))
294                })?,
295            },
296        })
297    }
298}
299impl Unregister {
300    pub fn builder() -> UnregisterBuilder {
301        <UnregisterBuilder as Default>::default()
302    }
303}
304#[derive(Default, Clone)]
305pub struct UnregisterBuilder {
306    scope_url: Option<String>,
307}
308impl UnregisterBuilder {
309    pub fn scope_url(mut self, scope_url: impl Into<String>) -> Self {
310        self.scope_url = Some(scope_url.into());
311        self
312    }
313    pub fn build(self) -> Result<Unregister, String> {
314        Ok(Unregister {
315            method: UnregisterMethod::Unregister,
316            params: UnregisterParams {
317                scope_url: self.scope_url.ok_or_else(|| {
318                    format!("Field `{}` is mandatory.", std::stringify!(scope_url))
319                })?,
320            },
321        })
322    }
323}
324impl UpdateRegistration {
325    pub fn builder() -> UpdateRegistrationBuilder {
326        <UpdateRegistrationBuilder as Default>::default()
327    }
328}
329#[derive(Default, Clone)]
330pub struct UpdateRegistrationBuilder {
331    scope_url: Option<String>,
332}
333impl UpdateRegistrationBuilder {
334    pub fn scope_url(mut self, scope_url: impl Into<String>) -> Self {
335        self.scope_url = Some(scope_url.into());
336        self
337    }
338    pub fn build(self) -> Result<UpdateRegistration, String> {
339        Ok(UpdateRegistration {
340            method: UpdateRegistrationMethod::UpdateRegistration,
341            params: UpdateRegistrationParams {
342                scope_url: self.scope_url.ok_or_else(|| {
343                    format!("Field `{}` is mandatory.", std::stringify!(scope_url))
344                })?,
345            },
346        })
347    }
348}