Skip to main content

generic_matching/
generic_matching.rs

1use cdg_api::cdg_types::{BillType, FormatType};
2use cdg_api::endpoints::{Endpoints, NewEndpoint};
3use cdg_api::param_models::BillDetailsParams;
4use cdg_api::response_models::{parse_response, BillDetailsResponse, GenericResponse};
5use cdg_api::{unwrap_option_string, CongressApiClient};
6
7use std::error::Error;
8
9fn main() -> Result<(), Box<dyn Error>> {
10    let client = CongressApiClient::new(None)?; // Use API key from environment
11
12    // Define parameters for bill details
13    let params = BillDetailsParams::default().format(FormatType::Json);
14
15    // Specify the bill to fetch (e.g., H.R. 1234 from the 118th Congress)
16    let endpoint = Endpoints::new_bill_details(118, BillType::Hr, 1234, params);
17
18    // Fetch the data as GenericResponse
19    let response: GenericResponse = client.fetch(endpoint)?;
20
21    // Parse the response as BillDetails
22    let bill_details: BillDetailsResponse = parse_response(&response)?;
23    let bill = bill_details.bill;
24
25    println!("Bill: {}", unwrap_option_string(bill.bill_type));
26    println!("Title: {}", unwrap_option_string(bill.title));
27    println!("Summary: {:#?}", bill.summaries.unwrap_or_default());
28
29    Ok(())
30}