aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-01-03 23:42:37 +0100
committerHarald Eilertsen <haraldei@anduin.net>2020-01-03 23:42:37 +0100
commit970df3ea4169eb2fe935a0f50012503079b8636d (patch)
tree4b339e01e957ecf63e7a0d9a67ceabc77496e3d3
parent0c76f0c9727a512475e29b5d099b5b7188f72052 (diff)
downloadrust-zotapi-970df3ea4169eb2fe935a0f50012503079b8636d.tar.gz
rust-zotapi-970df3ea4169eb2fe935a0f50012503079b8636d.tar.bz2
rust-zotapi-970df3ea4169eb2fe935a0f50012503079b8636d.zip
Make channel and network stream behave like the rest.
-rw-r--r--examples/zot/channel_stream.rs2
-rw-r--r--examples/zot/network_stream.rs2
-rw-r--r--src/channel_stream.rs33
-rw-r--r--src/client.rs8
-rw-r--r--src/lib.rs4
-rw-r--r--src/network_stream.rs33
-rw-r--r--tests/zotapi.rs6
7 files changed, 75 insertions, 13 deletions
diff --git a/examples/zot/channel_stream.rs b/examples/zot/channel_stream.rs
index b50f93f..bad7152 100644
--- a/examples/zot/channel_stream.rs
+++ b/examples/zot/channel_stream.rs
@@ -21,7 +21,7 @@ use serde_json;
use std::iter::Iterator;
pub fn fetch(client: &zotapi::Client, raw: bool) {
- match client.channel_stream() {
+ match zotapi::channel_stream().fetch(&client) {
Ok(payload) => {
if raw {
println!("{}", payload);
diff --git a/examples/zot/network_stream.rs b/examples/zot/network_stream.rs
index 6dc1a0c..0e6edb4 100644
--- a/examples/zot/network_stream.rs
+++ b/examples/zot/network_stream.rs
@@ -21,7 +21,7 @@ use serde_json;
use std::iter::Iterator;
pub fn fetch(client: &zotapi::Client, raw: bool) {
- match client.network_stream() {
+ match zotapi::network_stream().fetch(&client) {
Ok(payload) => {
if raw {
println!("{}", payload);
diff --git a/src/channel_stream.rs b/src/channel_stream.rs
new file mode 100644
index 0000000..f99ca1c
--- /dev/null
+++ b/src/channel_stream.rs
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2020 Harald Eilertsen
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+use crate::{
+ client::Client,
+ error::Error,
+};
+
+pub struct ChannelStream;
+
+pub fn channel_stream() -> ChannelStream {
+ ChannelStream {}
+}
+
+impl ChannelStream {
+ pub fn fetch(&self, client: &Client) -> Result<String, Error> {
+ client.fetch_stream("channel/stream", &())
+ }
+}
diff --git a/src/client.rs b/src/client.rs
index dc6cf43..fcafed3 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -43,14 +43,6 @@ impl Client {
}
}
- pub fn channel_stream(&self) -> Result<String, Error> {
- self.fetch_stream("channel/stream", &())
- }
-
- pub fn network_stream(&self) -> Result<String, Error> {
- self.fetch_stream("network/stream", &())
- }
-
fn url<T>(&self, path: &str, args: &T) -> String
where
T: Serialize + std::fmt::Debug,
diff --git a/src/lib.rs b/src/lib.rs
index c4a39c8..d89eb46 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -16,18 +16,22 @@
mod abconfig;
mod abook;
+mod channel_stream;
mod client;
mod error;
mod group;
mod item;
+mod network_stream;
mod xchan;
pub use abconfig::abconfig;
pub use abook::abook;
+pub use channel_stream::channel_stream;
pub use client::Client;
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 fn client(url: &str, user: &str, pw: &str) -> Client {
diff --git a/src/network_stream.rs b/src/network_stream.rs
new file mode 100644
index 0000000..48a04a7
--- /dev/null
+++ b/src/network_stream.rs
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2020 Harald Eilertsen
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+use crate::{
+ client::Client,
+ error::Error,
+};
+
+pub struct NetworkStream;
+
+pub fn network_stream() -> NetworkStream {
+ NetworkStream {}
+}
+
+impl NetworkStream {
+ pub fn fetch(&self, client: &Client) -> Result<String, Error> {
+ client.fetch_stream("network/stream", &())
+ }
+}
diff --git a/tests/zotapi.rs b/tests/zotapi.rs
index 4c0a207..e22ba30 100644
--- a/tests/zotapi.rs
+++ b/tests/zotapi.rs
@@ -38,7 +38,7 @@ fn client() -> zotapi::Client {
#[test]
fn get_channel_stream() {
let m = default_mock("GET", "/api/z/1.0/channel/stream");
- let data = client().channel_stream();
+ let data = zotapi::channel_stream().fetch(&client());
m.assert();
assert_eq!(data.unwrap(), "{}");
}
@@ -46,7 +46,7 @@ fn get_channel_stream() {
#[test]
fn get_network_stream() {
let m = default_mock("GET", "/api/z/1.0/network/stream");
- let data = client().network_stream();
+ let data = zotapi::network_stream().fetch(&client());
m.assert();
assert_eq!(data.unwrap(), "{}");
}
@@ -59,7 +59,7 @@ fn return_error_if_invalid_auth_provided() {
.with_body("This api requires login")
.create();
- let data = client().channel_stream();
+ let data = zotapi::channel_stream().fetch(&client());
m.assert();
assert!(data.is_err());
assert_eq!(format!("{:?}", data), "Err(Unauthorized)");