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
// @generated by xtask/generate_services.py — do not edit by hand.
//! `phone-system` — typed methods for all 4 API v3 operations
//! in this module.
//!
//! Access via [`Ghl::v3`](crate::Ghl::v3)`().phone_system()`. These endpoints send `Version: v3`.
//!
//! Request and response types come from [`ghl_models::v3::phone_system`](https://docs.rs/ghl-models/latest/ghl_models/v3/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::v3::phone_system as models;
/// Typed access to the `phone-system` API v3 surface (4 operations). Obtained via
/// [`Ghl::v3`](crate::Ghl::v3)`().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 scope the number pool list
/// Required by the API.
pub location_id: String,
}
impl ListNumberPoolsParams {
/// Start from the parameters the API requires.
pub fn new(location_id: impl Into<String>) -> Self {
Self {
location_id: location_id.into(),
}
}
fn to_query(&self) -> Vec<(String, String)> {
let q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
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. The default is 0.
pub page: Option<f64>,
/// Number search Filter
pub search_filter: Option<String>,
/// When true, exclude numbers assigned to number pools from the list.
pub skip_number_pool: Option<bool>,
/// Include RCS Sender IDs
pub include_rcs_sender_ids: 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. The default is 0.
pub fn page(mut self, v: f64) -> Self {
self.page = Some(v);
self
}
/// Number search Filter
pub fn search_filter(mut self, v: impl Into<String>) -> Self {
self.search_filter = Some(v.into());
self
}
/// When true, exclude numbers assigned to number pools from the list.
pub fn skip_number_pool(mut self, v: bool) -> Self {
self.skip_number_pool = Some(v);
self
}
/// Include RCS Sender IDs
pub fn include_rcs_sender_ids(mut self, v: bool) -> Self {
self.include_rcs_sender_ids = 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()));
}
if let Some(v) = &self.include_rcs_sender_ids {
q.push(("includeRcsSenderIds".into(), v.to_string()));
}
q
}
}
/// Query parameters for [`PhoneSystemService::list_available_phone_numbers`].
#[derive(Debug, Clone, Default)]
pub struct ListAvailablePhoneNumbersParams {
/// firstPart is the beginning of the phone number
/// Required by the API.
pub first_part: String,
/// lastPart is the ending of the phone number
/// Required by the API.
pub last_part: String,
/// anywhere are the numbers required anywhere in phone number
/// Required by the API.
pub anywhere: String,
/// comma separated types of phone number required
/// Required by the API.
pub number_types: String,
/// requested phone numbers should have sms functionality
/// Required by the API.
pub sms_enabled: bool,
/// requested phone numbers should have mms functionality
/// Required by the API.
pub mms_enabled: bool,
/// requested phone numbers should have voice functionality
/// Required by the API.
pub voice_enabled: bool,
/// country for which the phone numbers are being requested
/// Required by the API.
pub country_code: String,
}
impl ListAvailablePhoneNumbersParams {
/// Start from the parameters the API requires.
pub fn new(
first_part: impl Into<String>,
last_part: impl Into<String>,
anywhere: impl Into<String>,
number_types: impl Into<String>,
sms_enabled: bool,
mms_enabled: bool,
voice_enabled: bool,
country_code: impl Into<String>,
) -> Self {
Self {
first_part: first_part.into(),
last_part: last_part.into(),
anywhere: anywhere.into(),
number_types: number_types.into(),
sms_enabled,
mms_enabled,
voice_enabled,
country_code: country_code.into(),
}
}
fn to_query(&self) -> Vec<(String, String)> {
let q: Vec<(String, String)> = vec![
("firstPart".into(), self.first_part.clone()),
("lastPart".into(), self.last_part.clone()),
("anywhere".into(), self.anywhere.clone()),
("numberTypes".into(), self.number_types.clone()),
("smsEnabled".into(), self.sms_enabled.to_string()),
("mmsEnabled".into(), self.mms_enabled.to_string()),
("voiceEnabled".into(), self.voice_enabled.to_string()),
("countryCode".into(), self.country_code.clone()),
];
q
}
}
impl PhoneSystemService {
/// List number pools
///
/// Returns number pools for the location. Requires locationId as a query parameter.
///
/// `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("v3"),
)
.await
}
/// List active numbers
///
/// List active numbers. With `version: v3`, the HTTP 200 body is the standard success
/// envelope (`status`, `data`, `message`, `statusCode`). The v3 list payload is under
/// `data`; `isUnderGhl` is renamed to `isUnderLc` per AIP naming convention.
///
/// `GET /phone-system/numbers/location/{locationId}`
///
/// Requires scope: `phonenumbers.read`.
pub async fn list_active_numbers(
&self,
location_id: &str,
params: &ListActiveNumbersParams,
) -> Result<models::ListNumbersV3Http200ResponseDto> {
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("v3"))
.await
}
/// List available phone numbers
///
/// Search Twilio inventory for purchasable phone numbers in a country for the given
/// location.
///
/// `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<serde_json::Value> {
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("v3"))
.await
}
/// Purchase number for location
///
/// Purchase number for location. With `version: v3`, the HTTP 201 body is the standard
/// success envelope (`status`, `data`, `message`, `statusCode`). The v3 purchase fields
/// live under `data`: `number`, `locationId`, `id`, and `underLcAccount` (renamed from
/// under_ghl_account).
///
/// `POST /phone-system/numbers/location/{locationId}/purchase`
///
/// Requires scope: `phonenumbers.write`.
pub async fn purchase_number_for_location(
&self,
location_id: &str,
body: &models::PurchasePhoneNumberBodyDto,
) -> Result<models::PurchaseNumberForLocationV3Http201ResponseDto> {
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("v3"))
.await
}
}