aboutsummaryrefslogtreecommitdiffstats
path: root/src/xchan.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/xchan.rs')
-rw-r--r--src/xchan.rs60
1 files changed, 50 insertions, 10 deletions
diff --git a/src/xchan.rs b/src/xchan.rs
index 1a5fadc..994f4b0 100644
--- a/src/xchan.rs
+++ b/src/xchan.rs
@@ -15,25 +15,55 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::{client::Client, error::Error};
-//use serde::{Serialize, Serializer};
-use serde::Serialize;
+use serde::Deserialize;
+
+#[derive(Debug, Default, Deserialize)]
+pub struct XChan {
+ hash: String,
+ guid: String,
+ guid_sig: String,
+ pubkey: String,
+ photo_mimetype: String,
+ photo_l: String,
+ photo_m: String,
+ photo_s: String,
+ addr: String,
+ url: String,
+ connurl: String,
+ follow: String,
+ connpage: String,
+ name: String,
+ network: String,
+ instance_url: String,
+ flags: u32,
+ photo_date: String,
+ name_date: String,
+ hidden: u32,
+ orphan: u32,
+ censored: u32,
+ selfcensored: u32,
+ system: u32,
+ pubforum: u32,
+ deleted: u32,
+}
+
+impl XChan {
+ pub fn z<'a>() -> XChanRequest<'a> {
+ XChanRequest::default()
+ }
+}
-#[derive(Debug, Serialize)]
-#[serde(rename_all = "lowercase")]
enum XChanRequestSelector<'a> {
Address(&'a str),
Hash(&'a str),
GUID(&'a str),
}
+#[derive(Default)]
pub struct XChanRequest<'a> {
data: Option<XChanRequestSelector<'a>>,
}
-pub fn xchan<'a>() -> XChanRequest<'a> {
- XChanRequest { data: None }
-}
-
impl<'a> XChanRequest<'a> {
pub fn by_address(&mut self, addr: &'a str) -> &mut XChanRequest<'a> {
self.data = Some(XChanRequestSelector::Address(addr));
@@ -50,7 +80,17 @@ impl<'a> XChanRequest<'a> {
self
}
- pub fn fetch(&self, client: &Client) -> Result<String, Error> {
- client.fetch_stream("xchan", &self.data.as_ref().unwrap())
+ pub fn fetch(&self, client: &Client) -> Result<XChan, 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(serde_json::from_str(&dbg!(req.send()?.text()?))?)
}
}