Skip to main content

Crate smsdev

Crate smsdev 

Source
Expand description

§smsdev

An async Rust SDK for the SMSDev SMS Gateway API.

§Features

MethodDescription
send_smsSend one or many SMS messages (bulk supported)
send_oneConvenience wrapper to send a single SMS
cancelCancel scheduled messages by ID
inboxQuery received (MO) messages
dlrQuery delivery status of sent messages
balanceGet account SMS credit balance
reportFetch a usage summary report by date range

§Quick Start

Add the dependency to your Cargo.toml:

[dependencies]
smsdev = "0.1"
tokio = { version = "1", features = ["full"] }

§Send an SMS

use smsdev::{SmsDev, models::SendSmsRequest};

#[tokio::main]
async fn main() -> smsdev::Result<()> {
    let client = SmsDev::new("YOUR_API_KEY");

    let result = client
        .send_one(SendSmsRequest::new(
            "YOUR_API_KEY",
            5511988887777_u64,
            "Hello from the smsdev Rust SDK!",
        ))
        .await?;

    println!("Message queued with id: {}", result.id);
    Ok(())
}

§Check Account Balance

use smsdev::SmsDev;

#[tokio::main]
async fn main() -> smsdev::Result<()> {
    let client = SmsDev::new("YOUR_API_KEY");
    let balance = client.balance().await?;
    println!("SMS credits: {}", balance.sms_balance);
    Ok(())
}

§Bulk Send

use smsdev::{SmsDev, models::SendSmsRequest};

#[tokio::main]
async fn main() -> smsdev::Result<()> {
    let client = SmsDev::new("YOUR_API_KEY");

    let messages = vec![
        SendSmsRequest::new("YOUR_API_KEY", 5511988887777, "Hi Alice!"),
        SendSmsRequest::new("YOUR_API_KEY", 5521977776666, "Hi Bob!")
            .refer("campaign-123"),
    ];

    let results = client.send_sms(messages).await?;
    for r in results {
        println!("id={} ok={}", r.id, r.is_ok());
    }
    Ok(())
}

§Authentication

All requests are authenticated via an API key (Chave Key) which you can find in your SMSDev account profile. Pass it once when constructing SmsDev; the client attaches it automatically to every request.

Re-exports§

pub use error::Result;
pub use error::SmsDevError;

Modules§

error
models

Structs§

SmsDev
The primary entry-point for interacting with the SMSDev API.