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::conversion::EndTagResponse;

impl Client {
    /// Confirms a conversion for a previously tracked message.
    ///
    /// Wraps `POST /ct/1/log/end/{messageId}`. Pair this with
    /// [`SmsRequestOptions::conversion_tracking`][1] on the original
    /// send to mark the recipient as having converted (e.g. clicked
    /// the link and signed up).
    ///
    /// [1]: crate::models::send::SmsRequestOptions::conversion_tracking
    ///
    /// # Errors
    ///
    /// On non-2xx responses, returns
    /// [`Error::Exception`].
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use infobip_sms::Client;
    /// # async fn run(client: Client, message_id: &str) -> Result<(), infobip_sms::Error> {
    /// let result = client.end_conversion_log(message_id).await?;
    /// println!("Process key: {:?}", result.process_key);
    /// # Ok(()) }
    /// ```
    pub async fn end_conversion_log(
        &self,
        message_id: &str,
    ) -> Result<EndTagResponse, Error> {
        let path = format!(
            "ct/1/log/end/{}",
            urlencoding(message_id)
        );
        let response = self.request(Method::POST, &path)?.send().await?;
        decode_response(response, ErrorKind::Legacy).await
    }
}

fn urlencoding(s: &str) -> String {
    url::form_urlencoded::byte_serialize(s.as_bytes()).collect()
}