vylth-flow 0.3.2

Official Rust SDK for Vylth Flow — self-custody crypto payment processing
Documentation
use std::sync::Arc;

use crate::error::FlowResult;
use crate::http::HttpClient;

pub struct TeamService {
    pub(crate) http: Arc<HttpClient>,
}

impl TeamService {
    pub async fn get(&self) -> FlowResult<serde_json::Value> {
        let data = self.http.get("/merchants/me/team", None).await?;
        Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
    }

    pub async fn my_role(&self) -> FlowResult<serde_json::Value> {
        let data = self.http.get("/merchants/me/team/my-role", None).await?;
        Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
    }

    pub async fn invite(&self, email: &str, role: &str) -> FlowResult<serde_json::Value> {
        let body = serde_json::json!({"email": email, "role": role});
        let data = self.http.post("/merchants/me/team/invite", Some(&body)).await?;
        Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
    }

    pub async fn revoke_invite(&self, invite_id: &str) -> FlowResult<serde_json::Value> {
        let data = self.http.post::<()>(&format!("/merchants/me/team/invite/{}/revoke", invite_id), None).await?;
        Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
    }

    pub async fn update_role(&self, member_id: &str, role: &str) -> FlowResult<serde_json::Value> {
        let body = serde_json::json!({"role": role});
        let data = self.http.patch(&format!("/merchants/me/team/{}/role", member_id), Some(&body)).await?;
        Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
    }

    pub async fn remove(&self, member_id: &str) -> FlowResult<()> {
        self.http.delete(&format!("/merchants/me/team/{}", member_id)).await?;
        Ok(())
    }
}