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
//! Miscellaneous utilities including the [`OctocatConfig`] struct and
//! [`Authorization`] enum.
use serde::{Deserialize, Serialize};
use thiserror::Error;
/// Used to represent the default Octocat configuration file format.
///
/// ```toml
/// username = "USERNAME"
/// access_token = "TOKEN"
/// ```
#[derive(Serialize, Deserialize)]
pub struct OctocatConfig {
username: String,
access_token: String,
}
impl OctocatConfig {
/// Converts the current [`OctocatConfig`] instance into an
/// [`Authorization`] instance.
pub fn to_personal_auth(self) -> Authorization {
Authorization::PersonalToken {
username: self.username,
token: self.access_token,
}
}
}
/// Used in [`Client`] to represent the authorization method
///
/// [`Client`]: crate::github::Client
#[derive(Clone)]
pub enum Authorization {
PersonalToken { username: String, token: String },
}
impl Default for Authorization {
fn default() -> Self {
Authorization::PersonalToken {
username: "".to_owned(),
token: "".to_owned(),
}
}
}
/// Used to represent errors when building a [`ClientBuilder`]
///
/// [`ClientBuilder`]: crate::github::ClientBuilder
#[derive(Error, Debug)]
pub enum BuildError {
#[error("Call build_no_handler instead!")]
NoHandler,
}