dropbox_sdk/
client_trait_common.rs

1//! Types common to the sync and async HTTP clients.
2
3/// A builder for a HTTP request.
4pub trait HttpRequest {
5    /// Set a HTTP header.
6    fn set_header(self, name: &str, value: &str) -> Self;
7}
8
9/// The API base endpoint for a request. Determines which hostname the request should go to.
10#[derive(Debug, Copy, Clone, PartialEq, Eq)]
11pub enum Endpoint {
12    /// The endpoint used for most API calls.
13    Api,
14
15    /// The endpoint primarily used for upload and download calls.
16    Content,
17
18    /// The endpoint primarily used for longpolling calls.
19    Notify,
20
21    /// The endpoint used for OAuth2 token requests.
22    OAuth2,
23}
24
25impl Endpoint {
26    /// The base URL for API calls using the given endpoint.
27    pub fn url(self) -> &'static str {
28        match self {
29            Endpoint::Api => "https://api.dropboxapi.com/2/",
30            Endpoint::Content => "https://content.dropboxapi.com/2/",
31            Endpoint::Notify => "https://notify.dropboxapi.com/2/",
32            Endpoint::OAuth2 => "https://api.dropboxapi.com/", // note no '2/'
33        }
34    }
35}
36
37/// The style of a request, which determines how arguments are passed, and whether there is a
38/// request and/or response body.
39#[derive(Debug, Copy, Clone, PartialEq, Eq)]
40pub enum Style {
41    /// Arguments are passed in the request body; response is in the body; no request or response
42    /// body content stream.
43    Rpc,
44
45    /// Arguments are passed in a HTTP header; response is in the body; request body is the upload
46    /// content; no response body content stream.
47    Upload,
48
49    /// Arguments are passed in a HTTP header; response is in a HTTP header; no request content
50    /// body; response body contains the content stream.
51    Download,
52}
53
54/// The format of arguments being sent in a request.
55#[derive(Debug, Copy, Clone, PartialEq, Eq)]
56pub enum ParamsType {
57    /// JSON.
58    Json,
59
60    /// WWW Form URL-encoded. Only used for OAuth2 requests.
61    Form,
62}
63
64impl ParamsType {
65    /// The value for the HTTP Content-Type header for the given params format.
66    pub fn content_type(self) -> &'static str {
67        match self {
68            ParamsType::Json => "application/json",
69            ParamsType::Form => "application/x-www-form-urlencoded",
70        }
71    }
72}
73
74/// Used with Team Authentication to select a user context within that team.
75#[derive(Debug, Clone)]
76pub enum TeamSelect {
77    /// A team member's user ID.
78    User(String),
79
80    /// A team admin's user ID, which grants additional access.
81    Admin(String),
82}
83
84impl TeamSelect {
85    /// The name of the HTTP header that must be set.
86    pub fn header_name(&self) -> &'static str {
87        match self {
88            TeamSelect::User(_) => "Dropbox-API-Select-User",
89            TeamSelect::Admin(_) => "Dropbox-API-Select-Admin",
90        }
91    }
92}