diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/abconfig.rs | 21 | ||||
-rw-r--r-- | src/error.rs | 7 | ||||
-rw-r--r-- | src/lib.rs | 3 |
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) @@ -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::*; |