termii_rust/
mod.rs

1//! # Termii Rust
2//!
3//! The `termii_rust` crate provides a Rust interface to the Termii messaging platform. It contains handlers for termii's modules like
4//!
5//! - Switch API: Including the Sender ID, Messaging, Number, Templates and Campaign API's
6//! - Token API: Including the Send Token, Verify Token and In-App Token API's.
7//! - Insights API: Including the Balance, Search, Status and History API's.
8//!
9//! The crate provides both blocking and async interfaces to the Termii API. The blocking interface is behind the blocking module likewise
10//! the async interface is behind the async_impl module but is also exported and can be used directly from the root of the crate.
11//!
12//! ## Sending a quick message
13//!
14//! We can use the [`messaging`](async_impl::rest::switch::messaging) module of the Switch api to send messages.
15//!
16//! ```rust
17//! use termii_rust::{
18//!     async_impl::rest::termii,
19//!     common::switch::messaging::{Channel, MessageRequest, MessageType},
20//! };
21//!
22//! let client = termii::Termii::new("Your API key");
23//!
24//! let _message = MessageRequest::new(
25//!     "234XXXXXXXXXX".to_string(),
26//!     "FromYourOrg".to_string(),
27//!     "Hello from Rust Termii. 😎".to_string(),
28//!     MessageType::Plain,
29//!     Channel::Dnd,
30//! );
31//!
32//! let message = client.switch.messaging.send(_message).await;
33//!
34//! println!("{:?}", message);
35//! ```
36//!
37//! ## Sending a one time token
38//!
39//! We can use the [`token`](async_impl::rest::token) module of the Token api to send a one time token.
40//!
41//! ```rust
42//! use termii_rust::{
43//!     async_impl::rest::termii,
44//!     common::token::request::{
45//!         RequestTokenChannel, RequestTokenMessageType, RequestTokenPinType, RequestTokenRequest,
46//!     },
47//! };
48//!
49//! let client = termii::Termii::new("Your API key");
50//!
51//! let payload = RequestTokenRequest::new(
52//!     RequestTokenMessageType::ALPHANUMERIC,
53//!     String::from("234XXXXXXXXXX"),
54//!     String::from("FromYourOrg"),
55//!     RequestTokenChannel::Generic,
56//!     3 as u8,
57//!     50 as usize,
58//!     6 as u8,
59//!     String::from("< 1234 >"),
60//!     String::from("Your pin is < 1234 >"),
61//!     RequestTokenPinType::ALPHANUMERIC,
62//! );
63//!
64//! let response = client.token.request_token.send(otp_payload).await;
65//!
66//! println!("{:#?}", response);
67//! ```
68//!
69//! ## Gets your messaging history.
70//!
71//!
72//! ```rust
73//! use termii_rust::{
74//!     async_impl::rest::termii,
75//!     common::{insights::history::HistoryItem, pagination::PaginatedResourceAsync},
76//! };
77//!
78//! let client = termii::Termii::new("Your API key");
79//! 
80//! let all_history = client.insights.history.all().await;
81//!
82//! println!("{:?}", all_history);
83//! ```
84//!
85//! ## Optional Features
86//!
87//! The crate provides an optional [`blocking`][blocking] module which provides a blocking interface to the Termii API.
88
89#[macro_use]
90pub mod macros;
91
92pub mod common;
93
94pub mod async_impl;
95pub use async_impl::*;
96
97#[cfg(feature = "blocking")]
98pub mod blocking;