rust_dropbox/
lib.rs

1pub mod client;
2mod test;
3
4use serde::Deserialize;
5#[derive(Debug, Deserialize)]
6struct DbxRequestLimitsErrorSummary {
7    error_summary: String,
8    error: DbxRequestErrorReason,
9}
10#[derive(Debug, Deserialize)]
11struct DbxRequestErrorSummary {
12    error_summary: String,
13    error: DbxRequestErrorTag,
14}
15
16#[derive(Debug, Deserialize)]
17struct DbxRequestErrorReason {
18    reason: DbxRequestErrorTag,
19    retry_after: u32,
20}
21#[derive(Debug, Deserialize)]
22struct DbxRequestErrorTag {
23    #[serde(alias = ".tag")]
24    tag: String,
25}
26#[derive(Debug, Deserialize)]
27struct UserCheckResult {
28    result: String,
29}
30
31pub type DropboxResult<T> = std::result::Result<T, DropboxError>;
32#[derive(Debug)]
33pub enum DropboxError {
34    #[cfg(feature = "non-blocking")]
35    NonBlockingRequestError(reqwest::Error),
36    #[cfg(feature = "blocking")]
37    BlockingRequestError(ureq::Error),
38    DbxUserCheckError(String),
39    DbxPathError(String),
40    DbxExistedError(String),
41    DbxInvalidTokenError(String),
42    DbxFromLookUpError(String),
43    DbxRequestLimitsError(String),
44    DbxAccessError(String),
45    DbxConflictError(String),
46    DbxServerError(String),
47    OtherError(String),
48    #[cfg(feature = "blocking")]
49    BodyParseError(std::io::Error),
50}
51
52#[cfg(feature = "blocking")]
53impl From<std::io::Error> for DropboxError {
54    fn from(e: std::io::Error) -> Self {
55        Self::BodyParseError(e)
56    }
57}
58
59#[cfg(feature = "non-blocking")]
60impl From<reqwest::Error> for DropboxError {
61    fn from(e: reqwest::Error) -> Self {
62        Self::NonBlockingRequestError(e)
63    }
64}
65#[cfg(feature = "blocking")]
66impl From<ureq::Error> for DropboxError {
67    fn from(e: ureq::Error) -> Self {
68        Self::BlockingRequestError(e)
69    }
70}
71
72#[derive(Clone)]
73pub struct UploadOption {
74    mode: UploadMode,
75    allow_auto_rename: bool,
76    mute_notification: bool,
77    allow_strict_conflict: bool,
78}
79pub struct UploadOptionBuilder {
80    mode: UploadMode,
81    allow_auto_rename: bool,
82    mute_notification: bool,
83    allow_strict_conflict: bool,
84}
85
86impl UploadOptionBuilder {
87    ///new will return an option with follow value
88    ///mode:"add", autorename:"true", mute:"false", strict_conflict: "false"
89    pub fn new() -> Self {
90        Self {
91            mode: UploadMode::Add,
92            allow_auto_rename: true,
93            mute_notification: false,
94            allow_strict_conflict: false,
95        }
96    }
97
98    pub fn disallow_auto_rename(&mut self) -> &mut UploadOptionBuilder {
99        self.allow_auto_rename = false;
100        self
101    }
102
103    pub fn mute_notification(&mut self) -> &mut UploadOptionBuilder {
104        self.mute_notification = true;
105        self
106    }
107
108    pub fn allow_strict_conflict(&mut self) -> &mut UploadOptionBuilder {
109        self.allow_strict_conflict = true;
110        self
111    }
112
113    pub fn set_upload_mode(&mut self, mode: UploadMode) -> &mut UploadOptionBuilder {
114        self.mode = mode;
115        self
116    }
117
118    pub fn build(&self) -> UploadOption {
119        UploadOption {
120            mode: self.mode.clone(),
121            allow_auto_rename: self.allow_auto_rename,
122            mute_notification: self.mute_notification,
123            allow_strict_conflict: self.allow_strict_conflict,
124        }
125    }
126}
127
128#[derive(Clone)]
129pub struct MoveCopyOption {
130    allow_shared_folder: bool,
131    auto_rename: bool,
132    allow_ownership_transfer: bool,
133}
134pub struct MoveCopyOptionBuilder {
135    allow_shared_folder: bool,
136    auto_rename: bool,
137    allow_ownership_transfer: bool,
138}
139
140impl MoveCopyOptionBuilder {
141    ///new will return an option with follow value
142    ///sheared_folder:"true", autorename:"false", ownership_transfer:"false"
143    pub fn new() -> Self {
144        Self {
145            allow_shared_folder: false,
146            auto_rename: false,
147            allow_ownership_transfer: false,
148        }
149    }
150
151    pub fn allow_shared_folder(&mut self) -> &mut MoveCopyOptionBuilder {
152        self.allow_shared_folder = true;
153        self
154    }
155
156    pub fn allow_auto_rename(&mut self) -> &mut MoveCopyOptionBuilder {
157        self.auto_rename = true;
158        self
159    }
160
161    pub fn allow_ownership_transfer(&mut self) -> &mut MoveCopyOptionBuilder {
162        self.allow_ownership_transfer = true;
163        self
164    }
165
166    pub fn build(&mut self) -> MoveCopyOption {
167        MoveCopyOption {
168            allow_ownership_transfer: self.allow_ownership_transfer,
169            allow_shared_folder: self.allow_shared_folder,
170            auto_rename: self.auto_rename,
171        }
172    }
173}
174
175#[derive(Clone)]
176///Update will receive rev for the Update.0
177pub enum UploadMode {
178    Add,
179    Overwrite,
180    Update(String),
181}