use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::{client::Sendry, error::Error, DeleteResponse, Page, PaginationParams};
#[derive(Debug, Clone)]
pub struct DedicatedIps {
client: Sendry,
}
impl DedicatedIps {
pub(crate) fn new(client: Sendry) -> Self {
Self { client }
}
pub async fn provision(&self, params: ProvisionDedicatedIp) -> Result<DedicatedIp, Error> {
self.client
.request(
self.client
.build(Method::POST, "/v1/ips", &[], Some(¶ms)),
)
.await
}
pub async fn list(&self, params: PaginationParams) -> Result<Page<DedicatedIp>, Error> {
let q = params.to_query();
self.client
.request(self.client.build::<()>(Method::GET, "/v1/ips", &q, None))
.await
}
pub async fn get(&self, id: &str) -> Result<DedicatedIp, Error> {
self.client
.request(self.client.build::<()>(
Method::GET,
&format!("/v1/ips/{id}"),
&[],
None,
))
.await
}
pub async fn assign(&self, ip_id: &str, params: AssignIp) -> Result<IpAssignment, Error> {
self.client
.request(self.client.build(
Method::POST,
&format!("/v1/ips/{ip_id}/assign"),
&[],
Some(¶ms),
))
.await
}
pub async fn remove_assignment(
&self,
ip_id: &str,
assignment_id: &str,
) -> Result<DeleteResponse, Error> {
self.client
.request(self.client.build::<()>(
Method::DELETE,
&format!("/v1/ips/{ip_id}/assign/{assignment_id}"),
&[],
None,
))
.await
}
pub async fn release(&self, id: &str) -> Result<DeleteResponse, Error> {
self.client
.request(self.client.build::<()>(
Method::DELETE,
&format!("/v1/ips/{id}"),
&[],
None,
))
.await
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct DedicatedIpAssignment {
pub id: String,
pub domain_id: String,
pub domain_name: String,
pub created_at: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct DedicatedIp {
pub id: String,
pub ip_address: String,
pub provider: String,
pub status: String,
pub warmup_day: u32,
pub warmup_progress: f64,
pub pool_name: Option<String>,
#[serde(default)]
pub assignments: Vec<DedicatedIpAssignment>,
pub created_at: String,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct ProvisionDedicatedIp {
#[serde(skip_serializing_if = "Option::is_none")]
pub provider: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct AssignIp {
pub domain_id: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct IpAssignment {
pub id: String,
pub ip_id: String,
pub domain_id: String,
pub created_at: String,
}