use reqwest;
#[allow(unused_imports)]
use serde::{de::Error as _};
use crate::{apis::ResponseContent, models};
#[allow(unused_imports)]
use super::{Error, ContentType};
use dtz_config::Configuration;
fn build_url(config: &Configuration) -> String {
if let Some(base_path) = &config.base_path {
let base = url::Url::parse(base_path).unwrap();
let mut target_url = url::Url::parse(crate::apis::SVC_URL).unwrap();
let _ = target_url.set_scheme(base.scheme());
let _ = target_url.set_port(base.port());
let _ = target_url.set_host(Some(base.host_str().unwrap()));
format!("{target_url}")
} else {
crate::apis::SVC_URL.to_string()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateFeedError {
Status401(models::ErrorMessage),
Status500(models::ErrorMessage),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteFeedError {
Status401(models::ErrorMessage),
Status500(models::ErrorMessage),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DisableFeedError {
Status401(models::ErrorMessage),
Status500(models::ErrorMessage),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DisableServiceError {
Status401(models::ErrorMessage),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DiscoverFeedError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EnableFeedError {
Status401(models::ErrorMessage),
Status500(models::ErrorMessage),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EnableServiceError {
Status401(models::ErrorMessage),
Status500(models::ErrorMessage),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFeedError {
Status401(models::ErrorMessage),
Status404(models::ErrorMessage),
Status500(models::ErrorMessage),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetProfileError {
Status401(models::ErrorMessage),
Status404(models::ErrorMessage),
Status500(models::ErrorMessage),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetStatsError {
Status401(models::ErrorMessage),
Status500(models::ErrorMessage),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListFeedError {
Status401(models::ErrorMessage),
Status500(models::ErrorMessage),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PostProfileError {
Status401(models::ErrorMessage),
Status500(models::ErrorMessage),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateFeedError {
Status401(models::ErrorMessage),
Status500(models::ErrorMessage),
UnknownValue(serde_json::Value),
}
pub async fn create_feed(configuration: &Configuration, feed_request: Option<models::FeedRequest>) -> Result<models::Feed, Error<CreateFeedError>> {
let p_body_feed_request = feed_request;
let uri_str = format!("{}/rss2email/feed", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
req_builder = req_builder.json(&p_body_feed_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Feed`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Feed`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateFeedError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn delete_feed(configuration: &Configuration, feed_id: &str) -> Result<models::FeedResponse, Error<DeleteFeedError>> {
let p_path_feed_id = feed_id;
let uri_str = format!("{}/rss2email/feed/{feed_id}", build_url(configuration), feed_id=crate::apis::urlencode(p_path_feed_id));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FeedResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FeedResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DeleteFeedError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn disable_feed(configuration: &Configuration, feed_id: &str) -> Result<(), Error<DisableFeedError>> {
let p_path_feed_id = feed_id;
let uri_str = format!("{}/rss2email/feed/{feed_id}/disable", build_url(configuration), feed_id=crate::apis::urlencode(p_path_feed_id));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<DisableFeedError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn disable_service(configuration: &Configuration) -> Result<(), Error<DisableServiceError>> {
let uri_str = format!("{}/disable", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<DisableServiceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn discover_feed(configuration: &Configuration, discover_feed_request: Option<models::DiscoverFeedRequest>) -> Result<models::DiscoverFeed200Response, Error<DiscoverFeedError>> {
let p_body_discover_feed_request = discover_feed_request;
let uri_str = format!("{}/rss2email/discover", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
req_builder = req_builder.json(&p_body_discover_feed_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DiscoverFeed200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DiscoverFeed200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DiscoverFeedError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn enable_feed(configuration: &Configuration, feed_id: &str) -> Result<(), Error<EnableFeedError>> {
let p_path_feed_id = feed_id;
let uri_str = format!("{}/rss2email/feed/{feed_id}/enable", build_url(configuration), feed_id=crate::apis::urlencode(p_path_feed_id));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<EnableFeedError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn enable_service(configuration: &Configuration) -> Result<(), Error<EnableServiceError>> {
let uri_str = format!("{}/enable", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<EnableServiceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_feed(configuration: &Configuration, feed_id: &str) -> Result<models::Feed, Error<GetFeedError>> {
let p_path_feed_id = feed_id;
let uri_str = format!("{}/rss2email/feed/{feed_id}", build_url(configuration), feed_id=crate::apis::urlencode(p_path_feed_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Feed`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Feed`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetFeedError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_profile(configuration: &Configuration) -> Result<models::ProfileResponse, Error<GetProfileError>> {
let uri_str = format!("{}/rss2email/profile", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProfileResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ProfileResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetProfileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_stats(configuration: &Configuration) -> Result<models::FeedStatistics, Error<GetStatsError>> {
let uri_str = format!("{}/stats", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FeedStatistics`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FeedStatistics`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetStatsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn list_feed(configuration: &Configuration) -> Result<Vec<models::Feed>, Error<ListFeedError>> {
let uri_str = format!("{}/rss2email/feed", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Feed>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Feed>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListFeedError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn post_profile(configuration: &Configuration, profile: Option<models::Profile>) -> Result<(), Error<PostProfileError>> {
let p_body_profile = profile;
let uri_str = format!("{}/rss2email/profile", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
req_builder = req_builder.json(&p_body_profile);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<PostProfileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn update_feed(configuration: &Configuration, feed_id: &str, feed_request: Option<models::FeedRequest>) -> Result<models::FeedResponse, Error<UpdateFeedError>> {
let p_path_feed_id = feed_id;
let p_body_feed_request = feed_request;
let uri_str = format!("{}/rss2email/feed/{feed_id}", build_url(configuration), feed_id=crate::apis::urlencode(p_path_feed_id));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
req_builder = req_builder.json(&p_body_feed_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FeedResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FeedResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateFeedError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}