1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
// @generated by xtask/generate_services.py — do not edit by hand.
//! `phone-system` — typed methods for all 4 API v2 operations
//! in this module.
//!
//! Access via [`Ghl::phone_system`](crate::Ghl::phone_system).
//!
//! Request and response types come from [`ghl_models::v2::phone_system`](https://docs.rs/ghl-models/latest/ghl_models/v2/phone_system/); every endpoint is also documented in the
//! [`phone-system` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/phone-system.md).
//!
//! Enable with `features = ["phone-system"]`.
#![allow(clippy::too_many_arguments)]
use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v2::phone_system as models;
/// Typed access to the `phone-system` API v2 surface (4 operations). Obtained via
/// [`Ghl::phone_system`](crate::Ghl::phone_system).
#[derive(Debug, Clone)]
pub struct PhoneSystemService {
pub(crate) client: Ghl,
}
impl PhoneSystemService {
pub(crate) fn new(client: Ghl) -> Self {
Self { client }
}
}
/// Query parameters for [`PhoneSystemService::list_number_pools`].
#[derive(Debug, Clone, Default)]
pub struct ListNumberPoolsParams {
/// Location ID to filter pools
pub location_id: Option<String>,
}
impl ListNumberPoolsParams {
/// Start from the parameters the API requires.
pub fn new() -> Self {
Self {
..Default::default()
}
}
/// Location ID to filter pools
pub fn location_id(mut self, v: impl Into<String>) -> Self {
self.location_id = Some(v.into());
self
}
fn to_query(&self) -> Vec<(String, String)> {
let mut q: Vec<(String, String)> = Vec::new();
if let Some(v) = &self.location_id {
q.push(("locationId".into(), v.to_string()));
}
q
}
}
/// Query parameters for [`PhoneSystemService::list_active_numbers`].
#[derive(Debug, Clone, Default)]
pub struct ListActiveNumbersParams {
/// How many resources to return in each list page. The default is 50, and the maximum
/// is 1000.
pub page_size: Option<f64>,
/// The page index for pagination. The default is 0.
pub page: Option<f64>,
/// Filter numbers by phone number pattern. Supports partial matching (e.g., "+91" to
/// find all Indian numbers).
pub search_filter: Option<String>,
/// Whether to exclude numbers that are assigned to number pools. Default is true.
pub skip_number_pool: Option<bool>,
}
impl ListActiveNumbersParams {
/// Start from the parameters the API requires.
pub fn new() -> Self {
Self {
..Default::default()
}
}
/// How many resources to return in each list page. The default is 50, and the maximum
/// is 1000.
pub fn page_size(mut self, v: f64) -> Self {
self.page_size = Some(v);
self
}
/// The page index for pagination. The default is 0.
pub fn page(mut self, v: f64) -> Self {
self.page = Some(v);
self
}
/// Filter numbers by phone number pattern. Supports partial matching (e.g., "+91" to
/// find all Indian numbers).
pub fn search_filter(mut self, v: impl Into<String>) -> Self {
self.search_filter = Some(v.into());
self
}
/// Whether to exclude numbers that are assigned to number pools. Default is true.
pub fn skip_number_pool(mut self, v: bool) -> Self {
self.skip_number_pool = Some(v);
self
}
fn to_query(&self) -> Vec<(String, String)> {
let mut q: Vec<(String, String)> = Vec::new();
if let Some(v) = &self.page_size {
q.push(("pageSize".into(), v.to_string()));
}
if let Some(v) = &self.page {
q.push(("page".into(), v.to_string()));
}
if let Some(v) = &self.search_filter {
q.push(("searchFilter".into(), v.to_string()));
}
if let Some(v) = &self.skip_number_pool {
q.push(("skipNumberPool".into(), v.to_string()));
}
q
}
}
/// Query parameters for [`PhoneSystemService::list_available_phone_numbers`].
#[derive(Debug, Clone, Default)]
pub struct ListAvailablePhoneNumbersParams {
/// ISO 3166-1 alpha-2 country code for which to search available numbers
/// Required by the API.
pub country_code: String,
/// Comma-separated list of phone number types to search for (e.g. local, tollFree,
/// mobile)
pub number_types: Option<String>,
/// Filter numbers that begin with this digit pattern
pub first_part: Option<String>,
/// Filter numbers that end with this digit pattern
pub last_part: Option<String>,
/// Filter numbers that contain this digit pattern anywhere
pub anywhere: Option<String>,
/// Filter for numbers with SMS capability
pub sms_enabled: Option<bool>,
/// Filter for numbers with MMS capability
pub mms_enabled: Option<bool>,
/// Filter for numbers with voice capability
pub voice_enabled: Option<bool>,
}
impl ListAvailablePhoneNumbersParams {
/// Start from the parameters the API requires.
pub fn new(country_code: impl Into<String>) -> Self {
Self {
country_code: country_code.into(),
..Default::default()
}
}
/// Comma-separated list of phone number types to search for (e.g. local, tollFree,
/// mobile)
pub fn number_types(mut self, v: impl Into<String>) -> Self {
self.number_types = Some(v.into());
self
}
/// Filter numbers that begin with this digit pattern
pub fn first_part(mut self, v: impl Into<String>) -> Self {
self.first_part = Some(v.into());
self
}
/// Filter numbers that end with this digit pattern
pub fn last_part(mut self, v: impl Into<String>) -> Self {
self.last_part = Some(v.into());
self
}
/// Filter numbers that contain this digit pattern anywhere
pub fn anywhere(mut self, v: impl Into<String>) -> Self {
self.anywhere = Some(v.into());
self
}
/// Filter for numbers with SMS capability
pub fn sms_enabled(mut self, v: bool) -> Self {
self.sms_enabled = Some(v);
self
}
/// Filter for numbers with MMS capability
pub fn mms_enabled(mut self, v: bool) -> Self {
self.mms_enabled = Some(v);
self
}
/// Filter for numbers with voice capability
pub fn voice_enabled(mut self, v: bool) -> Self {
self.voice_enabled = Some(v);
self
}
fn to_query(&self) -> Vec<(String, String)> {
let mut q: Vec<(String, String)> = vec![("countryCode".into(), self.country_code.clone())];
if let Some(v) = &self.number_types {
q.push(("numberTypes".into(), v.to_string()));
}
if let Some(v) = &self.first_part {
q.push(("firstPart".into(), v.to_string()));
}
if let Some(v) = &self.last_part {
q.push(("lastPart".into(), v.to_string()));
}
if let Some(v) = &self.anywhere {
q.push(("anywhere".into(), v.to_string()));
}
if let Some(v) = &self.sms_enabled {
q.push(("smsEnabled".into(), v.to_string()));
}
if let Some(v) = &self.mms_enabled {
q.push(("mmsEnabled".into(), v.to_string()));
}
if let Some(v) = &self.voice_enabled {
q.push(("voiceEnabled".into(), v.to_string()));
}
q
}
}
impl PhoneSystemService {
/// List Number Pools
///
/// Get list of number pools
///
/// `GET /phone-system/number-pools`
///
/// Requires scope: `numberpools.read`.
pub async fn list_number_pools(
&self,
params: &ListNumberPoolsParams,
) -> Result<serde_json::Value> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
"/phone-system/number-pools",
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// List active numbers
///
/// Retrieve a paginated list of active phone numbers for a specific location. Supports
/// filtering, pagination, and optional exclusion of number pool assignments.
///
/// `GET /phone-system/numbers/location/{locationId}`
///
/// Requires scope: `phonenumbers.read`.
pub async fn list_active_numbers(
&self,
location_id: &str,
params: &ListActiveNumbersParams,
) -> Result<serde_json::Value> {
let path = format!(
"/phone-system/numbers/location/{}",
crate::services::encode(location_id)
);
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
&path,
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// List available phone numbers
///
/// Search for available phone numbers to purchase for a specific location. Supports
/// filtering by number pattern, type, and capabilities.
///
/// `GET /phone-system/numbers/location/{locationId}/available`
///
/// Requires scope: `phonenumbers.read`.
pub async fn list_available_phone_numbers(
&self,
location_id: &str,
params: &ListAvailablePhoneNumbersParams,
) -> Result<models::AvailableNumbersResponseDto> {
let path = format!(
"/phone-system/numbers/location/{}/available",
crate::services::encode(location_id)
);
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
&path,
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Purchase a phone number
///
/// Purchase a phone number for a specific location.
///
/// `POST /phone-system/numbers/location/{locationId}/purchase`
///
/// Requires scope: `phonenumbers.write`.
pub async fn purchase_a_phone_number(
&self,
location_id: &str,
body: &models::PurchasePhoneNumberBodyDto,
) -> Result<models::TwilioAccountResponseDto> {
let path = format!(
"/phone-system/numbers/location/{}/purchase",
crate::services::encode(location_id)
);
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
&path,
&query,
Some(body),
Some("2021-07-28"),
)
.await
}
}