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
// @generated by xtask/generate_services.py — do not edit by hand.
//! `oauth` — typed methods for all 3 API v3 operations
//! in this module.
//!
//! Access via [`Ghl::v3`](crate::Ghl::v3)`().oauth()`. These endpoints send `Version: v3`.
//!
//! Request and response types come from [`ghl_models::v3::oauth`](https://docs.rs/ghl-models/latest/ghl_models/v3/oauth/); every endpoint is also documented in the
//! [`oauth` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/oauth.md).
//!
//! Enable with `features = ["oauth"]`.
#![allow(clippy::too_many_arguments)]
use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v3::oauth as models;
/// Typed access to the `oauth` API v3 surface (3 operations). Obtained via
/// [`Ghl::v3`](crate::Ghl::v3)`().oauth()`.
#[derive(Debug, Clone)]
pub struct OauthService {
pub(crate) client: Ghl,
}
impl OauthService {
pub(crate) fn new(client: Ghl) -> Self {
Self { client }
}
}
/// Query parameters for [`OauthService::get_location_where_app_is_installed`].
#[derive(Debug, Clone, Default)]
pub struct GetLocationWhereAppIsInstalledParams {
/// Max items per page (1-100). Replaces legacy `limit` parameter per AIP-158.
pub page_size: Option<f64>,
/// Opaque token returned in a previous response to fetch the next page. Replaces legacy
/// `skip` parameter per AIP-158.
pub page_token: Option<String>,
/// Parameter to search for the installed location by name
pub query: Option<String>,
/// Filters out location which are installed for specified app under the specified
/// company
pub is_installed: Option<bool>,
/// When true, restricts the list to locations the current user has access to (for
/// restricted agency admins and account admins). When false or omitted, no user-based
/// filter is applied for installed list; for backward compatibility, install list
/// (isInstalled=false) is still filtered by user when this param is omitted.
pub restrict_to_user_locations: Option<bool>,
/// Parameter to search by the companyId
/// Required by the API.
pub company_id: String,
/// Parameter to search by the appId
/// Required by the API.
pub app_id: String,
/// VersionId of the app
pub version_id: Option<String>,
/// Filters out locations which are installed for specified app in trial mode
pub on_trial: Option<bool>,
/// Filters out location which are installed for specified app under the specified
/// planId
pub plan_id: Option<String>,
/// locationId
pub location_id: Option<String>,
}
impl GetLocationWhereAppIsInstalledParams {
/// Start from the parameters the API requires.
pub fn new(company_id: impl Into<String>, app_id: impl Into<String>) -> Self {
Self {
company_id: company_id.into(),
app_id: app_id.into(),
..Default::default()
}
}
/// Max items per page (1-100). Replaces legacy `limit` parameter per AIP-158.
pub fn page_size(mut self, v: f64) -> Self {
self.page_size = Some(v);
self
}
/// Opaque token returned in a previous response to fetch the next page. Replaces legacy
/// `skip` parameter per AIP-158.
pub fn page_token(mut self, v: impl Into<String>) -> Self {
self.page_token = Some(v.into());
self
}
/// Parameter to search for the installed location by name
pub fn query(mut self, v: impl Into<String>) -> Self {
self.query = Some(v.into());
self
}
/// Filters out location which are installed for specified app under the specified
/// company
pub fn is_installed(mut self, v: bool) -> Self {
self.is_installed = Some(v);
self
}
/// When true, restricts the list to locations the current user has access to (for
/// restricted agency admins and account admins). When false or omitted, no user-based
/// filter is applied for installed list; for backward compatibility, install list
/// (isInstalled=false) is still filtered by user when this param is omitted.
pub fn restrict_to_user_locations(mut self, v: bool) -> Self {
self.restrict_to_user_locations = Some(v);
self
}
/// VersionId of the app
pub fn version_id(mut self, v: impl Into<String>) -> Self {
self.version_id = Some(v.into());
self
}
/// Filters out locations which are installed for specified app in trial mode
pub fn on_trial(mut self, v: bool) -> Self {
self.on_trial = Some(v);
self
}
/// Filters out location which are installed for specified app under the specified
/// planId
pub fn plan_id(mut self, v: impl Into<String>) -> Self {
self.plan_id = Some(v.into());
self
}
/// locationId
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![
("companyId".into(), self.company_id.clone()),
("appId".into(), self.app_id.clone()),
];
if let Some(v) = &self.page_size {
q.push(("pageSize".into(), v.to_string()));
}
if let Some(v) = &self.page_token {
q.push(("pageToken".into(), v.to_string()));
}
if let Some(v) = &self.query {
q.push(("query".into(), v.to_string()));
}
if let Some(v) = &self.is_installed {
q.push(("isInstalled".into(), v.to_string()));
}
if let Some(v) = &self.restrict_to_user_locations {
q.push(("restrictToUserLocations".into(), v.to_string()));
}
if let Some(v) = &self.version_id {
q.push(("versionId".into(), v.to_string()));
}
if let Some(v) = &self.on_trial {
q.push(("onTrial".into(), v.to_string()));
}
if let Some(v) = &self.plan_id {
q.push(("planId".into(), v.to_string()));
}
if let Some(v) = &self.location_id {
q.push(("locationId".into(), v.to_string()));
}
q
}
}
impl OauthService {
/// Get Location where app is installed
///
/// This API allows you fetch location where app is installed upon
///
/// `GET /oauth/installed-locations`
///
/// Requires scope: `oauth.readonly`.
pub async fn get_location_where_app_is_installed(
&self,
params: &GetLocationWhereAppIsInstalledParams,
) -> Result<models::GetInstalledLocationsV3SuccessfulResponseDto> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
"/oauth/installed-locations",
&query,
None::<&()>,
Some("v3"),
)
.await
}
/// Get Location Access Token from Agency Token
///
/// This API allows you to generate locationAccessToken from AgencyAccessToken
///
/// `POST /oauth/location-token`
///
/// Requires scope: `oauth.write`.
pub async fn get_location_access_token_from_agency_token(
&self,
body: &serde_json::Value,
) -> Result<models::GetLocationAccessTokenV3SuccessfulResponseDto> {
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
"/oauth/location-token",
&query,
Some(body),
Some("v3"),
)
.await
}
/// Get Access Token
///
/// Use Access Tokens to access CRM resources on behalf of an authenticated
/// location/company.
///
/// `POST /oauth/token`
pub async fn get_access_token(
&self,
body: &models::GetAccessTokenBodyDto,
) -> Result<models::GetAccessTokenSuccessfulResponseDto> {
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
"/oauth/token",
&query,
Some(body),
Some("v3"),
)
.await
}
}