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
use self::super::read_toml_file;
use self::super::super::Error;
use toml::encode_str;
use std::path::Path;
use std::io::Write;
use std::fs::File;


/// The tokens needed to authenticate the app to GitHub.
#[derive(Debug, Clone, Hash, PartialEq, Eq, RustcEncodable, RustcDecodable)]
pub struct AppTokens {
    /// GitHub OAuth authentication token
    ///
    /// Required scopes: public_repo, repo:status.
    pub github: String,
    /// Discord bot user token
    pub discord: String,
}

impl AppTokens {
    /// Read the application GitHub tokens from the specified file.
    pub fn read(p: &Path) -> Result<AppTokens, Error> {
        read_toml_file(p, "App tokens")
    }

    /// Save the application GitHub tokens to the specified file.
    pub fn write(&self, p: &Path) {
        File::create(p).unwrap().write_all(encode_str(&self).as_bytes()).unwrap();
    }
}