use async_trait::async_trait;
#[cfg(feature = "mockall")]
use mockall::automock;
use reqwest;
use std::sync::Arc;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};
use crate::apis::ContentType;
#[cfg_attr(feature = "mockall", automock)]
#[async_trait]
pub trait SubscribersApi: Send + Sync {
async fn bulk_create<'bulk_create_subscribers>(&self, bulk_create_subscribers: models::BulkCreateSubscribers) -> Result<models::BulkResult, Error<BulkCreateError>>;
async fn bulk_update_preferences<'id, 'bulk_preferences>(&self, id: &'id str, bulk_preferences: models::BulkPreferences) -> Result<(), Error<BulkUpdatePreferencesError>>;
async fn create_subscriber<'create_subscriber>(&self, create_subscriber: models::CreateSubscriber) -> Result<models::SubscriberRecord, Error<CreateSubscriberError>>;
async fn delete_subscriber<'id>(&self, id: &'id str) -> Result<(), Error<DeleteSubscriberError>>;
async fn get_subscriber<'id>(&self, id: &'id str) -> Result<models::SubscriberRecord, Error<GetSubscriberError>>;
async fn list_subscriber_subscriptions<'id>(&self, id: &'id str) -> Result<Vec<models::TopicSubscription>, Error<ListSubscriberSubscriptionsError>>;
async fn list_subscribers<'limit, 'offset, 'q, 'filter_by>(&self, limit: Option<i32>, offset: Option<i32>, q: Option<&'q str>, filter_by: Option<&'filter_by str>) -> Result<models::PaginatedSubscriberRecord, Error<ListSubscribersError>>;
async fn mark_all_messages<'id, 'mark_all>(&self, id: &'id str, mark_all: models::MarkAll) -> Result<models::MarkResult, Error<MarkAllMessagesError>>;
async fn mark_messages<'id, 'mark_messages>(&self, id: &'id str, mark_messages: models::MarkMessages) -> Result<models::MarkResult, Error<MarkMessagesError>>;
async fn subscriber_feed<'id, 'limit, 'after, 'before, 'channel, 'read, 'seen>(&self, id: &'id str, limit: Option<i32>, after: Option<&'after str>, before: Option<&'before str>, channel: Option<&'channel str>, read: Option<bool>, seen: Option<bool>) -> Result<models::CursorPaginatedFeedItem, Error<SubscriberFeedError>>;
async fn unseen_count<'id>(&self, id: &'id str) -> Result<models::UnseenCount, Error<UnseenCountError>>;
async fn update_online_status<'id, 'online_status>(&self, id: &'id str, online_status: models::OnlineStatus) -> Result<models::SubscriberRecord, Error<UpdateOnlineStatusError>>;
async fn update_subscriber<'id, 'update_subscriber>(&self, id: &'id str, update_subscriber: models::UpdateSubscriber) -> Result<models::SubscriberRecord, Error<UpdateSubscriberError>>;
}
pub struct SubscribersApiClient {
configuration: Arc<configuration::Configuration>
}
impl SubscribersApiClient {
pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
Self { configuration }
}
}
#[async_trait]
impl SubscribersApi for SubscribersApiClient {
async fn bulk_create<'bulk_create_subscribers>(&self, bulk_create_subscribers: models::BulkCreateSubscribers) -> Result<models::BulkResult, Error<BulkCreateError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/subscribers/bulk/", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&bulk_create_subscribers);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_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::BulkResult`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::BulkResult`")))),
}
} else {
let local_var_entity: Option<BulkCreateError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn bulk_update_preferences<'id, 'bulk_preferences>(&self, id: &'id str, bulk_preferences: models::BulkPreferences) -> Result<(), Error<BulkUpdatePreferencesError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/subscribers/{id}/preferences/bulk/", local_var_configuration.base_path, id=crate::apis::urlencode(id));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&bulk_preferences);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_entity: Option<BulkUpdatePreferencesError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn create_subscriber<'create_subscriber>(&self, create_subscriber: models::CreateSubscriber) -> Result<models::SubscriberRecord, Error<CreateSubscriberError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/subscribers/", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&create_subscriber);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_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::SubscriberRecord`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SubscriberRecord`")))),
}
} else {
let local_var_entity: Option<CreateSubscriberError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn delete_subscriber<'id>(&self, id: &'id str) -> Result<(), Error<DeleteSubscriberError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/subscribers/{id}/", local_var_configuration.base_path, id=crate::apis::urlencode(id));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_entity: Option<DeleteSubscriberError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn get_subscriber<'id>(&self, id: &'id str) -> Result<models::SubscriberRecord, Error<GetSubscriberError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/subscribers/{id}/", local_var_configuration.base_path, id=crate::apis::urlencode(id));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_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::SubscriberRecord`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SubscriberRecord`")))),
}
} else {
let local_var_entity: Option<GetSubscriberError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn list_subscriber_subscriptions<'id>(&self, id: &'id str) -> Result<Vec<models::TopicSubscription>, Error<ListSubscriberSubscriptionsError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/subscribers/{id}/subscriptions/", local_var_configuration.base_path, id=crate::apis::urlencode(id));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_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::TopicSubscription>`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::TopicSubscription>`")))),
}
} else {
let local_var_entity: Option<ListSubscriberSubscriptionsError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn list_subscribers<'limit, 'offset, 'q, 'filter_by>(&self, limit: Option<i32>, offset: Option<i32>, q: Option<&'q str>, filter_by: Option<&'filter_by str>) -> Result<models::PaginatedSubscriberRecord, Error<ListSubscribersError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/subscribers/", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref param_value) = limit {
local_var_req_builder = local_var_req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = offset {
local_var_req_builder = local_var_req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = q {
local_var_req_builder = local_var_req_builder.query(&[("q", ¶m_value.to_string())]);
}
if let Some(ref param_value) = filter_by {
local_var_req_builder = local_var_req_builder.query(&[("filter_by", ¶m_value.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_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::PaginatedSubscriberRecord`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::PaginatedSubscriberRecord`")))),
}
} else {
let local_var_entity: Option<ListSubscribersError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn mark_all_messages<'id, 'mark_all>(&self, id: &'id str, mark_all: models::MarkAll) -> Result<models::MarkResult, Error<MarkAllMessagesError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/subscribers/{id}/messages/mark-all/", local_var_configuration.base_path, id=crate::apis::urlencode(id));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&mark_all);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_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::MarkResult`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::MarkResult`")))),
}
} else {
let local_var_entity: Option<MarkAllMessagesError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn mark_messages<'id, 'mark_messages>(&self, id: &'id str, mark_messages: models::MarkMessages) -> Result<models::MarkResult, Error<MarkMessagesError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/subscribers/{id}/messages/mark-as/", local_var_configuration.base_path, id=crate::apis::urlencode(id));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&mark_messages);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_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::MarkResult`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::MarkResult`")))),
}
} else {
let local_var_entity: Option<MarkMessagesError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn subscriber_feed<'id, 'limit, 'after, 'before, 'channel, 'read, 'seen>(&self, id: &'id str, limit: Option<i32>, after: Option<&'after str>, before: Option<&'before str>, channel: Option<&'channel str>, read: Option<bool>, seen: Option<bool>) -> Result<models::CursorPaginatedFeedItem, Error<SubscriberFeedError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/subscribers/{id}/notifications/feed/", local_var_configuration.base_path, id=crate::apis::urlencode(id));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref param_value) = limit {
local_var_req_builder = local_var_req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = after {
local_var_req_builder = local_var_req_builder.query(&[("after", ¶m_value.to_string())]);
}
if let Some(ref param_value) = before {
local_var_req_builder = local_var_req_builder.query(&[("before", ¶m_value.to_string())]);
}
if let Some(ref param_value) = channel {
local_var_req_builder = local_var_req_builder.query(&[("channel", ¶m_value.to_string())]);
}
if let Some(ref param_value) = read {
local_var_req_builder = local_var_req_builder.query(&[("read", ¶m_value.to_string())]);
}
if let Some(ref param_value) = seen {
local_var_req_builder = local_var_req_builder.query(&[("seen", ¶m_value.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_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::CursorPaginatedFeedItem`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::CursorPaginatedFeedItem`")))),
}
} else {
let local_var_entity: Option<SubscriberFeedError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn unseen_count<'id>(&self, id: &'id str) -> Result<models::UnseenCount, Error<UnseenCountError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/subscribers/{id}/notifications/unseen/", local_var_configuration.base_path, id=crate::apis::urlencode(id));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_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::UnseenCount`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::UnseenCount`")))),
}
} else {
let local_var_entity: Option<UnseenCountError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn update_online_status<'id, 'online_status>(&self, id: &'id str, online_status: models::OnlineStatus) -> Result<models::SubscriberRecord, Error<UpdateOnlineStatusError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/subscribers/{id}/online-status/", local_var_configuration.base_path, id=crate::apis::urlencode(id));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&online_status);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_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::SubscriberRecord`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SubscriberRecord`")))),
}
} else {
let local_var_entity: Option<UpdateOnlineStatusError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn update_subscriber<'id, 'update_subscriber>(&self, id: &'id str, update_subscriber: models::UpdateSubscriber) -> Result<models::SubscriberRecord, Error<UpdateSubscriberError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/subscribers/{id}/", local_var_configuration.base_path, id=crate::apis::urlencode(id));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&update_subscriber);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_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::SubscriberRecord`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SubscriberRecord`")))),
}
} else {
let local_var_entity: Option<UpdateSubscriberError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum BulkCreateError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum BulkUpdatePreferencesError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateSubscriberError {
Status409(models::ErrorDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteSubscriberError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSubscriberError {
Status404(models::ErrorDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListSubscriberSubscriptionsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListSubscribersError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum MarkAllMessagesError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum MarkMessagesError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SubscriberFeedError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UnseenCountError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateOnlineStatusError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateSubscriberError {
Status404(models::ErrorDetail),
UnknownValue(serde_json::Value),
}