pub struct FreeMobileClient { /* private fields */ }
Expand description
FreeMobile SMS API client
This client handles all communication with the FreeMobile API, including message sanitization, chunking, and proper error handling.
§Example
use freemobile_api::{FreeMobileClient, Credentials};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let credentials = Credentials::new(
"12345678".to_string(),
"your-api-key".to_string()
);
let client = FreeMobileClient::new(credentials)?;
client.send("Hello World! ✅").await?;
Ok(())
}
Implementations§
Source§impl FreeMobileClient
impl FreeMobileClient
Sourcepub fn new(credentials: Credentials) -> Result<Self, FreeMobileError>
pub fn new(credentials: Credentials) -> Result<Self, FreeMobileError>
Sourcepub async fn send(&self, message: &str) -> Result<(), FreeMobileError>
pub async fn send(&self, message: &str) -> Result<(), FreeMobileError>
Send an SMS message
This method automatically handles:
- Message sanitization (emoji replacement)
- Message chunking for long texts
- Rate limiting between chunks
§Arguments
message
- The message to send (will be sanitized automatically)
§Errors
FreeMobileError::EmptyMessage
- If message is empty after trimmingFreeMobileError::InvalidCredentials
- If API credentials are rejectedFreeMobileError::TooManyRequests
- If rate limit is exceededFreeMobileError::HttpError
- For network-related errors
§Example
client.send("Hello World! ✅").await?;
Sourcepub async fn send_sanitized(
&self,
sanitized_message: &str,
) -> Result<(), FreeMobileError>
pub async fn send_sanitized( &self, sanitized_message: &str, ) -> Result<(), FreeMobileError>
Send a pre-sanitized message
Use this method if you want to handle sanitization yourself or send a message that has already been processed.
§Arguments
sanitized_message
- Pre-sanitized message content
Sourcepub fn sanitize_message(&self, message: &str) -> String
pub fn sanitize_message(&self, message: &str) -> String
Sanitize a message without sending it
This method applies the same emoji sanitization that would be applied during sending, useful for previewing changes.
§Arguments
message
- Raw message to sanitize
§Returns
The sanitized message with supported emojis preserved and unsupported ones replaced with []
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FreeMobileClient
impl !RefUnwindSafe for FreeMobileClient
impl Send for FreeMobileClient
impl Sync for FreeMobileClient
impl Unpin for FreeMobileClient
impl !UnwindSafe for FreeMobileClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more