Crates.io | freemobile-api |
lib.rs | freemobile-api |
version | 0.1.0 |
created_at | 2025-08-24 12:19:45.633013+00 |
updated_at | 2025-08-24 12:19:45.633013+00 |
description | Rust library for FreeMobile SMS API integration with comprehensive emoji support |
homepage | https://github.com/davlgd/send-sms |
repository | https://github.com/davlgd/send-sms |
max_upload_size | |
id | 1808291 |
size | 82,017 |
A modern, efficient, and safe Rust library for FreeMobile SMS API integration. Built with async/await support, comprehensive emoji handling, and production-ready reliability.
Add this to your Cargo.toml
:
[dependencies]
freemobile-api = "0.1.0"
tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] }
use freemobile_api::{FreeMobileClient, Credentials};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create credentials
let credentials = Credentials::new(
"12345678".to_string(), // Your FreeMobile user ID (8 digits)
"your-api-key".to_string() // Your API key from FreeMobile
);
// Initialize client
let client = FreeMobileClient::new(credentials)?;
// Send a message
client.send("Hello from Rust! β
").await?;
println!("Message sent successfully!");
Ok(())
}
use freemobile_api::{FreeMobileClient, Credentials, FreeMobileError};
#[tokio::main]
async fn main() {
let credentials = Credentials::new(
std::env::var("FREEMOBILE_USER").expect("FREEMOBILE_USER not set"),
std::env::var("FREEMOBILE_PASS").expect("FREEMOBILE_PASS not set")
);
let client = FreeMobileClient::new(credentials).unwrap();
// Send with comprehensive error handling
match client.send("π Deployment complete! All tests passed β
").await {
Ok(()) => println!("β
SMS sent successfully"),
Err(FreeMobileError::InvalidCredentials) => {
eprintln!("β Invalid credentials - check your user ID and API key");
}
Err(FreeMobileError::TooManyRequests) => {
eprintln!("β³ Rate limit exceeded - please wait before sending again");
}
Err(FreeMobileError::EmptyMessage) => {
eprintln!("π Message is empty");
}
Err(e) => {
eprintln!("π₯ Unexpected error: {}", e);
}
}
// Preview sanitization without sending
let original = "Hello π world π with β
mixed π± emojis!";
let sanitized = client.sanitize_message(original);
println!("Original: {}", original);
println!("Sanitized: {}", sanitized); // "Hello [] world [] with β
mixed [] emojis!"
}
The library automatically handles emoji compatibility:
let client = FreeMobileClient::new(credentials)?;
// Emojis are automatically sanitized
client.send("Status: β
OK, Performance: β‘ Fast, Issues: π None").await?;
// Actually sends: "Status: β
OK, Performance: β‘ Fast, Issues: [] None"
Long messages are automatically split into chunks:
let long_message = "A".repeat(2000); // 2000 characters
client.send(&long_message).await?;
// Automatically sends as:
// "[1/2] AAAA..." (first 999 chars)
// "[2/2] AAAA..." (remaining chars)
The library provides comprehensive, typed error handling:
use freemobile_api::FreeMobileError;
match client.send("message").await {
Ok(()) => {
// Message sent successfully
}
Err(FreeMobileError::InvalidCredentials) => {
// HTTP 400 - Check user ID and API key
}
Err(FreeMobileError::TooManyRequests) => {
// HTTP 402 - Rate limit exceeded, wait and retry
}
Err(FreeMobileError::AccessDenied) => {
// HTTP 403 - Check FreeMobile subscription status
}
Err(FreeMobileError::ServerError) => {
// HTTP 500 - FreeMobile server error
}
Err(FreeMobileError::HttpError(e)) => {
// Network or HTTP client error
eprintln!("Network error: {}", e);
}
Err(FreeMobileError::EmptyMessage) => {
// Message was empty after trimming
}
Err(e) => {
// Other errors
eprintln!("Error: {}", e);
}
}
export FREEMOBILE_USER="12345678" # Your 8-digit user ID
export FREEMOBILE_PASS="your-api-key" # Your API key
FreeMobileClient
is Send
and Sync
, making it safe to use across async tasks:
use std::sync::Arc;
let client = Arc::new(FreeMobileClient::new(credentials)?);
// Use in multiple async tasks
let client_clone = client.clone();
tokio::spawn(async move {
client_clone.send("Message from task 1").await.unwrap();
});
let client_clone = client.clone();
tokio::spawn(async move {
client_clone.send("Message from task 2").await.unwrap();
});
The library supports 146+ emojis that are compatible with FreeMobile's SMS system:
Symbols: β‘ β
β β οΈ β β€οΈ βοΈ βοΈ βοΈ β β
Numbers: 0οΈβ£ 1οΈβ£ 2οΈβ£ 3οΈβ£ 4οΈβ£ 5οΈβ£ 6οΈβ£ 7οΈβ£ 8οΈβ£ 9οΈβ£
Arrows: β‘οΈ β¬
οΈ β¬οΈ β¬οΈ βοΈ βοΈ βοΈ βοΈ
Shapes: β¬ β¬ βΌοΈ β»οΈ βΎ β½ βͺ β«
All API parameters are configurable through constants in src/constants.rs
:
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.