diff options
Diffstat (limited to 'src/xchan.rs')
-rw-r--r-- | src/xchan.rs | 54 |
1 files changed, 1 insertions, 53 deletions
diff --git a/src/xchan.rs b/src/xchan.rs index 4544f08..e4f6893 100644 --- a/src/xchan.rs +++ b/src/xchan.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -use crate::{client::Client, error::Error}; +use crate::{error::Error}; use serde::Deserialize; use std::convert::TryFrom; @@ -103,12 +103,6 @@ pub struct XChan { pub deleted: u32, } -impl XChan { - pub fn z<'a>() -> XChanRequest<'a> { - XChanRequest::default() - } -} - impl<'a> TryFrom<&'a str> for XChan { type Error = Error; @@ -116,49 +110,3 @@ impl<'a> TryFrom<&'a str> for XChan { Ok(serde_json::from_str(s)?) } } - -enum XChanRequestSelector<'a> { - Address(&'a str), - Hash(&'a str), - GUID(&'a str), -} - -#[derive(Default)] -pub struct XChanRequest<'a> { - data: Option<XChanRequestSelector<'a>>, -} - -impl<'a> XChanRequest<'a> { - pub fn by_address(&mut self, addr: &'a str) -> &mut XChanRequest<'a> { - self.data = Some(XChanRequestSelector::Address(addr)); - self - } - - pub fn by_hash(&mut self, hash: &'a str) -> &mut XChanRequest<'a> { - self.data = Some(XChanRequestSelector::Hash(hash)); - self - } - - pub fn by_guid(&mut self, guid: &'a str) -> &mut XChanRequest<'a> { - self.data = Some(XChanRequestSelector::GUID(guid)); - self - } - - pub async fn fetch_raw(&self, client: &Client) -> Result<String, Error> { - let mut req = client.get("xchan"); - - if let Some(sel) = &self.data { - req = match sel { - XChanRequestSelector::Address(s) => req.query(&[("address", s.to_string())]), - XChanRequestSelector::Hash(s) => req.query(&[("hash", s.to_string())]), - XChanRequestSelector::GUID(s) => req.query(&[("guid", s.to_string())]), - }; - } - - Ok(req.send().await?.text().await?) - } - - pub async fn fetch(&self, client: &Client) -> Result<XChan, Error> { - Ok(XChan::try_from(self.fetch_raw(&client).await?.as_str())?) - } -} |