1#![allow(unused_imports)]
2#![cfg_attr(rustfmt, rustfmt_skip)]
3use crate::{Client, ClientBuilder, Credentials, Retry};
5use anyhow::Error;
6use serde_json::Value;
7use std::time::Duration;
8use crate::util::urlencode;
9
10pub struct PurgeCache {
18 pub client: Client
20}
21
22#[allow(non_snake_case)]
23impl PurgeCache {
24 pub fn new<CB: Into<ClientBuilder>>(client_builder: CB) -> Result<Self, Error> {
26 Ok(Self{
27 client: client_builder
28 .into()
29 .path_prefix("api/purge-cache/v1/")
30 .build()?,
31 })
32 }
33
34 pub async fn ping(&self) -> Result<(), Error> {
39 let method = "GET";
40 let (path, query) = Self::ping_details();
41 let body = None;
42 let resp = self.client.request(method, path, query, body).await?;
43 resp.bytes().await?;
44 Ok(())
45 }
46
47 pub fn ping_url(&self) -> Result<String, Error> {
49 let (path, query) = Self::ping_details();
50 self.client.make_url(path, query)
51 }
52
53 pub fn ping_signed_url(&self, ttl: Duration) -> Result<String, Error> {
55 let (path, query) = Self::ping_details();
56 self.client.make_signed_url(path, query, ttl)
57 }
58
59 fn ping_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
61 let path = "ping";
62 let query = None;
63
64 (path, query)
65 }
66
67 pub async fn lbheartbeat(&self) -> Result<(), Error> {
72 let method = "GET";
73 let (path, query) = Self::lbheartbeat_details();
74 let body = None;
75 let resp = self.client.request(method, path, query, body).await?;
76 resp.bytes().await?;
77 Ok(())
78 }
79
80 pub fn lbheartbeat_url(&self) -> Result<String, Error> {
82 let (path, query) = Self::lbheartbeat_details();
83 self.client.make_url(path, query)
84 }
85
86 pub fn lbheartbeat_signed_url(&self, ttl: Duration) -> Result<String, Error> {
88 let (path, query) = Self::lbheartbeat_details();
89 self.client.make_signed_url(path, query, ttl)
90 }
91
92 fn lbheartbeat_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
94 let path = "__lbheartbeat__";
95 let query = None;
96
97 (path, query)
98 }
99
100 pub async fn version(&self) -> Result<(), Error> {
105 let method = "GET";
106 let (path, query) = Self::version_details();
107 let body = None;
108 let resp = self.client.request(method, path, query, body).await?;
109 resp.bytes().await?;
110 Ok(())
111 }
112
113 pub fn version_url(&self) -> Result<String, Error> {
115 let (path, query) = Self::version_details();
116 self.client.make_url(path, query)
117 }
118
119 pub fn version_signed_url(&self, ttl: Duration) -> Result<String, Error> {
121 let (path, query) = Self::version_details();
122 self.client.make_signed_url(path, query, ttl)
123 }
124
125 fn version_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
127 let path = "__version__";
128 let query = None;
129
130 (path, query)
131 }
132
133 pub async fn purgeCache(&self, workerPoolId: &str, payload: &Value) -> Result<(), Error> {
141 let method = "POST";
142 let (path, query) = Self::purgeCache_details(workerPoolId);
143 let body = Some(payload);
144 let resp = self.client.request(method, &path, query, body).await?;
145 resp.bytes().await?;
146 Ok(())
147 }
148
149 fn purgeCache_details<'a>(workerPoolId: &'a str) -> (String, Option<Vec<(&'static str, &'a str)>>) {
151 let path = format!("purge-cache/{}", urlencode(workerPoolId));
152 let query = None;
153
154 (path, query)
155 }
156
157 pub async fn allPurgeRequests(&self, continuationToken: Option<&str>, limit: Option<&str>) -> Result<Value, Error> {
167 let method = "GET";
168 let (path, query) = Self::allPurgeRequests_details(continuationToken, limit);
169 let body = None;
170 let resp = self.client.request(method, path, query, body).await?;
171 Ok(resp.json().await?)
172 }
173
174 pub fn allPurgeRequests_url(&self, continuationToken: Option<&str>, limit: Option<&str>) -> Result<String, Error> {
176 let (path, query) = Self::allPurgeRequests_details(continuationToken, limit);
177 self.client.make_url(path, query)
178 }
179
180 pub fn allPurgeRequests_signed_url(&self, continuationToken: Option<&str>, limit: Option<&str>, ttl: Duration) -> Result<String, Error> {
182 let (path, query) = Self::allPurgeRequests_details(continuationToken, limit);
183 self.client.make_signed_url(path, query, ttl)
184 }
185
186 fn allPurgeRequests_details<'a>(continuationToken: Option<&'a str>, limit: Option<&'a str>) -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
188 let path = "purge-cache/list";
189 let mut query = None;
190 if let Some(q) = continuationToken {
191 query.get_or_insert_with(Vec::new).push(("continuationToken", q));
192 }
193 if let Some(q) = limit {
194 query.get_or_insert_with(Vec::new).push(("limit", q));
195 }
196
197 (path, query)
198 }
199
200 pub async fn purgeRequests(&self, workerPoolId: &str, since: Option<&str>) -> Result<Value, Error> {
207 let method = "GET";
208 let (path, query) = Self::purgeRequests_details(workerPoolId, since);
209 let body = None;
210 let resp = self.client.request(method, &path, query, body).await?;
211 Ok(resp.json().await?)
212 }
213
214 pub fn purgeRequests_url(&self, workerPoolId: &str, since: Option<&str>) -> Result<String, Error> {
216 let (path, query) = Self::purgeRequests_details(workerPoolId, since);
217 self.client.make_url(&path, query)
218 }
219
220 pub fn purgeRequests_signed_url(&self, workerPoolId: &str, since: Option<&str>, ttl: Duration) -> Result<String, Error> {
222 let (path, query) = Self::purgeRequests_details(workerPoolId, since);
223 self.client.make_signed_url(&path, query, ttl)
224 }
225
226 fn purgeRequests_details<'a>(workerPoolId: &'a str, since: Option<&'a str>) -> (String, Option<Vec<(&'static str, &'a str)>>) {
228 let path = format!("purge-cache/{}", urlencode(workerPoolId));
229 let mut query = None;
230 if let Some(q) = since {
231 query.get_or_insert_with(Vec::new).push(("since", q));
232 }
233
234 (path, query)
235 }
236
237 pub async fn heartbeat(&self) -> Result<(), Error> {
244 let method = "GET";
245 let (path, query) = Self::heartbeat_details();
246 let body = None;
247 let resp = self.client.request(method, path, query, body).await?;
248 resp.bytes().await?;
249 Ok(())
250 }
251
252 pub fn heartbeat_url(&self) -> Result<String, Error> {
254 let (path, query) = Self::heartbeat_details();
255 self.client.make_url(path, query)
256 }
257
258 pub fn heartbeat_signed_url(&self, ttl: Duration) -> Result<String, Error> {
260 let (path, query) = Self::heartbeat_details();
261 self.client.make_signed_url(path, query, ttl)
262 }
263
264 fn heartbeat_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
266 let path = "__heartbeat__";
267 let query = None;
268
269 (path, query)
270 }
271}