legiscan/api/
get_roll_call.rs1use crate::{Error, LegiscanProxy};
2use serde::{Deserialize, Serialize};
3
4#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5pub struct GetRollCallResponse {
6 pub status: String,
7 pub roll_call: RollCall,
8}
9
10#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11#[cfg_attr(feature = "async-graphql", derive(async_graphql::SimpleObject))]
12pub struct RollCall {
13 pub roll_call_id: i64,
14 pub bill_id: i64,
15 pub date: String,
16 pub desc: String,
17 pub yea: i64,
18 pub nay: i64,
19 pub nv: i64,
20 pub absent: i64,
21 pub total: i64,
22 pub passed: i64,
23 pub chamber: String,
24 pub chamber_id: i64,
25 pub votes: Vec<RollCallVote>,
26}
27
28#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
29#[cfg_attr(feature = "async-graphql", derive(async_graphql::SimpleObject))]
30pub struct RollCallVote {
31 pub people_id: i64,
32 pub vote_id: i64,
33 pub vote_text: String,
34}
35
36impl LegiscanProxy {
37 pub async fn get_roll_call(&self, roll_call_id: i32) -> Result<RollCall, Error> {
40 let url = format!(
41 "{base_url}?key={key}&op={operation}&id={roll_call_id}",
42 base_url = self.base_url,
43 key = self.api_key,
44 operation = "getRollCall",
45 roll_call_id = roll_call_id
46 );
47 let response = self.client.get(url).send().await.unwrap();
48
49 match crate::handle_legiscan_response(response).await {
50 Ok(json) => {
51 let json: GetRollCallResponse = serde_json::from_value(json).unwrap();
52 Ok(json.roll_call)
53 }
54 Err(e) => Err(e),
55 }
56 }
57}
58
59#[tokio::test]
60async fn test_get_roll_call() {
61 let proxy = LegiscanProxy::new().unwrap();
62 let roll_call = proxy.get_roll_call(234223).await.unwrap();
63 assert_eq!(roll_call.date, "2013-02-20");
64}