infobip-sms-sdk 0.1.0

Async Rust SDK for the Infobip SMS API: send messages, manage scheduled bulks, query delivery reports and logs, fetch inbound SMS, and parse webhook payloads.
Documentation
use reqwest::Method;

use crate::api::{decode_response, ErrorKind};
use crate::client::Client;
use crate::error::Error;
use crate::models::reports::{DeliveryReports, DeliveryReportsQuery};

impl Client {
    /// Fetches a batch of outbound message delivery reports.
    ///
    /// Wraps `GET /sms/3/reports`. Use this when you can't expose a
    /// real-time delivery webhook. **Each report is returned only
    /// once** per call — consume them as they arrive, or set a
    /// `messageId` / `bulkId` filter to make repeated polls
    /// idempotent.
    ///
    /// To filter, pass a [`DeliveryReportsQuery`]; for an unfiltered
    /// fetch, use `&DeliveryReportsQuery::default()`.
    ///
    /// # Errors
    ///
    /// On non-2xx responses, returns
    /// [`Error::Api`].
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use infobip_sms::Client;
    /// use infobip_sms::models::reports::DeliveryReportsQuery;
    ///
    /// # async fn run(client: Client) -> Result<(), infobip_sms::Error> {
    /// let reports = client
    ///     .get_delivery_reports(&DeliveryReportsQuery {
    ///         bulk_id: Some("BULK-ID-123-xyz".into()),
    ///         limit: Some(100),
    ///         ..Default::default()
    ///     })
    ///     .await?;
    ///
    /// for r in reports.results {
    ///     println!("{:?} -> {:?}", r.message_id, r.status);
    /// }
    /// # Ok(()) }
    /// ```
    pub async fn get_delivery_reports(
        &self,
        query: &DeliveryReportsQuery,
    ) -> Result<DeliveryReports, Error> {
        let response = self
            .request(Method::GET, "sms/3/reports")?
            .query(query)
            .send()
            .await?;
        decode_response(response, ErrorKind::Rich).await
    }
}