open_lark/core/
req_option.rs1#![allow(dead_code)]
2
3use std::collections::HashMap;
4
5#[derive(Debug, Clone, Default)]
6pub struct RequestOption {
7 pub(crate) tenant_key: String,
8 pub(crate) user_access_token: String,
9 pub(crate) app_access_token: String,
10 pub(crate) tenant_access_token: String,
11 pub(crate) need_helpdesk_auth: bool,
12 pub(crate) request_id: String,
13 pub(crate) app_ticket: String,
14 pub(crate) file_upload: bool,
15 pub(crate) file_download: bool,
16 pub(crate) header: HashMap<String, String>,
17}
18
19impl RequestOption {
20 pub fn builder() -> RequestOptionBuilder {
21 RequestOptionBuilder::default()
22 }
23}
24
25#[derive(Default)]
26pub struct RequestOptionBuilder {
27 option: RequestOption,
28}
29
30impl RequestOptionBuilder {
31 pub fn tenant_key(mut self, tenant_key: impl ToString) -> Self {
32 self.option.tenant_key = tenant_key.to_string();
33 self
34 }
35
36 pub fn user_access_token(mut self, user_access_token: impl ToString) -> Self {
37 self.option.user_access_token = user_access_token.to_string();
38 self
39 }
40
41 pub fn app_access_token(mut self, app_access_token: impl ToString) -> Self {
42 self.option.app_access_token = app_access_token.to_string();
43 self
44 }
45
46 pub fn tenant_access_token(mut self, tenant_access_token: impl ToString) -> Self {
47 self.option.tenant_access_token = tenant_access_token.to_string();
48 self
49 }
50
51 pub fn need_helpdesk_auth(mut self, need_helpdesk_auth: bool) -> Self {
52 self.option.need_helpdesk_auth = need_helpdesk_auth;
53 self
54 }
55
56 pub fn request_id(mut self, request_id: impl ToString) -> Self {
57 self.option.request_id = request_id.to_string();
58 self
59 }
60
61 pub fn app_ticket(mut self, app_ticket: impl ToString) -> Self {
62 self.option.app_ticket = app_ticket.to_string();
63 self
64 }
65
66 pub fn file_upload(mut self, file_upload: bool) -> Self {
67 self.option.file_upload = file_upload;
68 self
69 }
70
71 pub fn file_download(mut self, file_download: bool) -> Self {
72 self.option.file_download = file_download;
73 self
74 }
75
76 pub fn header(mut self, header: HashMap<String, String>) -> Self {
77 self.option.header = header;
78 self
79 }
80
81 pub fn add_header(mut self, key: impl ToString, value: impl ToString) -> Self {
83 self.option
84 .header
85 .insert(key.to_string(), value.to_string());
86 self
87 }
88
89 pub fn build(self) -> RequestOption {
90 self.option
91 }
92}