mod api;
mod errors;
mod types;
pub use api::*;
pub use errors::*;
pub use types::*;
const VOTESMART_BASE_URL: &str = "http://api.votesmart.org/";
pub struct VotesmartProxy {
client: reqwest::Client,
pub base_url: reqwest::Url,
api_key: String,
}
impl VotesmartProxy {
pub fn new() -> Result<Self, Error> {
dotenv::dotenv().ok();
let api_key = std::env::var("VOTESMART_API_KEY")?;
let client = reqwest::Client::new();
Ok(VotesmartProxy {
client,
base_url: reqwest::Url::parse(VOTESMART_BASE_URL).unwrap(),
api_key,
})
}
pub fn new_from_key(api_key: String) -> Result<Self, Error> {
let client = reqwest::Client::new();
Ok(VotesmartProxy {
client,
base_url: reqwest::Url::parse(VOTESMART_BASE_URL).unwrap(),
api_key,
})
}
}
impl VotesmartProxy {
pub const fn office(&self) -> Office<'_> {
Office(self)
}
pub const fn officials(&self) -> Officials<'_> {
Officials(self)
}
pub const fn rating(&self) -> Rating<'_> {
Rating(self)
}
pub const fn state(&self) -> State<'_> {
State(self)
}
pub const fn address(&self) -> Address<'_> {
Address(self)
}
pub const fn candidates(&self) -> Candidates<'_> {
Candidates(self)
}
pub const fn committee(&self) -> Committee<'_> {
Committee(self)
}
pub const fn district(&self) -> District<'_> {
District(self)
}
pub const fn election(&self) -> Election<'_> {
Election(self)
}
pub const fn leadership(&self) -> Leadership<'_> {
Leadership(self)
}
pub const fn votes(&self) -> Votes<'_> {
Votes(self)
}
pub const fn candidate_bio(&self) -> CandidateBio<'_> {
CandidateBio(self)
}
}