aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-01-04 13:15:00 +0100
committerHarald Eilertsen <haraldei@anduin.net>2020-01-04 13:15:00 +0100
commit1ba083af3576d20b5c1fc1c6ebacefd91ceb6636 (patch)
tree54a04c60fcd6721ab5c0cb782f1fc2bef38538b7 /src
parent862a3b67d701b3c124e1b682db0cee5fc5b711da (diff)
downloadrust-zotapi-1ba083af3576d20b5c1fc1c6ebacefd91ceb6636.tar.gz
rust-zotapi-1ba083af3576d20b5c1fc1c6ebacefd91ceb6636.tar.bz2
rust-zotapi-1ba083af3576d20b5c1fc1c6ebacefd91ceb6636.zip
abconfig: reorg + parse result into struct.
Diffstat (limited to 'src')
-rw-r--r--src/abconfig.rs21
-rw-r--r--src/error.rs7
-rw-r--r--src/lib.rs3
3 files changed, 21 insertions, 10 deletions
diff --git a/src/abconfig.rs b/src/abconfig.rs
index 7957dea..294467a 100644
--- a/src/abconfig.rs
+++ b/src/abconfig.rs
@@ -15,15 +15,20 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::{client::Client, error::Error};
+use serde::Deserialize;
-pub struct ABConfig;
-
-pub fn abconfig() -> ABConfig {
- ABConfig {}
+#[derive(Debug, Deserialize)]
+pub struct ABConfig {
+ pub id: u32,
+ pub chan: u32,
+ pub xchan: String,
+ pub cat: String,
+ pub k: String,
+ pub v: String,
}
-impl ABConfig {
- pub fn fetch(&self, client: &Client) -> Result<String, Error> {
- client.fetch_stream("abconfig", &())
- }
+pub fn fetch(client: &Client) -> Result<Vec<ABConfig>, Error> {
+ let payload = client.fetch_stream("abconfig", &())?;
+ Ok(serde_json::from_str(&payload)?)
}
+
diff --git a/src/error.rs b/src/error.rs
index 1e349d9..9559ae6 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -21,6 +21,7 @@ use std;
pub enum Error {
Http(reqwest::Error),
Io(std::io::Error),
+ Json(serde_json::Error),
Qs(serde_qs::Error),
Unauthorized,
Unknown,
@@ -38,6 +39,12 @@ impl From<std::io::Error> for Error {
}
}
+impl From<serde_json::Error> for Error {
+ fn from(e: serde_json::Error) -> Error {
+ Error::Json(e)
+ }
+}
+
impl From<serde_qs::Error> for Error {
fn from(e: serde_qs::Error) -> Error {
Error::Qs(e)
diff --git a/src/lib.rs b/src/lib.rs
index 12396ca..7a17269 100644
--- a/src/lib.rs
+++ b/src/lib.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/>.
-mod abconfig;
+pub mod abconfig;
mod abook;
mod channel_stream;
mod client;
@@ -24,7 +24,6 @@ mod item;
mod network_stream;
mod xchan;
-pub use abconfig::abconfig;
pub use abook::abook;
pub use channel_stream::channel_stream;
pub use client::*;