aboutsummaryrefslogtreecommitdiffstats
path: root/src/group.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/group.rs')
-rw-r--r--src/group.rs46
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())
+ }
+}