diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2019-06-10 17:32:32 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2019-06-10 17:32:32 +0200 |
commit | 8158bee4cbb5cc599c38788f0aa12a489e5261c1 (patch) | |
tree | 30f669dbd06b7977c29febc524dc5dbc7aa2cfbb /src/group.rs | |
parent | 39bef981a13701aaca944e50c5354487d528d977 (diff) | |
download | rust-zotapi-8158bee4cbb5cc599c38788f0aa12a489e5261c1.tar.gz rust-zotapi-8158bee4cbb5cc599c38788f0aa12a489e5261c1.tar.bz2 rust-zotapi-8158bee4cbb5cc599c38788f0aa12a489e5261c1.zip |
Implement fetching privacy group members.
Diffstat (limited to 'src/group.rs')
-rw-r--r-- | src/group.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/group.rs b/src/group.rs index 64a6847..c01d5ae 100644 --- a/src/group.rs +++ b/src/group.rs @@ -18,6 +18,7 @@ use crate::{ client::{self, Client}, error::Error, }; +use serde::{Serialize, Serializer}; pub struct GroupFetcher<'a> { client: &'a Client, @@ -32,3 +33,48 @@ impl<'a> GroupFetcher<'a> { self.client.fetch_stream(client::ZOTAPI_GROUP_PATH, &()) } } + + +enum GroupSelector<'a> { + Id(u64), + Name(&'a str), +} + +impl<'a> Serialize for GroupSelector<'a> { + fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> + where + S: Serializer, + { + match *self { + GroupSelector::Id(id) => [("group_id", id)].serialize(serializer), + GroupSelector::Name(n) => [("group_name", n)].serialize(serializer), + } + } +} + +pub struct GroupMembersFetcher<'a> { + client: &'a Client, + id: Option<GroupSelector<'a>>, +} + +impl<'a> GroupMembersFetcher<'a> { + pub fn new(client: &'a Client) -> GroupMembersFetcher<'a> { + GroupMembersFetcher { client, id: None } + } + + pub fn by_group_id(&mut self, id: u64) -> &GroupMembersFetcher<'a> { + self.id = Some(GroupSelector::Id(id)); + self + } + + pub fn by_group_name(&mut self, name: &'a str) -> &GroupMembersFetcher<'a> { + self.id = Some(GroupSelector::Name(name)); + self + } + + pub fn fetch(&self) -> Result<String, Error> { + self.client.fetch_stream( + client::ZOTAPI_GROUP_MEMBERS_PATH, + &self.id.as_ref().unwrap()) + } +} |