harvest_api/request/
update_estimate.rs

1use serde_json::json;
2use crate::model::*;
3use crate::HarvestClient;
4/**Create this with the associated client method.
5
6That method takes required values as arguments. Set optional values using builder methods on this struct.*/
7pub struct UpdateEstimateRequest<'a> {
8    pub(crate) client: &'a HarvestClient,
9    pub estimate_id: String,
10    pub client_id: Option<i64>,
11    pub number: Option<String>,
12    pub purchase_order: Option<String>,
13    pub tax: Option<f64>,
14    pub tax2: Option<f64>,
15    pub discount: Option<f64>,
16    pub subject: Option<String>,
17    pub notes: Option<String>,
18    pub currency: Option<String>,
19    pub issue_date: Option<String>,
20    pub line_items: Option<Vec<serde_json::Value>>,
21}
22impl<'a> UpdateEstimateRequest<'a> {
23    pub async fn send(self) -> anyhow::Result<Estimate> {
24        let mut r = self
25            .client
26            .client
27            .patch(&format!("/estimates/{estimate_id}", estimate_id = self.estimate_id));
28        if let Some(ref unwrapped) = self.client_id {
29            r = r.push_json(json!({ "client_id" : unwrapped }));
30        }
31        if let Some(ref unwrapped) = self.number {
32            r = r.push_json(json!({ "number" : unwrapped }));
33        }
34        if let Some(ref unwrapped) = self.purchase_order {
35            r = r.push_json(json!({ "purchase_order" : unwrapped }));
36        }
37        if let Some(ref unwrapped) = self.tax {
38            r = r.push_json(json!({ "tax" : unwrapped }));
39        }
40        if let Some(ref unwrapped) = self.tax2 {
41            r = r.push_json(json!({ "tax2" : unwrapped }));
42        }
43        if let Some(ref unwrapped) = self.discount {
44            r = r.push_json(json!({ "discount" : unwrapped }));
45        }
46        if let Some(ref unwrapped) = self.subject {
47            r = r.push_json(json!({ "subject" : unwrapped }));
48        }
49        if let Some(ref unwrapped) = self.notes {
50            r = r.push_json(json!({ "notes" : unwrapped }));
51        }
52        if let Some(ref unwrapped) = self.currency {
53            r = r.push_json(json!({ "currency" : unwrapped }));
54        }
55        if let Some(ref unwrapped) = self.issue_date {
56            r = r.push_json(json!({ "issue_date" : unwrapped }));
57        }
58        if let Some(ref unwrapped) = self.line_items {
59            r = r.push_json(json!({ "line_items" : unwrapped }));
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 client_id(mut self, client_id: i64) -> Self {
72        self.client_id = Some(client_id);
73        self
74    }
75    pub fn number(mut self, number: &str) -> Self {
76        self.number = Some(number.to_owned());
77        self
78    }
79    pub fn purchase_order(mut self, purchase_order: &str) -> Self {
80        self.purchase_order = Some(purchase_order.to_owned());
81        self
82    }
83    pub fn tax(mut self, tax: f64) -> Self {
84        self.tax = Some(tax);
85        self
86    }
87    pub fn tax2(mut self, tax2: f64) -> Self {
88        self.tax2 = Some(tax2);
89        self
90    }
91    pub fn discount(mut self, discount: f64) -> Self {
92        self.discount = Some(discount);
93        self
94    }
95    pub fn subject(mut self, subject: &str) -> Self {
96        self.subject = Some(subject.to_owned());
97        self
98    }
99    pub fn notes(mut self, notes: &str) -> Self {
100        self.notes = Some(notes.to_owned());
101        self
102    }
103    pub fn currency(mut self, currency: &str) -> Self {
104        self.currency = Some(currency.to_owned());
105        self
106    }
107    pub fn issue_date(mut self, issue_date: &str) -> Self {
108        self.issue_date = Some(issue_date.to_owned());
109        self
110    }
111    pub fn line_items(mut self, line_items: Vec<serde_json::Value>) -> Self {
112        self.line_items = Some(line_items);
113        self
114    }
115}