generic_example/
generic_example.rs1use cdg_api::cdg_types::FormatType;
2use cdg_api::endpoints::Endpoints;
3use cdg_api::param_models::BillListParams;
4use cdg_api::response_models::{
5 parse_response, serialize_response, BillsResponse, GenericResponse,
6};
7use cdg_api::{unwrap_option_string, CongressApiClient};
8
9use std::error::Error;
10
11fn main() -> Result<(), Box<dyn Error>> {
12 let client = CongressApiClient::new(None)?; let params = BillListParams::default().format(FormatType::Json).limit(10);
16
17 let endpoint = Endpoints::BillList(params);
19
20 let response: GenericResponse = client.fetch(endpoint)?;
22
23 let bill_list: BillsResponse = match parse_response(&response) {
26 Ok(bill_list) => bill_list,
27 Err(_) => {
28 println!("{}", serialize_response(&response, true)?);
29 return Ok(());
30 }
31 };
32
33 for bill in bill_list.bills {
35 println!("Bill: {}", unwrap_option_string(bill.bill_type));
36 println!("Title: {}", unwrap_option_string(bill.title));
37 println!("Number: {}", unwrap_option_string(bill.number));
38 println!(
39 "Origin Chamber: {}",
40 unwrap_option_string(bill.origin_chamber)
41 );
42 println!("Update Date: {}", unwrap_option_string(bill.update_date));
43 println!("URL: {}", unwrap_option_string(bill.url));
44 println!();
45 }
46
47 Ok(())
48}