Skip to main content

voip_ms/
lib.rs

1//! Async client for the [voip.ms](https://voip.ms) REST API.
2//!
3//! # Quick start
4//!
5//! ```no_run
6//! use voip_ms::{Client, GetBalanceParams, GetBalanceResponse};
7//!
8//! # async fn run() -> voip_ms::Result<()> {
9//! let client = Client::new("you@example.com", "your-api-password");
10//! let balance: GetBalanceResponse = client
11//!     .get_balance(&GetBalanceParams { advanced: Some(true) })
12//!     .await?;
13//! println!("{balance:#?}");
14//! # Ok(()) }
15//! ```
16//!
17//! # Design
18//!
19//! Every voip.ms API method gets a typed `*Params` request struct (with all
20//! fields wrapped in [`Option`] and skipped when `None`) and a method on
21//! [`Client`]. The default method deserializes into a generated `*Response`
22//! struct; each generated method also has a `*_raw` variant that returns
23//! [`serde_json::Value`]. The
24//! crate ships a generated `*Response` struct per method (e.g.
25//! `GetBalanceResponse`, `GetDIDsInfoResponse`) inferred from the official
26//! API documentation's example output, so default calls can deserialize
27//! into a known shape without callers writing their own structs.
28//!
29//! # Authentication
30//!
31//! voip.ms uses an `api_username` (your account email) and an `api_password`
32//! that is **distinct** from your portal password — generate it under the
33//! "SOAP and REST/JSON API" page in the customer portal and allow-list the
34//! IP address you'll be calling from.
35
36mod client;
37mod error;
38mod generated;
39mod responses;
40mod types;
41
42pub use client::{Client, ClientBuilder, DEFAULT_BASE_URL};
43pub use error::{ApiStatus, Error, Result};
44pub use generated::*;
45pub use types::{Routing, RoutingParseError};