use std::io::Read;
pub trait HttpClient {
#[allow(clippy::too_many_arguments)]
fn request(
&self,
endpoint: Endpoint,
style: Style,
function: &str,
params: String,
params_type: ParamsType,
body: Option<&[u8]>,
range_start: Option<u64>,
range_end: Option<u64>,
) -> crate::Result<HttpRequestResultRaw>;
}
pub trait NoauthClient: HttpClient {}
pub trait UserAuthClient: HttpClient {}
pub trait TeamAuthClient: HttpClient {}
pub trait AppAuthClient: HttpClient {}
pub struct HttpRequestResultRaw {
pub result_json: String,
pub content_length: Option<u64>,
pub body: Option<Box<dyn Read>>,
}
pub struct HttpRequestResult<T> {
pub result: T,
pub content_length: Option<u64>,
pub body: Option<Box<dyn Read>>,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Endpoint {
Api,
Content,
Notify,
OAuth2,
}
impl Endpoint {
pub fn url(self) -> &'static str {
match self {
Endpoint::Api => "https://api.dropboxapi.com/2/",
Endpoint::Content => "https://content.dropboxapi.com/2/",
Endpoint::Notify => "https://notify.dropboxapi.com/2/",
Endpoint::OAuth2 => "https://api.dropboxapi.com/", }
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Style {
Rpc,
Upload,
Download,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ParamsType {
Json,
Form,
}
impl ParamsType {
pub fn content_type(self) -> &'static str {
match self {
ParamsType::Json => "application/json",
ParamsType::Form => "application/x-www-form-urlencoded",
}
}
}
#[derive(Debug, Clone)]
pub enum TeamSelect {
User(String),
Admin(String),
}
impl TeamSelect {
pub fn header_name(&self) -> &'static str {
match self {
TeamSelect::User(_) => "Dropbox-API-Select-User",
TeamSelect::Admin(_) => "Dropbox-API-Select-Admin",
}
}
}