Skip to main content

Client

Struct Client 

Source
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

Source

pub fn new(config: ClientConfig) -> Result<Self, Error>

Creates a new API client.

Validates the configuration and initializes the HTTP transport.

Source

pub async fn check_health(&self) -> Result<HealthResponse, Error>

Checks the service health status.

Source

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.

Source

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.

Source

pub async fn get_message_state(&self, id: &str) -> Result<MessageState, Error>

Gets the current state of a message by its ID.

Source

pub async fn cancel_message(&self, id: &str) -> Result<(), Error>

Cancels a pending message by its ID.

Source

pub async fn list_devices(&self) -> Result<Vec<Device>, Error>

Lists all registered devices.

Source

pub async fn delete_device(&self, id: &str) -> Result<(), Error>

Removes a device by its ID.

Source

pub async fn get_settings(&self) -> Result<DeviceSettings, Error>

Gets the current device settings.

Source

pub async fn replace_settings( &self, settings: &DeviceSettings, ) -> Result<DeviceSettings, Error>

Replaces all settings.

Source

pub async fn update_settings( &self, settings: &DeviceSettings, ) -> Result<DeviceSettings, Error>

Partially updates settings.

Source

pub async fn list_webhooks(&self) -> Result<Vec<Webhook>, Error>

Lists all registered webhooks.

Source

pub async fn register_webhook( &self, webhook: &Webhook, ) -> Result<Webhook, Error>

Registers a new webhook.

Source

pub async fn delete_webhook(&self, id: &str) -> Result<(), Error>

Deletes a webhook by its ID.

Source

pub async fn generate_token( &self, request: &TokenRequest, ) -> Result<TokenResponse, Error>

Generates a new JWT token with the specified scopes and TTL.

Source

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.

Source

pub async fn revoke_token(&self, jti: &str) -> Result<(), Error>

Revokes a JWT token by its ID (JTI).

Source

pub async fn refresh_inbox( &self, request: &InboxRefreshRequest, ) -> Result<(), Error>

Requests an inbox refresh to pull new messages from the device.

Source

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.

Source

pub async fn get_logs( &self, from: &DateTime<Utc>, to: &DateTime<Utc>, ) -> Result<Vec<LogEntry>, Error>

Retrieves log entries within a time range.

Source

pub async fn export_inbox( &self, request: &MessagesExportRequest, ) -> Result<(), Error>

Exports inbox messages via webhooks.

Source

pub async fn download_attachment( &self, message_id: &str, part_id: i32, ) -> Result<Vec<u8>, Error>

Downloads a specific MMS attachment by message ID and part ID.

Returns the raw attachment bytes (e.g. image, audio, video).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more