dropbox_sdk/generated/types/
auth.rs

1// DO NOT EDIT
2// This file was @generated by Stone
3
4#![allow(
5    clippy::too_many_arguments,
6    clippy::large_enum_variant,
7    clippy::result_large_err,
8    clippy::doc_markdown,
9)]
10
11/// Error occurred because the account doesn't have permission to access the resource.
12#[derive(Debug, Clone, PartialEq, Eq)]
13#[non_exhaustive] // variants may be added in the future
14pub enum AccessError {
15    /// Current account type cannot access the resource.
16    InvalidAccountType(InvalidAccountTypeError),
17    /// Current account cannot access Paper.
18    PaperAccessDenied(PaperAccessError),
19    /// Catch-all used for unrecognized values returned from the server. Encountering this value
20    /// typically indicates that this SDK version is out of date.
21    Other,
22}
23
24impl<'de> ::serde::de::Deserialize<'de> for AccessError {
25    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
26        // union deserializer
27        use serde::de::{self, MapAccess, Visitor};
28        struct EnumVisitor;
29        impl<'de> Visitor<'de> for EnumVisitor {
30            type Value = AccessError;
31            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
32                f.write_str("a AccessError structure")
33            }
34            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
35                let tag: &str = match map.next_key()? {
36                    Some(".tag") => map.next_value()?,
37                    _ => return Err(de::Error::missing_field(".tag"))
38                };
39                let value = match tag {
40                    "invalid_account_type" => {
41                        match map.next_key()? {
42                            Some("invalid_account_type") => AccessError::InvalidAccountType(map.next_value()?),
43                            None => return Err(de::Error::missing_field("invalid_account_type")),
44                            _ => return Err(de::Error::unknown_field(tag, VARIANTS))
45                        }
46                    }
47                    "paper_access_denied" => {
48                        match map.next_key()? {
49                            Some("paper_access_denied") => AccessError::PaperAccessDenied(map.next_value()?),
50                            None => return Err(de::Error::missing_field("paper_access_denied")),
51                            _ => return Err(de::Error::unknown_field(tag, VARIANTS))
52                        }
53                    }
54                    _ => AccessError::Other,
55                };
56                crate::eat_json_fields(&mut map)?;
57                Ok(value)
58            }
59        }
60        const VARIANTS: &[&str] = &["invalid_account_type",
61                                    "paper_access_denied",
62                                    "other"];
63        deserializer.deserialize_struct("AccessError", VARIANTS, EnumVisitor)
64    }
65}
66
67impl ::serde::ser::Serialize for AccessError {
68    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
69        // union serializer
70        use serde::ser::SerializeStruct;
71        match self {
72            AccessError::InvalidAccountType(x) => {
73                // union or polymporphic struct
74                let mut s = serializer.serialize_struct("AccessError", 2)?;
75                s.serialize_field(".tag", "invalid_account_type")?;
76                s.serialize_field("invalid_account_type", x)?;
77                s.end()
78            }
79            AccessError::PaperAccessDenied(x) => {
80                // union or polymporphic struct
81                let mut s = serializer.serialize_struct("AccessError", 2)?;
82                s.serialize_field(".tag", "paper_access_denied")?;
83                s.serialize_field("paper_access_denied", x)?;
84                s.end()
85            }
86            AccessError::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
87        }
88    }
89}
90
91impl ::std::error::Error for AccessError {
92    fn source(&self) -> Option<&(dyn ::std::error::Error + 'static)> {
93        match self {
94            AccessError::InvalidAccountType(inner) => Some(inner),
95            AccessError::PaperAccessDenied(inner) => Some(inner),
96            _ => None,
97        }
98    }
99}
100
101impl ::std::fmt::Display for AccessError {
102    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
103        match self {
104            AccessError::InvalidAccountType(inner) => write!(f, "Current account type cannot access the resource: {}", inner),
105            AccessError::PaperAccessDenied(inner) => write!(f, "Current account cannot access Paper: {}", inner),
106            _ => write!(f, "{:?}", *self),
107        }
108    }
109}
110
111/// Errors occurred during authentication.
112#[derive(Debug, Clone, PartialEq, Eq)]
113#[non_exhaustive] // variants may be added in the future
114pub enum AuthError {
115    /// The access token is invalid.
116    InvalidAccessToken,
117    /// The user specified in 'Dropbox-API-Select-User' is no longer on the team.
118    InvalidSelectUser,
119    /// The user specified in 'Dropbox-API-Select-Admin' is not a Dropbox Business team admin.
120    InvalidSelectAdmin,
121    /// The user has been suspended.
122    UserSuspended,
123    /// The access token has expired.
124    ExpiredAccessToken,
125    /// The access token does not have the required scope to access the route.
126    MissingScope(TokenScopeError),
127    /// The route is not available to public.
128    RouteAccessDenied,
129    /// Catch-all used for unrecognized values returned from the server. Encountering this value
130    /// typically indicates that this SDK version is out of date.
131    Other,
132}
133
134impl<'de> ::serde::de::Deserialize<'de> for AuthError {
135    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
136        // union deserializer
137        use serde::de::{self, MapAccess, Visitor};
138        struct EnumVisitor;
139        impl<'de> Visitor<'de> for EnumVisitor {
140            type Value = AuthError;
141            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
142                f.write_str("a AuthError structure")
143            }
144            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
145                let tag: &str = match map.next_key()? {
146                    Some(".tag") => map.next_value()?,
147                    _ => return Err(de::Error::missing_field(".tag"))
148                };
149                let value = match tag {
150                    "invalid_access_token" => AuthError::InvalidAccessToken,
151                    "invalid_select_user" => AuthError::InvalidSelectUser,
152                    "invalid_select_admin" => AuthError::InvalidSelectAdmin,
153                    "user_suspended" => AuthError::UserSuspended,
154                    "expired_access_token" => AuthError::ExpiredAccessToken,
155                    "missing_scope" => AuthError::MissingScope(TokenScopeError::internal_deserialize(&mut map)?),
156                    "route_access_denied" => AuthError::RouteAccessDenied,
157                    _ => AuthError::Other,
158                };
159                crate::eat_json_fields(&mut map)?;
160                Ok(value)
161            }
162        }
163        const VARIANTS: &[&str] = &["invalid_access_token",
164                                    "invalid_select_user",
165                                    "invalid_select_admin",
166                                    "user_suspended",
167                                    "expired_access_token",
168                                    "missing_scope",
169                                    "route_access_denied",
170                                    "other"];
171        deserializer.deserialize_struct("AuthError", VARIANTS, EnumVisitor)
172    }
173}
174
175impl ::serde::ser::Serialize for AuthError {
176    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
177        // union serializer
178        use serde::ser::SerializeStruct;
179        match self {
180            AuthError::InvalidAccessToken => {
181                // unit
182                let mut s = serializer.serialize_struct("AuthError", 1)?;
183                s.serialize_field(".tag", "invalid_access_token")?;
184                s.end()
185            }
186            AuthError::InvalidSelectUser => {
187                // unit
188                let mut s = serializer.serialize_struct("AuthError", 1)?;
189                s.serialize_field(".tag", "invalid_select_user")?;
190                s.end()
191            }
192            AuthError::InvalidSelectAdmin => {
193                // unit
194                let mut s = serializer.serialize_struct("AuthError", 1)?;
195                s.serialize_field(".tag", "invalid_select_admin")?;
196                s.end()
197            }
198            AuthError::UserSuspended => {
199                // unit
200                let mut s = serializer.serialize_struct("AuthError", 1)?;
201                s.serialize_field(".tag", "user_suspended")?;
202                s.end()
203            }
204            AuthError::ExpiredAccessToken => {
205                // unit
206                let mut s = serializer.serialize_struct("AuthError", 1)?;
207                s.serialize_field(".tag", "expired_access_token")?;
208                s.end()
209            }
210            AuthError::MissingScope(x) => {
211                // struct
212                let mut s = serializer.serialize_struct("AuthError", 2)?;
213                s.serialize_field(".tag", "missing_scope")?;
214                x.internal_serialize::<S>(&mut s)?;
215                s.end()
216            }
217            AuthError::RouteAccessDenied => {
218                // unit
219                let mut s = serializer.serialize_struct("AuthError", 1)?;
220                s.serialize_field(".tag", "route_access_denied")?;
221                s.end()
222            }
223            AuthError::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
224        }
225    }
226}
227
228impl ::std::error::Error for AuthError {
229}
230
231impl ::std::fmt::Display for AuthError {
232    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
233        match self {
234            AuthError::InvalidAccessToken => f.write_str("The access token is invalid."),
235            AuthError::InvalidSelectUser => f.write_str("The user specified in 'Dropbox-API-Select-User' is no longer on the team."),
236            AuthError::InvalidSelectAdmin => f.write_str("The user specified in 'Dropbox-API-Select-Admin' is not a Dropbox Business team admin."),
237            AuthError::UserSuspended => f.write_str("The user has been suspended."),
238            AuthError::ExpiredAccessToken => f.write_str("The access token has expired."),
239            AuthError::MissingScope(inner) => write!(f, "The access token does not have the required scope to access the route: {:?}", inner),
240            AuthError::RouteAccessDenied => f.write_str("The route is not available to public."),
241            _ => write!(f, "{:?}", *self),
242        }
243    }
244}
245
246#[derive(Debug, Clone, PartialEq, Eq)]
247#[non_exhaustive] // variants may be added in the future
248pub enum InvalidAccountTypeError {
249    /// Current account type doesn't have permission to access this route endpoint.
250    Endpoint,
251    /// Current account type doesn't have permission to access this feature.
252    Feature,
253    /// Catch-all used for unrecognized values returned from the server. Encountering this value
254    /// typically indicates that this SDK version is out of date.
255    Other,
256}
257
258impl<'de> ::serde::de::Deserialize<'de> for InvalidAccountTypeError {
259    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
260        // union deserializer
261        use serde::de::{self, MapAccess, Visitor};
262        struct EnumVisitor;
263        impl<'de> Visitor<'de> for EnumVisitor {
264            type Value = InvalidAccountTypeError;
265            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
266                f.write_str("a InvalidAccountTypeError structure")
267            }
268            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
269                let tag: &str = match map.next_key()? {
270                    Some(".tag") => map.next_value()?,
271                    _ => return Err(de::Error::missing_field(".tag"))
272                };
273                let value = match tag {
274                    "endpoint" => InvalidAccountTypeError::Endpoint,
275                    "feature" => InvalidAccountTypeError::Feature,
276                    _ => InvalidAccountTypeError::Other,
277                };
278                crate::eat_json_fields(&mut map)?;
279                Ok(value)
280            }
281        }
282        const VARIANTS: &[&str] = &["endpoint",
283                                    "feature",
284                                    "other"];
285        deserializer.deserialize_struct("InvalidAccountTypeError", VARIANTS, EnumVisitor)
286    }
287}
288
289impl ::serde::ser::Serialize for InvalidAccountTypeError {
290    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
291        // union serializer
292        use serde::ser::SerializeStruct;
293        match self {
294            InvalidAccountTypeError::Endpoint => {
295                // unit
296                let mut s = serializer.serialize_struct("InvalidAccountTypeError", 1)?;
297                s.serialize_field(".tag", "endpoint")?;
298                s.end()
299            }
300            InvalidAccountTypeError::Feature => {
301                // unit
302                let mut s = serializer.serialize_struct("InvalidAccountTypeError", 1)?;
303                s.serialize_field(".tag", "feature")?;
304                s.end()
305            }
306            InvalidAccountTypeError::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
307        }
308    }
309}
310
311impl ::std::error::Error for InvalidAccountTypeError {
312}
313
314impl ::std::fmt::Display for InvalidAccountTypeError {
315    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
316        match self {
317            InvalidAccountTypeError::Endpoint => f.write_str("Current account type doesn't have permission to access this route endpoint."),
318            InvalidAccountTypeError::Feature => f.write_str("Current account type doesn't have permission to access this feature."),
319            _ => write!(f, "{:?}", *self),
320        }
321    }
322}
323
324#[derive(Debug, Clone, PartialEq, Eq)]
325#[non_exhaustive] // variants may be added in the future
326pub enum PaperAccessError {
327    /// Paper is disabled.
328    PaperDisabled,
329    /// The provided user has not used Paper yet.
330    NotPaperUser,
331    /// Catch-all used for unrecognized values returned from the server. Encountering this value
332    /// typically indicates that this SDK version is out of date.
333    Other,
334}
335
336impl<'de> ::serde::de::Deserialize<'de> for PaperAccessError {
337    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
338        // union deserializer
339        use serde::de::{self, MapAccess, Visitor};
340        struct EnumVisitor;
341        impl<'de> Visitor<'de> for EnumVisitor {
342            type Value = PaperAccessError;
343            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
344                f.write_str("a PaperAccessError structure")
345            }
346            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
347                let tag: &str = match map.next_key()? {
348                    Some(".tag") => map.next_value()?,
349                    _ => return Err(de::Error::missing_field(".tag"))
350                };
351                let value = match tag {
352                    "paper_disabled" => PaperAccessError::PaperDisabled,
353                    "not_paper_user" => PaperAccessError::NotPaperUser,
354                    _ => PaperAccessError::Other,
355                };
356                crate::eat_json_fields(&mut map)?;
357                Ok(value)
358            }
359        }
360        const VARIANTS: &[&str] = &["paper_disabled",
361                                    "not_paper_user",
362                                    "other"];
363        deserializer.deserialize_struct("PaperAccessError", VARIANTS, EnumVisitor)
364    }
365}
366
367impl ::serde::ser::Serialize for PaperAccessError {
368    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
369        // union serializer
370        use serde::ser::SerializeStruct;
371        match self {
372            PaperAccessError::PaperDisabled => {
373                // unit
374                let mut s = serializer.serialize_struct("PaperAccessError", 1)?;
375                s.serialize_field(".tag", "paper_disabled")?;
376                s.end()
377            }
378            PaperAccessError::NotPaperUser => {
379                // unit
380                let mut s = serializer.serialize_struct("PaperAccessError", 1)?;
381                s.serialize_field(".tag", "not_paper_user")?;
382                s.end()
383            }
384            PaperAccessError::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
385        }
386    }
387}
388
389impl ::std::error::Error for PaperAccessError {
390}
391
392impl ::std::fmt::Display for PaperAccessError {
393    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
394        match self {
395            PaperAccessError::PaperDisabled => f.write_str("Paper is disabled."),
396            PaperAccessError::NotPaperUser => f.write_str("The provided user has not used Paper yet."),
397            _ => write!(f, "{:?}", *self),
398        }
399    }
400}
401
402/// Error occurred because the app is being rate limited.
403#[derive(Debug, Clone, PartialEq, Eq)]
404#[non_exhaustive] // structs may have more fields added in the future.
405pub struct RateLimitError {
406    /// The reason why the app is being rate limited.
407    pub reason: RateLimitReason,
408    /// The number of seconds that the app should wait before making another request.
409    pub retry_after: u64,
410}
411
412impl RateLimitError {
413    pub fn new(reason: RateLimitReason) -> Self {
414        RateLimitError {
415            reason,
416            retry_after: 1,
417        }
418    }
419
420    pub fn with_retry_after(mut self, value: u64) -> Self {
421        self.retry_after = value;
422        self
423    }
424}
425
426const RATE_LIMIT_ERROR_FIELDS: &[&str] = &["reason",
427                                           "retry_after"];
428impl RateLimitError {
429    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
430        map: V,
431    ) -> Result<RateLimitError, V::Error> {
432        Self::internal_deserialize_opt(map, false).map(Option::unwrap)
433    }
434
435    pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
436        mut map: V,
437        optional: bool,
438    ) -> Result<Option<RateLimitError>, V::Error> {
439        let mut field_reason = None;
440        let mut field_retry_after = None;
441        let mut nothing = true;
442        while let Some(key) = map.next_key::<&str>()? {
443            nothing = false;
444            match key {
445                "reason" => {
446                    if field_reason.is_some() {
447                        return Err(::serde::de::Error::duplicate_field("reason"));
448                    }
449                    field_reason = Some(map.next_value()?);
450                }
451                "retry_after" => {
452                    if field_retry_after.is_some() {
453                        return Err(::serde::de::Error::duplicate_field("retry_after"));
454                    }
455                    field_retry_after = Some(map.next_value()?);
456                }
457                _ => {
458                    // unknown field allowed and ignored
459                    map.next_value::<::serde_json::Value>()?;
460                }
461            }
462        }
463        if optional && nothing {
464            return Ok(None);
465        }
466        let result = RateLimitError {
467            reason: field_reason.ok_or_else(|| ::serde::de::Error::missing_field("reason"))?,
468            retry_after: field_retry_after.unwrap_or(1),
469        };
470        Ok(Some(result))
471    }
472
473    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
474        &self,
475        s: &mut S::SerializeStruct,
476    ) -> Result<(), S::Error> {
477        use serde::ser::SerializeStruct;
478        s.serialize_field("reason", &self.reason)?;
479        if self.retry_after != 1 {
480            s.serialize_field("retry_after", &self.retry_after)?;
481        }
482        Ok(())
483    }
484}
485
486impl<'de> ::serde::de::Deserialize<'de> for RateLimitError {
487    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
488        // struct deserializer
489        use serde::de::{MapAccess, Visitor};
490        struct StructVisitor;
491        impl<'de> Visitor<'de> for StructVisitor {
492            type Value = RateLimitError;
493            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
494                f.write_str("a RateLimitError struct")
495            }
496            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
497                RateLimitError::internal_deserialize(map)
498            }
499        }
500        deserializer.deserialize_struct("RateLimitError", RATE_LIMIT_ERROR_FIELDS, StructVisitor)
501    }
502}
503
504impl ::serde::ser::Serialize for RateLimitError {
505    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
506        // struct serializer
507        use serde::ser::SerializeStruct;
508        let mut s = serializer.serialize_struct("RateLimitError", 2)?;
509        self.internal_serialize::<S>(&mut s)?;
510        s.end()
511    }
512}
513
514#[derive(Debug, Clone, PartialEq, Eq)]
515#[non_exhaustive] // variants may be added in the future
516pub enum RateLimitReason {
517    /// You are making too many requests in the past few minutes.
518    TooManyRequests,
519    /// There are currently too many write operations happening in the user's Dropbox.
520    TooManyWriteOperations,
521    /// Catch-all used for unrecognized values returned from the server. Encountering this value
522    /// typically indicates that this SDK version is out of date.
523    Other,
524}
525
526impl<'de> ::serde::de::Deserialize<'de> for RateLimitReason {
527    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
528        // union deserializer
529        use serde::de::{self, MapAccess, Visitor};
530        struct EnumVisitor;
531        impl<'de> Visitor<'de> for EnumVisitor {
532            type Value = RateLimitReason;
533            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
534                f.write_str("a RateLimitReason structure")
535            }
536            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
537                let tag: &str = match map.next_key()? {
538                    Some(".tag") => map.next_value()?,
539                    _ => return Err(de::Error::missing_field(".tag"))
540                };
541                let value = match tag {
542                    "too_many_requests" => RateLimitReason::TooManyRequests,
543                    "too_many_write_operations" => RateLimitReason::TooManyWriteOperations,
544                    _ => RateLimitReason::Other,
545                };
546                crate::eat_json_fields(&mut map)?;
547                Ok(value)
548            }
549        }
550        const VARIANTS: &[&str] = &["too_many_requests",
551                                    "too_many_write_operations",
552                                    "other"];
553        deserializer.deserialize_struct("RateLimitReason", VARIANTS, EnumVisitor)
554    }
555}
556
557impl ::serde::ser::Serialize for RateLimitReason {
558    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
559        // union serializer
560        use serde::ser::SerializeStruct;
561        match self {
562            RateLimitReason::TooManyRequests => {
563                // unit
564                let mut s = serializer.serialize_struct("RateLimitReason", 1)?;
565                s.serialize_field(".tag", "too_many_requests")?;
566                s.end()
567            }
568            RateLimitReason::TooManyWriteOperations => {
569                // unit
570                let mut s = serializer.serialize_struct("RateLimitReason", 1)?;
571                s.serialize_field(".tag", "too_many_write_operations")?;
572                s.end()
573            }
574            RateLimitReason::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
575        }
576    }
577}
578
579impl ::std::fmt::Display for RateLimitReason {
580    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
581        match self {
582            RateLimitReason::TooManyRequests => f.write_str("You are making too many requests in the past few minutes."),
583            RateLimitReason::TooManyWriteOperations => f.write_str("There are currently too many write operations happening in the user's Dropbox."),
584            _ => write!(f, "{:?}", *self),
585        }
586    }
587}
588
589#[derive(Debug, Clone, PartialEq, Eq)]
590#[non_exhaustive] // structs may have more fields added in the future.
591pub struct TokenFromOAuth1Arg {
592    /// The supplied OAuth 1.0 access token.
593    pub oauth1_token: String,
594    /// The token secret associated with the supplied access token.
595    pub oauth1_token_secret: String,
596}
597
598impl TokenFromOAuth1Arg {
599    pub fn new(oauth1_token: String, oauth1_token_secret: String) -> Self {
600        TokenFromOAuth1Arg {
601            oauth1_token,
602            oauth1_token_secret,
603        }
604    }
605}
606
607const TOKEN_FROM_O_AUTH1_ARG_FIELDS: &[&str] = &["oauth1_token",
608                                                 "oauth1_token_secret"];
609impl TokenFromOAuth1Arg {
610    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
611        map: V,
612    ) -> Result<TokenFromOAuth1Arg, V::Error> {
613        Self::internal_deserialize_opt(map, false).map(Option::unwrap)
614    }
615
616    pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
617        mut map: V,
618        optional: bool,
619    ) -> Result<Option<TokenFromOAuth1Arg>, V::Error> {
620        let mut field_oauth1_token = None;
621        let mut field_oauth1_token_secret = None;
622        let mut nothing = true;
623        while let Some(key) = map.next_key::<&str>()? {
624            nothing = false;
625            match key {
626                "oauth1_token" => {
627                    if field_oauth1_token.is_some() {
628                        return Err(::serde::de::Error::duplicate_field("oauth1_token"));
629                    }
630                    field_oauth1_token = Some(map.next_value()?);
631                }
632                "oauth1_token_secret" => {
633                    if field_oauth1_token_secret.is_some() {
634                        return Err(::serde::de::Error::duplicate_field("oauth1_token_secret"));
635                    }
636                    field_oauth1_token_secret = Some(map.next_value()?);
637                }
638                _ => {
639                    // unknown field allowed and ignored
640                    map.next_value::<::serde_json::Value>()?;
641                }
642            }
643        }
644        if optional && nothing {
645            return Ok(None);
646        }
647        let result = TokenFromOAuth1Arg {
648            oauth1_token: field_oauth1_token.ok_or_else(|| ::serde::de::Error::missing_field("oauth1_token"))?,
649            oauth1_token_secret: field_oauth1_token_secret.ok_or_else(|| ::serde::de::Error::missing_field("oauth1_token_secret"))?,
650        };
651        Ok(Some(result))
652    }
653
654    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
655        &self,
656        s: &mut S::SerializeStruct,
657    ) -> Result<(), S::Error> {
658        use serde::ser::SerializeStruct;
659        s.serialize_field("oauth1_token", &self.oauth1_token)?;
660        s.serialize_field("oauth1_token_secret", &self.oauth1_token_secret)?;
661        Ok(())
662    }
663}
664
665impl<'de> ::serde::de::Deserialize<'de> for TokenFromOAuth1Arg {
666    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
667        // struct deserializer
668        use serde::de::{MapAccess, Visitor};
669        struct StructVisitor;
670        impl<'de> Visitor<'de> for StructVisitor {
671            type Value = TokenFromOAuth1Arg;
672            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
673                f.write_str("a TokenFromOAuth1Arg struct")
674            }
675            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
676                TokenFromOAuth1Arg::internal_deserialize(map)
677            }
678        }
679        deserializer.deserialize_struct("TokenFromOAuth1Arg", TOKEN_FROM_O_AUTH1_ARG_FIELDS, StructVisitor)
680    }
681}
682
683impl ::serde::ser::Serialize for TokenFromOAuth1Arg {
684    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
685        // struct serializer
686        use serde::ser::SerializeStruct;
687        let mut s = serializer.serialize_struct("TokenFromOAuth1Arg", 2)?;
688        self.internal_serialize::<S>(&mut s)?;
689        s.end()
690    }
691}
692
693#[derive(Debug, Clone, PartialEq, Eq)]
694#[non_exhaustive] // variants may be added in the future
695pub enum TokenFromOAuth1Error {
696    /// Part or all of the OAuth 1.0 access token info is invalid.
697    InvalidOauth1TokenInfo,
698    /// The authorized app does not match the app associated with the supplied access token.
699    AppIdMismatch,
700    /// Catch-all used for unrecognized values returned from the server. Encountering this value
701    /// typically indicates that this SDK version is out of date.
702    Other,
703}
704
705impl<'de> ::serde::de::Deserialize<'de> for TokenFromOAuth1Error {
706    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
707        // union deserializer
708        use serde::de::{self, MapAccess, Visitor};
709        struct EnumVisitor;
710        impl<'de> Visitor<'de> for EnumVisitor {
711            type Value = TokenFromOAuth1Error;
712            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
713                f.write_str("a TokenFromOAuth1Error structure")
714            }
715            fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
716                let tag: &str = match map.next_key()? {
717                    Some(".tag") => map.next_value()?,
718                    _ => return Err(de::Error::missing_field(".tag"))
719                };
720                let value = match tag {
721                    "invalid_oauth1_token_info" => TokenFromOAuth1Error::InvalidOauth1TokenInfo,
722                    "app_id_mismatch" => TokenFromOAuth1Error::AppIdMismatch,
723                    _ => TokenFromOAuth1Error::Other,
724                };
725                crate::eat_json_fields(&mut map)?;
726                Ok(value)
727            }
728        }
729        const VARIANTS: &[&str] = &["invalid_oauth1_token_info",
730                                    "app_id_mismatch",
731                                    "other"];
732        deserializer.deserialize_struct("TokenFromOAuth1Error", VARIANTS, EnumVisitor)
733    }
734}
735
736impl ::serde::ser::Serialize for TokenFromOAuth1Error {
737    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
738        // union serializer
739        use serde::ser::SerializeStruct;
740        match self {
741            TokenFromOAuth1Error::InvalidOauth1TokenInfo => {
742                // unit
743                let mut s = serializer.serialize_struct("TokenFromOAuth1Error", 1)?;
744                s.serialize_field(".tag", "invalid_oauth1_token_info")?;
745                s.end()
746            }
747            TokenFromOAuth1Error::AppIdMismatch => {
748                // unit
749                let mut s = serializer.serialize_struct("TokenFromOAuth1Error", 1)?;
750                s.serialize_field(".tag", "app_id_mismatch")?;
751                s.end()
752            }
753            TokenFromOAuth1Error::Other => Err(::serde::ser::Error::custom("cannot serialize 'Other' variant"))
754        }
755    }
756}
757
758impl ::std::error::Error for TokenFromOAuth1Error {
759}
760
761impl ::std::fmt::Display for TokenFromOAuth1Error {
762    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
763        match self {
764            TokenFromOAuth1Error::InvalidOauth1TokenInfo => f.write_str("Part or all of the OAuth 1.0 access token info is invalid."),
765            TokenFromOAuth1Error::AppIdMismatch => f.write_str("The authorized app does not match the app associated with the supplied access token."),
766            _ => write!(f, "{:?}", *self),
767        }
768    }
769}
770
771#[derive(Debug, Clone, PartialEq, Eq)]
772#[non_exhaustive] // structs may have more fields added in the future.
773pub struct TokenFromOAuth1Result {
774    /// The OAuth 2.0 token generated from the supplied OAuth 1.0 token.
775    pub oauth2_token: String,
776}
777
778impl TokenFromOAuth1Result {
779    pub fn new(oauth2_token: String) -> Self {
780        TokenFromOAuth1Result {
781            oauth2_token,
782        }
783    }
784}
785
786const TOKEN_FROM_O_AUTH1_RESULT_FIELDS: &[&str] = &["oauth2_token"];
787impl TokenFromOAuth1Result {
788    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
789        map: V,
790    ) -> Result<TokenFromOAuth1Result, V::Error> {
791        Self::internal_deserialize_opt(map, false).map(Option::unwrap)
792    }
793
794    pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
795        mut map: V,
796        optional: bool,
797    ) -> Result<Option<TokenFromOAuth1Result>, V::Error> {
798        let mut field_oauth2_token = None;
799        let mut nothing = true;
800        while let Some(key) = map.next_key::<&str>()? {
801            nothing = false;
802            match key {
803                "oauth2_token" => {
804                    if field_oauth2_token.is_some() {
805                        return Err(::serde::de::Error::duplicate_field("oauth2_token"));
806                    }
807                    field_oauth2_token = Some(map.next_value()?);
808                }
809                _ => {
810                    // unknown field allowed and ignored
811                    map.next_value::<::serde_json::Value>()?;
812                }
813            }
814        }
815        if optional && nothing {
816            return Ok(None);
817        }
818        let result = TokenFromOAuth1Result {
819            oauth2_token: field_oauth2_token.ok_or_else(|| ::serde::de::Error::missing_field("oauth2_token"))?,
820        };
821        Ok(Some(result))
822    }
823
824    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
825        &self,
826        s: &mut S::SerializeStruct,
827    ) -> Result<(), S::Error> {
828        use serde::ser::SerializeStruct;
829        s.serialize_field("oauth2_token", &self.oauth2_token)?;
830        Ok(())
831    }
832}
833
834impl<'de> ::serde::de::Deserialize<'de> for TokenFromOAuth1Result {
835    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
836        // struct deserializer
837        use serde::de::{MapAccess, Visitor};
838        struct StructVisitor;
839        impl<'de> Visitor<'de> for StructVisitor {
840            type Value = TokenFromOAuth1Result;
841            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
842                f.write_str("a TokenFromOAuth1Result struct")
843            }
844            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
845                TokenFromOAuth1Result::internal_deserialize(map)
846            }
847        }
848        deserializer.deserialize_struct("TokenFromOAuth1Result", TOKEN_FROM_O_AUTH1_RESULT_FIELDS, StructVisitor)
849    }
850}
851
852impl ::serde::ser::Serialize for TokenFromOAuth1Result {
853    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
854        // struct serializer
855        use serde::ser::SerializeStruct;
856        let mut s = serializer.serialize_struct("TokenFromOAuth1Result", 1)?;
857        self.internal_serialize::<S>(&mut s)?;
858        s.end()
859    }
860}
861
862#[derive(Debug, Clone, PartialEq, Eq)]
863#[non_exhaustive] // structs may have more fields added in the future.
864pub struct TokenScopeError {
865    /// The required scope to access the route.
866    pub required_scope: String,
867}
868
869impl TokenScopeError {
870    pub fn new(required_scope: String) -> Self {
871        TokenScopeError {
872            required_scope,
873        }
874    }
875}
876
877const TOKEN_SCOPE_ERROR_FIELDS: &[&str] = &["required_scope"];
878impl TokenScopeError {
879    pub(crate) fn internal_deserialize<'de, V: ::serde::de::MapAccess<'de>>(
880        map: V,
881    ) -> Result<TokenScopeError, V::Error> {
882        Self::internal_deserialize_opt(map, false).map(Option::unwrap)
883    }
884
885    pub(crate) fn internal_deserialize_opt<'de, V: ::serde::de::MapAccess<'de>>(
886        mut map: V,
887        optional: bool,
888    ) -> Result<Option<TokenScopeError>, V::Error> {
889        let mut field_required_scope = None;
890        let mut nothing = true;
891        while let Some(key) = map.next_key::<&str>()? {
892            nothing = false;
893            match key {
894                "required_scope" => {
895                    if field_required_scope.is_some() {
896                        return Err(::serde::de::Error::duplicate_field("required_scope"));
897                    }
898                    field_required_scope = Some(map.next_value()?);
899                }
900                _ => {
901                    // unknown field allowed and ignored
902                    map.next_value::<::serde_json::Value>()?;
903                }
904            }
905        }
906        if optional && nothing {
907            return Ok(None);
908        }
909        let result = TokenScopeError {
910            required_scope: field_required_scope.ok_or_else(|| ::serde::de::Error::missing_field("required_scope"))?,
911        };
912        Ok(Some(result))
913    }
914
915    pub(crate) fn internal_serialize<S: ::serde::ser::Serializer>(
916        &self,
917        s: &mut S::SerializeStruct,
918    ) -> Result<(), S::Error> {
919        use serde::ser::SerializeStruct;
920        s.serialize_field("required_scope", &self.required_scope)?;
921        Ok(())
922    }
923}
924
925impl<'de> ::serde::de::Deserialize<'de> for TokenScopeError {
926    fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
927        // struct deserializer
928        use serde::de::{MapAccess, Visitor};
929        struct StructVisitor;
930        impl<'de> Visitor<'de> for StructVisitor {
931            type Value = TokenScopeError;
932            fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
933                f.write_str("a TokenScopeError struct")
934            }
935            fn visit_map<V: MapAccess<'de>>(self, map: V) -> Result<Self::Value, V::Error> {
936                TokenScopeError::internal_deserialize(map)
937            }
938        }
939        deserializer.deserialize_struct("TokenScopeError", TOKEN_SCOPE_ERROR_FIELDS, StructVisitor)
940    }
941}
942
943impl ::serde::ser::Serialize for TokenScopeError {
944    fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
945        // struct serializer
946        use serde::ser::SerializeStruct;
947        let mut s = serializer.serialize_struct("TokenScopeError", 1)?;
948        self.internal_serialize::<S>(&mut s)?;
949        s.end()
950    }
951}
952