tiedcrossing_client/
repo.rs1use super::{Entity, Result, Tag};
5
6use std::ops::Deref;
7
8use drawbridge_type::{RepositoryConfig, RepositoryName, TagName};
9
10use mime::APPLICATION_JSON;
11
12pub struct Repository<'a>(Entity<'a>);
13
14impl<'a> Deref for Repository<'a> {
15 type Target = Entity<'a>;
16
17 fn deref(&self) -> &Self::Target {
18 &self.0
19 }
20}
21
22impl<'a> Repository<'a> {
23 pub fn new(entity: Entity<'a>, name: &RepositoryName) -> Repository<'a> {
24 Repository(entity.child(&name.to_string()))
25 }
26
27 pub fn create(&self, conf: &RepositoryConfig) -> Result<bool> {
28 self.0.create_json(&APPLICATION_JSON, conf)
29 }
30
31 pub fn get(&self) -> Result<RepositoryConfig> {
32 self.0.get_json()
33 }
34
35 pub fn tags(&self) -> Result<Vec<TagName>> {
36 self.0.child("_tag").get_json()
37 }
38
39 pub fn tag(&self, name: &TagName) -> Tag<'a> {
40 Tag::new(self.child("_tag"), name)
41 }
42}