pub struct Client { /* private fields */ }Expand description
Client for the SMSGate API.
Provides methods for all API endpoints including messages, devices, settings, webhooks, authentication, inbox, and logs.
§Example
use android_sms_gateway::{
Client, ClientConfig,
types::{Message, SendOptions, TextMessage},
};
let client = Client::new(
ClientConfig::new().with_token("your-jwt-token")
)?;
// Check service health
let health = client.check_health().await?;
println!("Status: {:?}", health.status);
// Send a text message
let message = Message {
phone_numbers: vec!["+1234567890".into()],
text_message: Some(TextMessage { text: "Hello!".into() }),
..Default::default()
};
let state = client.send(&message, &SendOptions::new()).await?;
println!("Message ID: {}", state.id);Implementations§
Source§impl Client
impl Client
Sourcepub fn new(config: ClientConfig) -> Result<Self, Error>
pub fn new(config: ClientConfig) -> Result<Self, Error>
Creates a new API client.
Validates the configuration and initializes the HTTP transport.
Sourcepub async fn check_health(&self) -> Result<HealthResponse, Error>
pub async fn check_health(&self) -> Result<HealthResponse, Error>
Checks the service health status.
Sourcepub async fn send(
&self,
message: &Message,
options: &SendOptions,
) -> Result<MessageState, Error>
pub async fn send( &self, message: &Message, options: &SendOptions, ) -> Result<MessageState, Error>
Sends a new message.
See SendOptions for available options like skip phone validation
and device active within filter.
Sourcepub async fn list_messages(
&self,
options: &ListMessagesOptions,
) -> Result<(Vec<MessageState>, Option<u64>), Error>
pub async fn list_messages( &self, options: &ListMessagesOptions, ) -> Result<(Vec<MessageState>, Option<u64>), Error>
Lists messages with optional filtering, pagination, and sorting.
Returns a tuple of (messages, total_count). The total count is
read from the X-Total-Count response header. Returns None for
the total when the header is missing or contains an unparseable
value.
Sourcepub async fn get_message_state(&self, id: &str) -> Result<MessageState, Error>
pub async fn get_message_state(&self, id: &str) -> Result<MessageState, Error>
Gets the current state of a message by its ID.
Sourcepub async fn cancel_message(&self, id: &str) -> Result<(), Error>
pub async fn cancel_message(&self, id: &str) -> Result<(), Error>
Cancels a pending message by its ID.
Sourcepub async fn get_settings(&self) -> Result<DeviceSettings, Error>
pub async fn get_settings(&self) -> Result<DeviceSettings, Error>
Gets the current device settings.
Sourcepub async fn replace_settings(
&self,
settings: &DeviceSettings,
) -> Result<DeviceSettings, Error>
pub async fn replace_settings( &self, settings: &DeviceSettings, ) -> Result<DeviceSettings, Error>
Replaces all settings.
Sourcepub async fn update_settings(
&self,
settings: &DeviceSettings,
) -> Result<DeviceSettings, Error>
pub async fn update_settings( &self, settings: &DeviceSettings, ) -> Result<DeviceSettings, Error>
Partially updates settings.
Sourcepub async fn list_webhooks(&self) -> Result<Vec<Webhook>, Error>
pub async fn list_webhooks(&self) -> Result<Vec<Webhook>, Error>
Lists all registered webhooks.
Sourcepub async fn register_webhook(
&self,
webhook: &Webhook,
) -> Result<Webhook, Error>
pub async fn register_webhook( &self, webhook: &Webhook, ) -> Result<Webhook, Error>
Registers a new webhook.
Sourcepub async fn generate_token(
&self,
request: &TokenRequest,
) -> Result<TokenResponse, Error>
pub async fn generate_token( &self, request: &TokenRequest, ) -> Result<TokenResponse, Error>
Generates a new JWT token with the specified scopes and TTL.
Sourcepub async fn refresh_token(
&self,
refresh_token: &str,
) -> Result<TokenResponse, Error>
pub async fn refresh_token( &self, refresh_token: &str, ) -> Result<TokenResponse, Error>
Refreshes an existing JWT token using its refresh token.
The refresh token is sent as a Bearer token in the Authorization header.
Sourcepub async fn revoke_token(&self, jti: &str) -> Result<(), Error>
pub async fn revoke_token(&self, jti: &str) -> Result<(), Error>
Revokes a JWT token by its ID (JTI).
Sourcepub async fn refresh_inbox(
&self,
request: &InboxRefreshRequest,
) -> Result<(), Error>
pub async fn refresh_inbox( &self, request: &InboxRefreshRequest, ) -> Result<(), Error>
Requests an inbox refresh to pull new messages from the device.
Sourcepub async fn list_inbox_messages(
&self,
options: &ListInboxOptions,
) -> Result<(Vec<IncomingMessage>, Option<u64>), Error>
pub async fn list_inbox_messages( &self, options: &ListInboxOptions, ) -> Result<(Vec<IncomingMessage>, Option<u64>), Error>
Lists inbox messages with filtering and pagination.
Returns a tuple of (messages, total_count). Returns None for
the total when the X-Total-Count header is missing or contains
an unparseable value.
Sourcepub async fn get_logs(
&self,
from: &DateTime<Utc>,
to: &DateTime<Utc>,
) -> Result<Vec<LogEntry>, Error>
pub async fn get_logs( &self, from: &DateTime<Utc>, to: &DateTime<Utc>, ) -> Result<Vec<LogEntry>, Error>
Retrieves log entries within a time range.
Sourcepub async fn export_inbox(
&self,
request: &MessagesExportRequest,
) -> Result<(), Error>
pub async fn export_inbox( &self, request: &MessagesExportRequest, ) -> Result<(), Error>
Exports inbox messages via webhooks.