aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYour Name <you@example.com>2020-05-02 12:11:57 +0200
committerYour Name <you@example.com>2020-05-02 12:11:57 +0200
commitf38b1cf6c5c37ea41d720a76dc928c25e7437546 (patch)
treeb57ee11eaecee214d30544c4b62ebd61a10158c0 /src
parent73f4ff61c4d3dc8c70d048c71bb23651c460c107 (diff)
downloadrust-zotapi-f38b1cf6c5c37ea41d720a76dc928c25e7437546.tar.gz
rust-zotapi-f38b1cf6c5c37ea41d720a76dc928c25e7437546.tar.bz2
rust-zotapi-f38b1cf6c5c37ea41d720a76dc928c25e7437546.zip
xchan: update internal api and parse results into struct.
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs2
-rw-r--r--src/xchan.rs60
2 files changed, 51 insertions, 11 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c363c8e..357591d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,7 +32,7 @@ pub use error::Error;
pub use group::{group, group_members};
pub use item::item;
pub use network_stream::network_stream;
-pub use xchan::xchan;
+pub use xchan::XChan;
#[cfg(test)]
mod tests {
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()?))?)
}
}