drawbridge_client/
repo.rs1use super::{scope, Entity, Result, Scope, Tag};
5
6use std::ops::Deref;
7
8use drawbridge_type::{RepositoryConfig, RepositoryName, TagName};
9
10use mime::APPLICATION_JSON;
11
12#[derive(Clone, Debug)]
13pub struct Repository<'a, S: Scope>(Entity<'a, S, scope::Repository>);
14
15impl<'a, S: Scope> Deref for Repository<'a, S> {
16 type Target = Entity<'a, S, scope::Repository>;
17
18 fn deref(&self) -> &Self::Target {
19 &self.0
20 }
21}
22
23impl<'a, S: Scope> Repository<'a, S> {
24 pub fn new(entity: Entity<'a, S, scope::User>, name: &RepositoryName) -> Repository<'a, S> {
25 Repository(entity.child(name.as_ref()))
26 }
27
28 pub fn create(&self, conf: &RepositoryConfig) -> Result<bool> {
29 self.0.create_json(&APPLICATION_JSON, conf)
30 }
31
32 pub fn get(&self) -> Result<RepositoryConfig> {
33 self.0.get_json(u64::MAX).map(|(_, v)| v)
35 }
36
37 pub fn tags(&self) -> Result<Vec<TagName>> {
38 self.0
39 .child::<scope::Unknown>("_tag")
40 .get_json(u64::MAX)
41 .map(|(_, v)| v)
42 }
43
44 pub fn tag(&self, name: &TagName) -> Tag<'a, S> {
45 Tag::new(self.child("_tag"), name)
46 }
47}