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
// @generated by xtask/generate_services.py — do not edit by hand.
//! `businesses` — typed methods for all 5 API v2 operations
//! in this module.
//!
//! Access via [`Ghl::businesses`](crate::Ghl::businesses).
//!
//! Request and response types come from [`ghl_models::v2::businesses`](https://docs.rs/ghl-models/latest/ghl_models/v2/businesses/); every endpoint is also documented in the
//! [`businesses` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/businesses.md).
//!
//! Enable with `features = ["businesses"]`.
#![allow(clippy::too_many_arguments)]
use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v2::businesses as models;
/// Typed access to the `businesses` API v2 surface (5 operations). Obtained via
/// [`Ghl::businesses`](crate::Ghl::businesses).
#[derive(Debug, Clone)]
pub struct BusinessesService {
pub(crate) client: Ghl,
}
impl BusinessesService {
pub(crate) fn new(client: Ghl) -> Self {
Self { client }
}
}
/// Query parameters for [`BusinessesService::get_businesses_by_location`].
#[derive(Debug, Clone, Default)]
pub struct GetBusinessesByLocationParams {
/// `locationId` query parameter.
/// Required by the API.
pub location_id: String,
/// `limit` query parameter.
pub limit: Option<String>,
/// `skip` query parameter.
pub skip: Option<String>,
}
impl GetBusinessesByLocationParams {
/// Start from the parameters the API requires.
pub fn new(location_id: impl Into<String>) -> Self {
Self {
location_id: location_id.into(),
..Default::default()
}
}
/// Set the `limit` query parameter.
pub fn limit(mut self, v: impl Into<String>) -> Self {
self.limit = Some(v.into());
self
}
/// Set the `skip` query parameter.
pub fn skip(mut self, v: impl Into<String>) -> Self {
self.skip = Some(v.into());
self
}
fn to_query(&self) -> Vec<(String, String)> {
let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
if let Some(v) = &self.limit {
q.push(("limit".into(), v.to_string()));
}
if let Some(v) = &self.skip {
q.push(("skip".into(), v.to_string()));
}
q
}
}
impl BusinessesService {
/// Get Businesses by Location
///
/// `GET /businesses/`
///
/// Requires scope: `businesses.readonly`.
pub async fn get_businesses_by_location(
&self,
params: &GetBusinessesByLocationParams,
) -> Result<models::GetBusinessByLocationResponseDto> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
"/businesses/",
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Create Business
///
/// `POST /businesses/`
///
/// Requires scope: `businesses.write`.
pub async fn create_business(
&self,
body: &models::CreateBusinessDto,
) -> Result<models::UpdateBusinessResponseDto> {
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
"/businesses/",
&query,
Some(body),
Some("2021-07-28"),
)
.await
}
/// Delete Business
///
/// `DELETE /businesses/{businessId}`
///
/// Requires scope: `businesses.write`.
pub async fn delete_business(
&self,
business_id: &str,
) -> Result<models::DeleteBusinessResponseDto> {
let path = format!("/businesses/{}", crate::services::encode(business_id));
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::DELETE,
&path,
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Get Business
///
/// `GET /businesses/{businessId}`
///
/// Requires scope: `businesses.readonly`.
pub async fn get_business(
&self,
business_id: &str,
) -> Result<models::GetBusinessByIdResponseDto> {
let path = format!("/businesses/{}", crate::services::encode(business_id));
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::GET,
&path,
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Update Business
///
/// `PUT /businesses/{businessId}`
///
/// Requires scope: `businesses.write`.
pub async fn update_business(
&self,
business_id: &str,
body: &models::UpdateBusinessDto,
) -> Result<models::UpdateBusinessResponseDto> {
let path = format!("/businesses/{}", crate::services::encode(business_id));
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::PUT,
&path,
&query,
Some(body),
Some("2021-07-28"),
)
.await
}
}