Crates.io | votesmart |
lib.rs | votesmart |
version | 0.2.2 |
source | src |
created_at | 2021-12-17 21:24:17.992137 |
updated_at | 2023-09-26 08:10:56.154391 |
description | A client wrapper for the Votesmart REST API |
homepage | https://github.com/populist-vote/votesmart |
repository | https://github.com/populist-vote/votesmart |
max_upload_size | |
id | 499761 |
size | 58,222 |
A Rust wrapper around the Votesmart REST API
https://docs.rs/votesmart/latest/votesmart/
To get started, you'll need to instantiate a VotesmartProxy in your program. You have two options:
use votesmart::VotesmartProxy
// If you have a `VOTESMART_API_KEY` set in your .env or environment
let proxy = VotesmartProxy::new().unwrap();
// If you want to pass in the API key from elsewhere
let proxy = VotesmartProxy::new_from_key(your_api_key);
From there, each of Votesmarts Objects are namespaced from the proxy you just instantiated so you can run queries like this:
let candidate_id = 53279 // Joe Biden
let response = proxy.candidate_bio().get_detailed_bio(candidate_id).await?;
if response.status().is_success() {
let json: serde_json::Value = response.json().await?;
// Do whatever you want with this data
} else {
panic!("Something went wrong fetching Joe Biden's bio");
}
This is a work in progress, but eventually all of the Votesmart object responses will be typed out into their own structs. See src/types as an example. Unfortunately, some Votesmart responses are not always consistent in their return types depending on what you query for, so certain ambigious fields can be typed as serde_json::Value