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
use crate::client::{ ApifyClient, ApifyClientResult, ApifyClientError };
use std::marker::PhantomData;
use serde::{Deserialize};
#[derive(Debug, PartialEq)]
pub struct NoContent;
impl NoContent {
pub fn new() -> Self {
NoContent {}
}
}
#[derive(Deserialize, Debug)]
pub struct PaginationList<T> {
total: u32,
offset: u32,
limit: Option<u32>,
count: u32,
desc: bool,
pub items: Vec<T>
}
pub struct SimpleBuilder <'a, T> {
pub client: &'a ApifyClient,
pub url: String,
pub method: reqwest::Method,
pub body: Option<Vec<u8>>,
pub headers: Option<reqwest::header::HeaderMap>,
pub phantom: PhantomData<T>,
}
impl<'a, T: serde::de::DeserializeOwned> SimpleBuilder<'a, T> {
pub async fn send(&self) -> Result<T, ApifyClientError> {
println!("size of: {}", std::mem::size_of::<T>());
let resp = self.client.retrying_request(&self.url, &self.method, &self.body, &self.headers).await;
match resp {
Err(err) => Err(err),
Ok(resp) => {
let apify_client_result: ApifyClientResult<T> = resp.json().await.unwrap();
return Ok(apify_client_result.data);
}
}
}
}
impl<'a> SimpleBuilder<'a, NoContent> {
pub async fn send(&self) -> Result<NoContent, ApifyClientError> {
let resp = self.client.retrying_request(&self.url, &self.method, &self.body, &self.headers).await;
match resp {
Err(err) => Err(err),
Ok(_) => {
Ok(NoContent::new())
}
}
}
}