1mod api;
2mod errors;
3mod types;
4pub use api::*;
5pub use errors::*;
6pub use types::*;
7
8const VOTESMART_BASE_URL: &str = "http://api.votesmart.org/";
9
10pub struct VotesmartProxy {
12 client: reqwest::Client,
13 pub base_url: reqwest::Url,
14 api_key: String,
15}
16
17impl VotesmartProxy {
18 pub fn new() -> Result<Self, Error> {
20 dotenv::dotenv().ok();
21 let api_key = std::env::var("VOTESMART_API_KEY")?;
22 let client = reqwest::Client::new();
23
24 Ok(VotesmartProxy {
25 client,
26 base_url: reqwest::Url::parse(VOTESMART_BASE_URL).unwrap(),
27 api_key,
28 })
29 }
30
31 pub fn new_from_key(api_key: String) -> Result<Self, Error> {
33 let client = reqwest::Client::new();
34
35 Ok(VotesmartProxy {
36 client,
37 base_url: reqwest::Url::parse(VOTESMART_BASE_URL).unwrap(),
38 api_key,
39 })
40 }
41}
42
43impl VotesmartProxy {
45 pub const fn office(&self) -> Office<'_> {
47 Office(self)
48 }
49 pub const fn officials(&self) -> Officials<'_> {
51 Officials(self)
52 }
53 pub const fn rating(&self) -> Rating<'_> {
55 Rating(self)
56 }
57 pub const fn state(&self) -> State<'_> {
59 State(self)
60 }
61 pub const fn address(&self) -> Address<'_> {
63 Address(self)
64 }
65 pub const fn candidates(&self) -> Candidates<'_> {
67 Candidates(self)
68 }
69 pub const fn committee(&self) -> Committee<'_> {
71 Committee(self)
72 }
73 pub const fn district(&self) -> District<'_> {
75 District(self)
76 }
77 pub const fn election(&self) -> Election<'_> {
79 Election(self)
80 }
81 pub const fn leadership(&self) -> Leadership<'_> {
83 Leadership(self)
84 }
85 pub const fn votes(&self) -> Votes<'_> {
87 Votes(self)
88 }
89 pub const fn candidate_bio(&self) -> CandidateBio<'_> {
91 CandidateBio(self)
92 }
93}