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
// @generated by xtask/generate_services.py — do not edit by hand.
//! `oauth` — typed methods for all 3 API v2 operations
//! in this module.
//!
//! Access via [`Ghl::oauth`](crate::Ghl::oauth).
//!
//! Request and response types come from [`ghl_models::v2::oauth`](https://docs.rs/ghl-models/latest/ghl_models/v2/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::v2::oauth as models;
/// Typed access to the `oauth` API v2 surface (3 operations). Obtained via
/// [`Ghl::oauth`](crate::Ghl::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 {
/// Parameter to skip the number installed locations
pub skip: Option<String>,
/// Parameter to limit the number installed locations
pub limit: 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>,
/// 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()
}
}
/// Parameter to skip the number installed locations
pub fn skip(mut self, v: impl Into<String>) -> Self {
self.skip = Some(v.into());
self
}
/// Parameter to limit the number installed locations
pub fn limit(mut self, v: impl Into<String>) -> Self {
self.limit = 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
}
/// 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.skip {
q.push(("skip".into(), v.to_string()));
}
if let Some(v) = &self.limit {
q.push(("limit".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.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/installedLocations`
///
/// Requires scope: `oauth.readonly`.
pub async fn get_location_where_app_is_installed(
&self,
params: &GetLocationWhereAppIsInstalledParams,
) -> Result<models::GetInstalledLocationsSuccessfulResponseDto> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
"/oauth/installedLocations",
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Get Location Access Token from Agency Token
///
/// This API allows you to generate locationAccessToken from AgencyAccessToken
///
/// `POST /oauth/locationToken`
///
/// Requires scope: `oauth.write`.
pub async fn get_location_access_token_from_agency_token(
&self,
body: &serde_json::Value,
) -> Result<models::GetLocationAccessTokenSuccessfulResponseDto> {
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
"/oauth/locationToken",
&query,
Some(body),
Some("2021-07-28"),
)
.await
}
/// Get Access Token
///
/// Use Access Tokens to access GoHighLevel resources on behalf of an authenticated
/// location/company.
///
/// `POST /oauth/token`
pub async fn get_access_token(
&self,
body: &serde_json::Value,
) -> Result<models::GetAccessCodeSuccessfulResponseDto> {
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
"/oauth/token",
&query,
Some(body),
None,
)
.await
}
}