aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-08-23 20:20:54 +0200
committerHarald Eilertsen <haraldei@anduin.net>2018-08-23 20:20:54 +0200
commitcc8207865b950de54fa3d20ee7b2bb9b29382c67 (patch)
treecc781ce0b9dde97a2901aa984a52f673f8043ad7
parent3604ab3e7b5ae6b7e985b5582d74dd3457088bc4 (diff)
downloadrust-zotapi-cc8207865b950de54fa3d20ee7b2bb9b29382c67.tar.gz
rust-zotapi-cc8207865b950de54fa3d20ee7b2bb9b29382c67.tar.bz2
rust-zotapi-cc8207865b950de54fa3d20ee7b2bb9b29382c67.zip
Add fetching xchans by guid and has too.
-rw-r--r--src/xchan.rs10
-rw-r--r--tests/zotapi.rs28
2 files changed, 38 insertions, 0 deletions
diff --git a/src/xchan.rs b/src/xchan.rs
index 564531a..88b3cb1 100644
--- a/src/xchan.rs
+++ b/src/xchan.rs
@@ -36,6 +36,16 @@ impl<'a> XChanFetcher<'a> {
self
}
+ pub fn by_hash(&mut self, hash: &'a str) -> &mut XChanFetcher<'a> {
+ self.data.insert("hash", hash);
+ self
+ }
+
+ pub fn by_guid(&mut self, guid: &'a str) -> &mut XChanFetcher<'a> {
+ self.data.insert("guid", guid);
+ self
+ }
+
pub fn fetch(&self) -> Result<String, Error> {
self.client.fetch_stream(client::ZOTAPI_XCHAN_PATH, &self.data)
}
diff --git a/tests/zotapi.rs b/tests/zotapi.rs
index ef58171..81210db 100644
--- a/tests/zotapi.rs
+++ b/tests/zotapi.rs
@@ -114,3 +114,31 @@ fn fetch_xchan_by_address() {
let _res = z.xchan().by_address("test@test.com").fetch().unwrap();
m.assert();
}
+
+#[test]
+fn fetch_xchan_by_hash() {
+ let m = mock("GET", "/api/z/1.0/xchan?hash=baffebaff")
+ .match_header("Authorization", Matcher::Regex(r"Basic \w+".into()))
+ .with_status(200)
+ .with_header("content-type", "application/json")
+ .with_body("{}")
+ .create();
+
+ let z = zotapi::client(&format!("http://{}", mockito::SERVER_ADDRESS), "testuser", "test1234");
+ let _res = z.xchan().by_hash("baffebaff").fetch().unwrap();
+ m.assert();
+}
+
+#[test]
+fn fetch_xchan_by_guid() {
+ let m = mock("GET", "/api/z/1.0/xchan?guid=baffebaff-baff-baff")
+ .match_header("Authorization", Matcher::Regex(r"Basic \w+".into()))
+ .with_status(200)
+ .with_header("content-type", "application/json")
+ .with_body("{}")
+ .create();
+
+ let z = zotapi::client(&format!("http://{}", mockito::SERVER_ADDRESS), "testuser", "test1234");
+ let _res = z.xchan().by_guid("baffebaff-baff-baff").fetch().unwrap();
+ m.assert();
+}