apibrasil 1.0.0

SDK oficial Rust da plataforma APIBrasil: WhatsApp, SMS, consultas de CPF/CNPJ, veiculos, CEP, correios, pagamentos PIX/boleto e mais.
Documentation
use serde_json::json;

use crate::core::{urlencode_path, Json, Result};

platform_service! {
    /// Catálogo público da plataforma: APIs, planos, documentações e
    /// servidores. A maioria das rotas é pública (não exige Bearer Token).
    CatalogService
}

impl CatalogService {
    /// Lista/busca as APIs disponíveis: `GET /apis?search=`.
    pub async fn apis(&self, search: Option<&str>) -> Result<Json> {
        match search.filter(|search| !search.is_empty()) {
            Some(search) => {
                self.base
                    .get_query("apis", json!({ "search": search }))
                    .await
            }
            None => self.base.get("apis").await,
        }
    }

    /// Detalha uma API por identificador: `GET /apis/{identifier}`.
    pub async fn api(&self, identifier: &str) -> Result<Json> {
        self.base.get(&format!("apis/{identifier}")).await
    }

    /// Detalha uma API pelo nome: `GET /apis/name/{name}`.
    pub async fn api_by_name(&self, name: &str) -> Result<Json> {
        self.base
            .get(&format!("apis/name/{}", urlencode_path(name)))
            .await
    }

    /// Lista as APIs vinculadas a um device:
    /// `GET /apis/device/{device_token}`.
    pub async fn apis_by_device(&self, device_token: &str) -> Result<Json> {
        self.base.get(&format!("apis/device/{device_token}")).await
    }

    /// Documentação por servidor:
    /// `GET /documentations/server/{server_search}`.
    pub async fn documentations_by_server(&self, server_search: &str) -> Result<Json> {
        self.base
            .get(&format!("documentations/server/{server_search}"))
            .await
    }
}

json_get! {
    CatalogService {
        /// Lista as categorias de APIs: `GET /apis/categories`.
        api_categories => "apis/categories",
        /// Lista as APIs contratadas pelo usuário (autenticado):
        /// `GET /apis/list`.
        my_apis => "apis/list",
        /// Lista os planos disponíveis: `GET /plans`.
        plans => "plans",
        /// Lista as documentações: `GET /documentations`.
        documentations => "documentations",
        /// Lista os servidores disponíveis: `GET /servers`.
        servers => "servers",
        /// Status do gateway: `GET /status`.
        status => "status",
    }
}

json_body! {
    CatalogService {
        /// Resolve a URL de uma action (descoberta dinâmica de
        /// endpoints): `POST /endpoint/url`.
        endpoint_url => post "endpoint/url",
        /// Body esperado por uma action: `POST /endpoint/body`.
        endpoint_body => post "endpoint/body",
    }
}