Skip to content

Commit

Permalink
chore: format code
Browse files Browse the repository at this point in the history
Signed-off-by: Lakshya Singh <[email protected]>
  • Loading branch information
king-11 committed Oct 29, 2023
1 parent 9a8f7e2 commit ac3a6f4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 26 deletions.
93 changes: 68 additions & 25 deletions src/integrations.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use serde::{Deserialize, Serialize};

use crate::{ChannelTypeEnum, client::{Response, Client}, error::NovuError};
use crate::{
client::{Client, Response},
error::NovuError,
ChannelTypeEnum,
};

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -18,7 +22,7 @@ pub struct Integration {
pub deleted_at: String,
pub deleted_by: String,
pub primary: bool,
pub conditions: Option<Vec<StepFilter>>
pub conditions: Option<Vec<StepFilter>>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -49,7 +53,7 @@ pub struct Credentials {
pub redirect_url: Option<String>,
pub hmac: Option<bool>,
pub service_account: Option<String>,
pub ip_pool_name: Option<String>
pub ip_pool_name: Option<String>,
}

#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
Expand All @@ -58,7 +62,7 @@ pub struct StepFilter {
is_negated: bool,
step_filter_type: StepFilterType,
value: StepFilterValue,
children: Vec<FieldFilterPart>
children: Vec<FieldFilterPart>,
}

#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -87,7 +91,7 @@ pub struct FieldFilterPart {
pub field: String,
pub value: String,
pub operator: FieldFilterPartOperator,
pub on: FieldFilterPartOn
pub on: FieldFilterPartOn,
}

#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
Expand All @@ -106,14 +110,14 @@ pub enum FieldFilterPartOperator {
NotBetween,
LIKE,
NotLike,
IN
IN,
}

#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FieldFilterPartOn {
SUBSCRIBER,
PAYLOAD
PAYLOAD,
}

#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
Expand All @@ -128,7 +132,7 @@ pub struct CreateIntegrationRequest {
credentials: Option<Credentials>,
active: Option<bool>,
check: Option<bool>,
conditions: Option<Vec<StepFilter>>
conditions: Option<Vec<StepFilter>>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand All @@ -140,7 +144,7 @@ pub struct UpdateIntegrationRequest {
credentials: Option<Credentials>,
active: Option<bool>,
check: Option<bool>,
conditions: Vec<StepFilter>
conditions: Vec<StepFilter>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand All @@ -159,10 +163,7 @@ impl Integrations {
}

pub async fn get_integrations(&self) -> Result<Vec<Integration>, NovuError> {
let result: Response<Vec<Integration>> = self
.client
.get("/integrations")
.await?;
let result: Response<Vec<Integration>> = self.client.get("/integrations").await?;

match result {
Response::Success(data) => Ok(data.data),
Expand Down Expand Up @@ -201,28 +202,49 @@ impl Integrations {
match result {
Response::Success(data) => Ok(data.data),
Response::Error(err) => match err.status_code {
401 => Err(NovuError::UnauthorizedError("/integrations/active".to_string())),
401 => Err(NovuError::UnauthorizedError(
"/integrations/active".to_string(),
)),
code => todo!("{}", code),
},
Response::Messages(err) => todo!("{:?}", err),
}
}

pub async fn webhook_support_status(&self, provider_id: u32) -> Result<bool, NovuError> {
let result: Response<bool> = self.client.get(format!("/integrations/webhook/provider/{}/status", provider_id)).await?;
let result: Response<bool> = self
.client
.get(format!(
"/integrations/webhook/provider/{}/status",
provider_id
))
.await?;

match result {
Response::Success(data) => Ok(data.data),
Response::Error(err) => match err.status_code {
401 => Err(NovuError::UnauthorizedError(format!("/integrations/provider/{}/webhook-support", provider_id))),
401 => Err(NovuError::UnauthorizedError(format!(
"/integrations/provider/{}/webhook-support",
provider_id
))),
code => todo!("{}", code),
},
Response::Messages(err) => todo!("{:?}", err),
}
}

pub async fn update_integration(&self, integration_id: u32, update_integration: UpdateIntegrationRequest) -> Result<Integration, NovuError> {
let result: Response<Integration> = self.client.put(format!("/integrations/{}", integration_id), &Some(update_integration)).await?;
pub async fn update_integration(
&self,
integration_id: u32,
update_integration: UpdateIntegrationRequest,
) -> Result<Integration, NovuError> {
let result: Response<Integration> = self
.client
.put(
format!("/integrations/{}", integration_id),
&Some(update_integration),
)
.await?;

match result {
Response::Success(data) => Ok(data.data),
Expand All @@ -239,7 +261,10 @@ impl Integrations {
}

pub async fn delete_integration(&self, integration_id: u32) -> Result<Integration, NovuError> {
let result: Response<Integration> = self.client.delete(format!("/integrations/{}", integration_id)).await?;
let result: Response<Integration> = self
.client
.delete(format!("/integrations/{}", integration_id))
.await?;

match result {
Response::Success(data) => Ok(data.data),
Expand All @@ -251,8 +276,17 @@ impl Integrations {
}
}

pub async fn set_primary_integration(&self, integration_id: u32) -> Result<Integration, NovuError> {
let result: Response<Integration> = self.client.post(format!("/integrations/{}/set-primary", integration_id), None::<&()>).await?;
pub async fn set_primary_integration(
&self,
integration_id: u32,
) -> Result<Integration, NovuError> {
let result: Response<Integration> = self
.client
.post(
format!("/integrations/{}/set-primary", integration_id),
None::<&()>,
)
.await?;

match result {
Response::Success(data) => Ok(data.data),
Expand All @@ -264,16 +298,25 @@ impl Integrations {
}
}

pub async fn get_channel_limit(&self, channel_type: ChannelTypeEnum) -> Result<ChannelTypeLimit, NovuError> {
let result: Response<ChannelTypeLimit> = self.client.get(format!("/integrations/{}/limit", channel_type)).await?;
pub async fn get_channel_limit(
&self,
channel_type: ChannelTypeEnum,
) -> Result<ChannelTypeLimit, NovuError> {
let result: Response<ChannelTypeLimit> = self
.client
.get(format!("/integrations/{}/limit", channel_type))
.await?;

match result {
Response::Success(data) => Ok(data.data),
Response::Error(err) => match err.status_code {
401 => Err(NovuError::UnauthorizedError(format!("/integrations/channel/{}/limit", channel_type))),
401 => Err(NovuError::UnauthorizedError(format!(
"/integrations/channel/{}/limit",
channel_type
))),
code => todo!("{}", code),
},
Response::Messages(err) => todo!("{:?}", err),
}
}
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ pub mod error;
pub mod events;
pub mod feeds;
pub mod inbound_parse;
pub mod integrations;
pub mod layouts;
pub mod messages;
pub mod subscriber;
pub mod utils;
pub mod workflows;
pub mod integrations;

use std::fmt::Display;

Expand Down

0 comments on commit ac3a6f4

Please sign in to comment.