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
// @generated by xtask/generate_services.py — do not edit by hand.
//! `marketplace` — typed methods for all 9 API v3 operations
//! in this module.
//!
//! Access via [`Ghl::v3`](crate::Ghl::v3)`().marketplace()`. These endpoints send `Version: v3`.
//!
//! Request and response types come from [`ghl_models::v3::marketplace`](https://docs.rs/ghl-models/latest/ghl_models/v3/marketplace/); every endpoint is also documented in the
//! [`marketplace` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/marketplace.md).
//!
//! Enable with `features = ["marketplace"]`.
#![allow(clippy::too_many_arguments)]
use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v3::marketplace as models;
/// Typed access to the `marketplace` API v3 surface (9 operations). Obtained via
/// [`Ghl::v3`](crate::Ghl::v3)`().marketplace()`.
#[derive(Debug, Clone)]
pub struct MarketplaceService {
pub(crate) client: Ghl,
}
impl MarketplaceService {
pub(crate) fn new(client: Ghl) -> Self {
Self { client }
}
}
/// Query parameters for [`MarketplaceService::get_all_wallet_charges`].
#[derive(Debug, Clone, Default)]
pub struct GetAllWalletChargesParams {
/// Billing Meter ID (you can find this on your app's pricing page on the developer
/// portal)
pub meter_id: Option<String>,
/// Event ID / Transaction ID
pub event_id: Option<String>,
/// Filter results by User ID that your server passed via API when the charge was
/// created
pub user_id: Option<String>,
/// Filter results AFTER a specific date. Use this in combination with endDate to filter
/// results in a specific time window.
pub start_date: Option<String>,
/// Filter results BEFORE a specific date. Use this in combination with startDate to
/// filter results in a specific time window.
pub end_date: Option<String>,
/// Number of records to skip
pub skip: Option<f64>,
/// Maximum number of records to return
pub limit: Option<f64>,
}
impl GetAllWalletChargesParams {
/// Start from the parameters the API requires.
pub fn new() -> Self {
Self {
..Default::default()
}
}
/// Billing Meter ID (you can find this on your app's pricing page on the developer
/// portal)
pub fn meter_id(mut self, v: impl Into<String>) -> Self {
self.meter_id = Some(v.into());
self
}
/// Event ID / Transaction ID
pub fn event_id(mut self, v: impl Into<String>) -> Self {
self.event_id = Some(v.into());
self
}
/// Filter results by User ID that your server passed via API when the charge was
/// created
pub fn user_id(mut self, v: impl Into<String>) -> Self {
self.user_id = Some(v.into());
self
}
/// Filter results AFTER a specific date. Use this in combination with endDate to filter
/// results in a specific time window.
pub fn start_date(mut self, v: impl Into<String>) -> Self {
self.start_date = Some(v.into());
self
}
/// Filter results BEFORE a specific date. Use this in combination with startDate to
/// filter results in a specific time window.
pub fn end_date(mut self, v: impl Into<String>) -> Self {
self.end_date = Some(v.into());
self
}
/// Number of records to skip
pub fn skip(mut self, v: f64) -> Self {
self.skip = Some(v);
self
}
/// Maximum number of records to return
pub fn limit(mut self, v: f64) -> Self {
self.limit = Some(v);
self
}
fn to_query(&self) -> Vec<(String, String)> {
let mut q: Vec<(String, String)> = Vec::new();
if let Some(v) = &self.meter_id {
q.push(("meterId".into(), v.to_string()));
}
if let Some(v) = &self.event_id {
q.push(("eventId".into(), v.to_string()));
}
if let Some(v) = &self.user_id {
q.push(("userId".into(), v.to_string()));
}
if let Some(v) = &self.start_date {
q.push(("startDate".into(), v.to_string()));
}
if let Some(v) = &self.end_date {
q.push(("endDate".into(), v.to_string()));
}
if let Some(v) = &self.skip {
q.push(("skip".into(), v.to_string()));
}
if let Some(v) = &self.limit {
q.push(("limit".into(), v.to_string()));
}
q
}
}
impl MarketplaceService {
/// Uninstall an application
///
/// Uninstalls an application from your company or a specific location. This will remove
/// the application`s access and stop all its functionalities
///
/// `DELETE /marketplace/app/{appId}/installations`
///
/// Requires scope: `oauth.write`.
pub async fn uninstall_an_application(
&self,
app_id: &str,
body: &models::DeleteIntegrationBodyDto,
) -> Result<models::DeleteIntegrationResponse> {
let path = format!(
"/marketplace/app/{}/installations",
crate::services::encode(app_id)
);
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::DELETE,
&path,
&query,
Some(body),
Some("v3"),
)
.await
}
/// Get Installer Details
///
/// Fetches installer details for the authenticated user. This endpoint returns
/// information about the company, location, user, and installation details associated
/// with the current OAuth token.
///
/// `GET /marketplace/app/{appId}/installations`
///
/// Requires scope: `marketplace-installer-details.readonly`.
pub async fn get_installer_details(
&self,
app_id: &str,
) -> Result<models::GetInstallerDetailsResponseDTO> {
let path = format!(
"/marketplace/app/{}/installations",
crate::services::encode(app_id)
);
let query = Vec::new();
self.client
.send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
.await
}
/// Get rebilling config for an app subscription and usage plans
///
/// Get rebilling config for an app subscription and usage plans for the authenticated
/// sub-account. This endpoint returns the subscription and usage plans for an app.
///
/// `GET /marketplace/app/{appId}/rebilling-config/location/{locationId}`
///
/// Requires scope: `oauth.readonly`.
pub async fn get_rebilling_config_for_an_app_subscription_and_usage_plans(
&self,
app_id: &str,
location_id: &str,
) -> Result<models::GetRebillingConfigResponseDTO> {
let path = format!(
"/marketplace/app/{}/rebilling-config/location/{}",
crate::services::encode(app_id),
crate::services::encode(location_id)
);
let query = Vec::new();
self.client
.send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
.await
}
/// Get all wallet charges
///
/// `GET /marketplace/billing/charges`
///
/// Requires scope: `charges.readonly`.
pub async fn get_all_wallet_charges(
&self,
params: &GetAllWalletChargesParams,
) -> Result<serde_json::Value> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
"/marketplace/billing/charges",
&query,
None::<&()>,
Some("v3"),
)
.await
}
/// Create a new wallet charge
///
/// `POST /marketplace/billing/charges`
///
/// Requires scope: `charges.write`.
pub async fn create_a_new_wallet_charge(
&self,
body: &models::RaiseChargeBodyDTO,
) -> Result<serde_json::Value> {
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
"/marketplace/billing/charges",
&query,
Some(body),
Some("v3"),
)
.await
}
/// Check if account has sufficient funds
///
/// `GET /marketplace/billing/charges/has-funds`
///
/// Requires scope: `charges.readonly`.
pub async fn check_if_account_has_sufficient_funds(&self) -> Result<serde_json::Value> {
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::GET,
"/marketplace/billing/charges/has-funds",
&query,
None::<&()>,
Some("v3"),
)
.await
}
/// Delete a wallet charge
///
/// `DELETE /marketplace/billing/charges/{chargeId}`
///
/// Requires scope: `charges.write`.
pub async fn delete_a_wallet_charge(&self, charge_id: &str) -> Result<serde_json::Value> {
let path = format!(
"/marketplace/billing/charges/{}",
crate::services::encode(charge_id)
);
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::DELETE,
&path,
&query,
None::<&()>,
Some("v3"),
)
.await
}
/// Get specific wallet charge details
///
/// `GET /marketplace/billing/charges/{chargeId}`
///
/// Requires scope: `charges.readonly`.
pub async fn get_specific_wallet_charge_details(
&self,
charge_id: &str,
) -> Result<serde_json::Value> {
let path = format!(
"/marketplace/billing/charges/{}",
crate::services::encode(charge_id)
);
let query = Vec::new();
self.client
.send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
.await
}
/// Migrate external authentication connection
///
/// Migrates an external authentication connection credentials (basic or oauth2) for a
/// specific app and location. This endpoint validates the app configuration, stores
/// credentials safely in CRM's native encrypted storage. With this the lifecycle of the
/// token is managed by CRM.
///
/// `POST /marketplace/external-auth/migration`
///
/// Requires scope: `marketplace-external-auth-migration.write`.
pub async fn migrate_external_authentication_connection(
&self,
body: &models::MigrateConnectionDto,
) -> Result<models::MigrateConnectionResponseDto> {
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
"/marketplace/external-auth/migration",
&query,
Some(body),
Some("v3"),
)
.await
}
}