Skip to content

populist-vote/votesmart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

Votesmart

A Rust wrapper around the Votesmart REST API

Docs

https://docs.rs/votesmart/latest/votesmart/

Quick Start

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");
}

Types

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

Releases

No releases published

Packages

No packages published

Languages