harvest_api/request/
list_time_entries.rs1use serde_json::json;
2use crate::model::*;
3use crate::HarvestClient;
4pub struct ListTimeEntriesRequest<'a> {
8 pub(crate) client: &'a HarvestClient,
9 pub user_id: Option<i64>,
10 pub client_id: Option<i64>,
11 pub project_id: Option<i64>,
12 pub task_id: Option<i64>,
13 pub external_reference_id: Option<String>,
14 pub is_billed: Option<bool>,
15 pub is_running: Option<bool>,
16 pub updated_since: Option<String>,
17 pub from: Option<String>,
18 pub to: Option<String>,
19 pub page: Option<i64>,
20 pub per_page: Option<i64>,
21}
22impl<'a> ListTimeEntriesRequest<'a> {
23 pub async fn send(self) -> anyhow::Result<TimeEntries> {
24 let mut r = self.client.client.get("/time_entries");
25 if let Some(ref unwrapped) = self.user_id {
26 r = r.push_query("user_id", &unwrapped.to_string());
27 }
28 if let Some(ref unwrapped) = self.client_id {
29 r = r.push_query("client_id", &unwrapped.to_string());
30 }
31 if let Some(ref unwrapped) = self.project_id {
32 r = r.push_query("project_id", &unwrapped.to_string());
33 }
34 if let Some(ref unwrapped) = self.task_id {
35 r = r.push_query("task_id", &unwrapped.to_string());
36 }
37 if let Some(ref unwrapped) = self.external_reference_id {
38 r = r.push_query("external_reference_id", &unwrapped.to_string());
39 }
40 if let Some(ref unwrapped) = self.is_billed {
41 r = r.push_query("is_billed", &unwrapped.to_string());
42 }
43 if let Some(ref unwrapped) = self.is_running {
44 r = r.push_query("is_running", &unwrapped.to_string());
45 }
46 if let Some(ref unwrapped) = self.updated_since {
47 r = r.push_query("updated_since", &unwrapped.to_string());
48 }
49 if let Some(ref unwrapped) = self.from {
50 r = r.push_query("from", &unwrapped.to_string());
51 }
52 if let Some(ref unwrapped) = self.to {
53 r = r.push_query("to", &unwrapped.to_string());
54 }
55 if let Some(ref unwrapped) = self.page {
56 r = r.push_query("page", &unwrapped.to_string());
57 }
58 if let Some(ref unwrapped) = self.per_page {
59 r = r.push_query("per_page", &unwrapped.to_string());
60 }
61 r = self.client.authenticate(r);
62 let res = r.send().await.unwrap().error_for_status();
63 match res {
64 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
65 Err(res) => {
66 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
67 Err(anyhow::anyhow!("{:?}", text))
68 }
69 }
70 }
71 pub fn user_id(mut self, user_id: i64) -> Self {
72 self.user_id = Some(user_id);
73 self
74 }
75 pub fn client_id(mut self, client_id: i64) -> Self {
76 self.client_id = Some(client_id);
77 self
78 }
79 pub fn project_id(mut self, project_id: i64) -> Self {
80 self.project_id = Some(project_id);
81 self
82 }
83 pub fn task_id(mut self, task_id: i64) -> Self {
84 self.task_id = Some(task_id);
85 self
86 }
87 pub fn external_reference_id(mut self, external_reference_id: &str) -> Self {
88 self.external_reference_id = Some(external_reference_id.to_owned());
89 self
90 }
91 pub fn is_billed(mut self, is_billed: bool) -> Self {
92 self.is_billed = Some(is_billed);
93 self
94 }
95 pub fn is_running(mut self, is_running: bool) -> Self {
96 self.is_running = Some(is_running);
97 self
98 }
99 pub fn updated_since(mut self, updated_since: &str) -> Self {
100 self.updated_since = Some(updated_since.to_owned());
101 self
102 }
103 pub fn from(mut self, from: &str) -> Self {
104 self.from = Some(from.to_owned());
105 self
106 }
107 pub fn to(mut self, to: &str) -> Self {
108 self.to = Some(to.to_owned());
109 self
110 }
111 pub fn page(mut self, page: i64) -> Self {
112 self.page = Some(page);
113 self
114 }
115 pub fn per_page(mut self, per_page: i64) -> Self {
116 self.per_page = Some(per_page);
117 self
118 }
119}