use serde::Deserialize;
use crate::repositories::Repo;
use crate::{Future, Github, Stream};
pub struct Watching {
github: Github,
}
impl Watching {
#[doc(hidden)]
pub fn new(github: Github) -> Self {
Self { github }
}
pub fn iter(&self) -> Stream<Repo> {
self.github.get_stream("/user/subscriptions")
}
pub fn get_for_repo<O, R>(&self, owner: O, repo: R) -> Future<Subscription>
where
O: Into<String>,
R: Into<String>,
{
self.github.get(&format!(
"/repos/{}/{}/subscription",
owner.into(),
repo.into()
))
}
pub fn watch_repo<O, R>(&self, owner: O, repo: R) -> Future<Subscription>
where
O: Into<String>,
R: Into<String>,
{
self.github.put(
&format!("/repos/{}/{}/subscription", owner.into(), repo.into()),
json_lit!({ "subscribed": true }),
)
}
pub fn ignore_repo<O, R>(&self, owner: O, repo: R) -> Future<Subscription>
where
O: Into<String>,
R: Into<String>,
{
self.github.put(
&format!("/repos/{}/{}/subscription", owner.into(), repo.into()),
json_lit!({ "ignored": true }),
)
}
pub fn unwatch_repo<O, R>(&self, owner: O, repo: R) -> Future<()>
where
O: Into<String>,
R: Into<String>,
{
self.github.delete(&format!(
"/repos/{}/{}/subscription",
owner.into(),
repo.into()
))
}
}
#[derive(Debug, Deserialize)]
pub struct Subscription {
pub subscribed: bool,
pub ignored: bool,
pub reason: Option<String>,
pub created_at: String,
pub url: String,
pub repository_url: String,
}