diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2020-02-13 13:19:04 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2020-02-13 13:19:04 +0100 |
commit | da461fc867b7c9211116fe7d0c23afbb96f6aaa4 (patch) | |
tree | 99477046a03775d3da8e409498b7529299750c9c /src | |
parent | 732d289605b72260711357b73ba5fa88921d77fd (diff) | |
download | rust-zotapi-da461fc867b7c9211116fe7d0c23afbb96f6aaa4.tar.gz rust-zotapi-da461fc867b7c9211116fe7d0c23afbb96f6aaa4.tar.bz2 rust-zotapi-da461fc867b7c9211116fe7d0c23afbb96f6aaa4.zip |
Let api access client request object directly.
This simplifies things a bit, as we don't need to buffer query params
and such outside of the request itself.
Diffstat (limited to 'src')
-rw-r--r-- | src/abconfig.rs | 10 | ||||
-rw-r--r-- | src/client.rs | 8 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/abconfig.rs b/src/abconfig.rs index c8af6c5..723747c 100644 --- a/src/abconfig.rs +++ b/src/abconfig.rs @@ -16,8 +16,6 @@ use crate::{client::Client, error::Error}; use serde::Deserialize; -use std::collections::HashMap; -use std::iter::FromIterator; /// A struct for storing a key value pair with a category in /// relation to a contact. Typically used to store permissions @@ -56,9 +54,11 @@ pub struct ABConfigRequest { impl ABConfigRequest { pub fn fetch(&self, client: &Client) -> Result<Vec<ABConfig>, Error> { - let data: HashMap<&str, String> = HashMap::from_iter(vec![("abook_id", self.abook_id.to_string())]); - let body = client.fetch_stream("abconfig", &data)?; - Ok(serde_json::from_str(&body)?) + let mut res = client.get("abconfig") + .query(&[("abook_id", self.abook_id.to_string())]) + .send()?; + + Ok(serde_json::from_str(&res.text()?)?) } } diff --git a/src/client.rs b/src/client.rs index 5381286..7a54825 100644 --- a/src/client.rs +++ b/src/client.rs @@ -118,6 +118,14 @@ impl Client { handle_result(res) } + + /// Return a RequestBuilder object that's set up with the correct + /// path and headers for performing a zot api request. + pub fn get(&self, path: &str) -> reqwest::RequestBuilder { + self.inner.get(&self.url(path, &())) + .header(ACCEPT, "application/json") + .basic_auth(self.user.clone(), Some(self.pw.clone())) + } } // A common function for handling the response after a request. |