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
// @generated by xtask/generate_services.py — do not edit by hand.
//! `snapshots` — typed methods for all 4 API v2 operations
//! in this module.
//!
//! Access via [`Ghl::snapshots`](crate::Ghl::snapshots).
//!
//! Request and response types come from [`ghl_models::v2::snapshots`](https://docs.rs/ghl-models/latest/ghl_models/v2/snapshots/); every endpoint is also documented in the
//! [`snapshots` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/snapshots.md).
//!
//! Enable with `features = ["snapshots"]`.
#![allow(clippy::too_many_arguments)]
use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v2::snapshots as models;
/// Typed access to the `snapshots` API v2 surface (4 operations). Obtained via
/// [`Ghl::snapshots`](crate::Ghl::snapshots).
#[derive(Debug, Clone)]
pub struct SnapshotsService {
pub(crate) client: Ghl,
}
impl SnapshotsService {
pub(crate) fn new(client: Ghl) -> Self {
Self { client }
}
}
/// Query parameters for [`SnapshotsService::get_snapshots`].
#[derive(Debug, Clone, Default)]
pub struct GetSnapshotsParams {
/// Company Id
/// Required by the API.
pub company_id: String,
}
impl GetSnapshotsParams {
/// Start from the parameters the API requires.
pub fn new(company_id: impl Into<String>) -> Self {
Self {
company_id: company_id.into(),
}
}
fn to_query(&self) -> Vec<(String, String)> {
let q: Vec<(String, String)> = vec![("companyId".into(), self.company_id.clone())];
q
}
}
/// Query parameters for [`SnapshotsService::create_snapshot_share_link`].
#[derive(Debug, Clone, Default)]
pub struct CreateSnapshotShareLinkParams {
/// `companyId` query parameter.
/// Required by the API.
pub company_id: String,
}
impl CreateSnapshotShareLinkParams {
/// Start from the parameters the API requires.
pub fn new(company_id: impl Into<String>) -> Self {
Self {
company_id: company_id.into(),
}
}
fn to_query(&self) -> Vec<(String, String)> {
let q: Vec<(String, String)> = vec![("companyId".into(), self.company_id.clone())];
q
}
}
/// Query parameters for [`SnapshotsService::get_snapshot_push_between_dates`].
#[derive(Debug, Clone, Default)]
pub struct GetSnapshotPushBetweenDatesParams {
/// `companyId` query parameter.
/// Required by the API.
pub company_id: String,
/// `from` query parameter.
/// Required by the API.
pub from_: String,
/// `to` query parameter.
/// Required by the API.
pub to: String,
/// Id for last document till what you want to skip
/// Required by the API.
pub last_doc: String,
/// `limit` query parameter.
/// Required by the API.
pub limit: String,
}
impl GetSnapshotPushBetweenDatesParams {
/// Start from the parameters the API requires.
pub fn new(
company_id: impl Into<String>,
from_: impl Into<String>,
to: impl Into<String>,
last_doc: impl Into<String>,
limit: impl Into<String>,
) -> Self {
Self {
company_id: company_id.into(),
from_: from_.into(),
to: to.into(),
last_doc: last_doc.into(),
limit: limit.into(),
}
}
fn to_query(&self) -> Vec<(String, String)> {
let q: Vec<(String, String)> = vec![
("companyId".into(), self.company_id.clone()),
("from".into(), self.from_.clone()),
("to".into(), self.to.clone()),
("lastDoc".into(), self.last_doc.clone()),
("limit".into(), self.limit.clone()),
];
q
}
}
/// Query parameters for [`SnapshotsService::get_last_snapshot_push`].
#[derive(Debug, Clone, Default)]
pub struct GetLastSnapshotPushParams {
/// `companyId` query parameter.
/// Required by the API.
pub company_id: String,
}
impl GetLastSnapshotPushParams {
/// Start from the parameters the API requires.
pub fn new(company_id: impl Into<String>) -> Self {
Self {
company_id: company_id.into(),
}
}
fn to_query(&self) -> Vec<(String, String)> {
let q: Vec<(String, String)> = vec![("companyId".into(), self.company_id.clone())];
q
}
}
impl SnapshotsService {
/// Get Snapshots
///
/// Get a list of all own and imported Snapshots
///
/// `GET /snapshots/`
pub async fn get_snapshots(
&self,
params: &GetSnapshotsParams,
) -> Result<models::GetSnapshotsSuccessfulResponseDto> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
"/snapshots/",
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Create Snapshot Share Link
///
/// Create a share link for snapshot
///
/// `POST /snapshots/share/link`
pub async fn create_snapshot_share_link(
&self,
params: &CreateSnapshotShareLinkParams,
body: &models::CreateSnapshotShareLinkRequestDTO,
) -> Result<models::CreateSnapshotShareLinkSuccessfulResponseDTO> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::POST,
"/snapshots/share/link",
&query,
Some(body),
Some("2021-07-28"),
)
.await
}
/// Get Snapshot Push between Dates
///
/// Get list of sub-accounts snapshot pushed in time period
///
/// `GET /snapshots/snapshot-status/{snapshotId}`
pub async fn get_snapshot_push_between_dates(
&self,
snapshot_id: &str,
params: &GetSnapshotPushBetweenDatesParams,
) -> Result<models::GetSnapshotPushStatusSuccessfulResponseDTO> {
let path = format!(
"/snapshots/snapshot-status/{}",
crate::services::encode(snapshot_id)
);
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
&path,
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Get Last Snapshot Push
///
/// Get Latest Snapshot Push Status for a location id
///
/// `GET /snapshots/snapshot-status/{snapshotId}/location/{locationId}`
pub async fn get_last_snapshot_push(
&self,
snapshot_id: &str,
location_id: &str,
params: &GetLastSnapshotPushParams,
) -> Result<models::GetLatestSnapshotPushStatusSuccessfulResponseDTO> {
let path = format!(
"/snapshots/snapshot-status/{}/location/{}",
crate::services::encode(snapshot_id),
crate::services::encode(location_id)
);
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
&path,
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
}