summaryrefslogtreecommitdiffstats
path: root/librepology/src/v1/api.rs
blob: d740d44b594d15cc94f7b87232436c684fa93e15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use std::io::{Stdin, Read};
use std::cell::RefCell;
use std::ops::Deref;
use std::ops::DerefMut;

use failure::Fallible as Result;
use failure::Error;

use crate::v1::types::Problem;
use crate::v1::types::Package;

pub trait Api {
    fn project<N: AsRef<str>>(&self, name: N) -> Result<Vec<Package>>;

    fn problems_for_repo<R: AsRef<str>>(&self, repo: R) -> Result<Vec<Problem>>;

    fn problems_for_maintainer<M: AsRef<str>>(&self, maintainer: M) -> Result<Vec<Problem>>;
}


//
// Api implemented for StdIn (via a Wrapper for interior mutability)
//
// This way we can read the data from stdin and process it
//

pub struct StdinWrapper(RefCell<Stdin>);

impl From<Stdin> for StdinWrapper {
    fn from(inner: Stdin) -> Self {
        StdinWrapper(RefCell::new(inner))
    }
}

impl Deref for StdinWrapper {
    type Target = RefCell<Stdin>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl DerefMut for StdinWrapper {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.0
    }
}

impl Api for StdinWrapper {

    fn project<N: AsRef<str>>(&self, _name: N) -> Result<Vec<Package>> {
        let s = read_to_string(self.0.try_borrow_mut()?.deref_mut())?;
        serde_json::de::from_str(&s).map_err(Error::from)
    }

    fn problems_for_repo<R: AsRef<str>>(&self, _repo: R) -> Result<Vec<Problem>> {
        let s = read_to_string(self.0.try_borrow_mut()?.deref_mut())?;
        serde_json::de::from_str(&s).map_err(Error::from)
    }

    fn problems_for_maintainer<M: AsRef<str>>(&self, _maintainer: M) -> Result<Vec<Problem>> {
        let s = read_to_string(self.0.try_borrow_mut()?.deref_mut())?;
        serde_json::de::from_str(&s).map_err(Error::from)
    }

}

fn read_to_string(input: &mut Read) -> Result<String> {
    let mut buffer = String::new();
    let read = input.read_to_string(&mut buffer)?;
    trace!("Read {} bytes from stdin", read);
    Ok(buffer)
}
> msgid "Folder name" msgstr "Folder name" #: templates/part.addnew.php:59 msgid "Back to folder selection" msgstr "Back to folder selection" #: templates/part.addnew.php:63 msgid "Create folder" msgstr "Create folder" #: templates/part.feed.starred.php:11 msgid "Starred" msgstr "Starred" #: templates/part.feed.unread.php:11 msgid "Unread articles" msgstr "Unread articles" #: templates/part.feed.unread.php:18 msgid "All articles" msgstr "All articles" #: templates/part.feed.unread.php:27 templates/part.listfeed.php:62 #: templates/part.listfolder.php:55 msgid "Mark read" msgstr "Mark read" #: templates/part.firstrun.php:2 msgid "Welcome to the ownCloud News app!" msgstr "Welcome to the ownCloud News app!" #: templates/part.items.php:20 msgid "read on website" msgstr "read on website" #: templates/part.items.php:40 msgid "star" msgstr "star" #: templates/part.items.php:56 msgid "from" msgstr "from" #: templates/part.items.php:61 msgid "by" msgstr "by" #: templates/part.items.php:68 msgid "Download" msgstr "Download" #: templates/part.items.php:79 msgid "Keep unread" msgstr "Keep unread" #: templates/part.listfeed.php:22 templates/part.listfolder.php:19 msgid "Cancel" msgstr "Cancel" #: templates/part.listfeed.php:25 templates/part.listfolder.php:22 msgid "Save" msgstr "Save" #: templates/part.listfeed.php:50 templates/part.listfeed.php:74 msgid "Delete website" msgstr "Delete website" #: templates/part.listfeed.php:69 msgid "Rename feed" msgstr "Rename feed" #: templates/part.listfolder.php:15 msgid "Collapse" msgstr "Collapse" #: templates/part.listfolder.php:44 templates/part.listfolder.php:60 msgid "Delete folder" msgstr "Delete folder" #: templates/part.listfolder.php:67 msgid "Rename folder" msgstr "Rename folder" #: templates/part.settings.php:13 msgid "Settings" msgstr "Settings" #: templates/part.settings.php:15 msgid "Use compact view" msgstr "Use compact view" #: templates/part.settings.php:17 msgid "Subscriptions (OPML)" msgstr "Subscriptions (OPML)" #: templates/part.settings.php:21 templates/part.settings.php:24 #: templates/part.settings.php:52 templates/part.settings.php:57 msgid "Import" msgstr "Import" #: templates/part.settings.php:28 templates/part.settings.php:32 #: templates/part.settings.php:36 templates/part.settings.php:38 #: templates/part.settings.php:60 templates/part.settings.php:64 #: templates/part.settings.php:68 templates/part.settings.php:70 msgid "Export" msgstr "Export" #: templates/part.settings.php:42 msgid "Error when importing: file does not contain valid OPML" msgstr "Error when importing: file does not contain valid OPML" #: templates/part.settings.php:48 msgid "Unread/Starred Articles" msgstr "Unread/Starred Articles" #: templates/part.settings.php:74 msgid "Error when importing: file does not contain valid JSON" msgstr "Error when importing: file does not contain valid JSON" #: templates/part.showall.php:5 msgid "Show read articles" msgstr "Show read articles" #: templates/part.showall.php:11 msgid "Hide read articles" msgstr "Hide read articles"