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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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)
}
}