pub enum BillType {
Hr,
S,
Hjres,
Sjres,
Hconres,
Sconres,
Hres,
Sres,
}Expand description
Enum representing various bill types in legislative processes.
This enum categorizes bills based on their origin and nature within the legislative system.
Variants§
Hr
House Resolution ([hr]).
S
Senate Bill ([s]).
Hjres
House Joint Resolution ([hjres]).
Sjres
Senate Joint Resolution ([sjres]).
Hconres
House Concurrent Resolution ([hconres]).
Sconres
Senate Concurrent Resolution ([sconres]).
Hres
House Simple Resolution ([hres]).
Sres
Senate Simple Resolution ([sres]).
Implementations§
Source§impl BillType
impl BillType
Sourcepub fn from_str(s: &str) -> Option<BillType>
pub fn from_str(s: &str) -> Option<BillType>
Converts a &str to the corresponding BillType variant.
Examples found in repository?
examples/cli_example.rs (line 164)
56fn run() -> Result<(), Box<dyn Error>> {
57 // Retrieve the API key from the environment variable or use default
58 let api_key = env::var("CDG_API_KEY").ok();
59 let client = CongressApiClient::new(api_key)?;
60
61 // Collect command-line arguments
62 let args: Vec<String> = env::args().collect();
63
64 if args.len() < 2 {
65 print_usage();
66 return Err("No command provided.".into());
67 }
68
69 // The first argument is the command
70 let command = args[1].to_lowercase();
71 let results_max = 1000;
72
73 match command.as_str() {
74 "list_bills" => {
75 if args.len() < 3 {
76 eprintln!("Usage: cargo run -- list_bills {{amount}}");
77 return Err("Missing amount for list_bills command.".into());
78 }
79 let bill_amount = args[2].parse::<u32>().unwrap_or(10);
80 println!("Searching for {} bills...", bill_amount);
81 let limit = 250;
82 let all_bills = fetch_all(
83 &client,
84 |offset, limit| {
85 Endpoints::BillList(
86 BillListParams::default()
87 .format(FormatType::Json)
88 .limit(limit as u32)
89 .offset(offset as u32),
90 )
91 },
92 |response: &BillsResponse| response.bills.clone(),
93 bill_amount as usize,
94 limit,
95 )?;
96 display_bills(&all_bills);
97 }
98 "current_congress" => {
99 let endpoint =
100 Endpoints::CongressCurrent(cdg_api::param_models::CongressCurrentParams::default());
101 let response: CongressDetailsResponse = client.fetch(endpoint)?;
102 display_congress_details(&response);
103 }
104 "list_nominations" => {
105 let limit = 250;
106 let all_nominations: Vec<cdg_api::response_models::NominationItem> = fetch_all(
107 &client,
108 |offset, limit| {
109 Endpoints::NominationList(
110 NominationListParams::default()
111 .format(FormatType::Json)
112 .limit(limit as u32)
113 .offset(offset as u32),
114 )
115 },
116 |response: &NominationsResponse| response.nominations.clone(),
117 results_max,
118 limit,
119 )
120 .unwrap_or_default();
121 display_nominations(&NominationsResponse {
122 nominations: all_nominations,
123 unknown: None,
124 });
125 }
126 "list_treaties" => {
127 let limit = 250;
128 let all_treaties = fetch_all(
129 &client,
130 |offset, limit| {
131 Endpoints::TreatyList(
132 TreatyListParams::default()
133 .format(FormatType::Json)
134 .limit(limit as u32)
135 .offset(offset as u32),
136 )
137 },
138 |response: &TreatiesResponse| response.treaty.clone(),
139 results_max,
140 limit,
141 )?;
142 display_treaties(&TreatiesResponse {
143 treaty: all_treaties,
144 unknown: None,
145 });
146 }
147 "member_details" => {
148 if args.len() < 3 {
149 eprintln!("Usage: cargo run -- member_details <bioguide_id>");
150 return Err("Missing bioguide_id for member_details command.".into());
151 }
152 let bioguide_id = &args[2];
153 let params = MemberDetailsParams::default();
154 let endpoint = Endpoints::MemberDetails(bioguide_id.clone(), params);
155 let response: MemberDetailsResponse = client.fetch(endpoint)?;
156 display_member_details(&response);
157 }
158 "bill_details" => {
159 if args.len() < 5 {
160 eprintln!("Usage: cargo run -- bill_details <congress> <bill_type> <bill_number>");
161 return Err("Missing arguments for bill_details command.".into());
162 }
163 let congress: u32 = args[2].parse()?;
164 let bill_type = BillType::from_str(&args[3]).unwrap_or_default();
165 let bill_number: u32 = args[4].parse()?;
166 let params = BillDetailsParams::default();
167 let endpoint = Endpoints::BillDetails(congress, bill_type, bill_number, params);
168 let response: BillDetailsResponse = client.fetch(endpoint)?;
169 display_bill_details(&response);
170 }
171 "bill_actions" => {
172 if args.len() < 5 {
173 eprintln!("Usage: cargo run -- bill_actions <congress> <bill_type> <bill_number>");
174 return Err("Missing arguments for bill_actions command.".into());
175 }
176 let congress: u32 = args[2].parse()?;
177 let bill_type = BillType::from_str(&args[3]).unwrap_or_default();
178 let bill_number: u32 = args[4].parse()?;
179 let params = BillActionsParams::default();
180 let endpoint = Endpoints::BillActions(congress, bill_type, bill_number, params);
181 let response: BillActionsResponse = client.fetch(endpoint)?;
182 display_billacts_details(&response);
183 }
184 "current_members" => {
185 let limit = 250;
186 let all_members = fetch_all(
187 &client,
188 |offset, limit| {
189 Endpoints::MemberList(
190 MemberListParams::default()
191 .format(FormatType::Json)
192 .limit(limit as u32)
193 .offset(offset as u32)
194 .current_member(true),
195 )
196 },
197 |response: &MembersResponse| response.members.clone(),
198 results_max,
199 limit,
200 )?;
201 display_members(&MembersResponse {
202 members: all_members,
203 unknown: None,
204 });
205 }
206 "list_committees" => {
207 let limit = 250;
208 let all_committees = fetch_all(
209 &client,
210 |offset, limit| {
211 Endpoints::CommitteeList(
212 CommitteeListParams::default()
213 .format(FormatType::Json)
214 .limit(limit as u32)
215 .offset(offset as u32),
216 )
217 },
218 |response: &CommitteesResponse| response.committees.clone(),
219 results_max,
220 limit,
221 )?;
222 display_committees(&CommitteesResponse {
223 committees: all_committees,
224 });
225 }
226 "list_laws" => {
227 let limit = 250;
228 let congress = 118; // Current Congress
229 let all_laws = fetch_all(
230 &client,
231 |offset, limit| {
232 Endpoints::LawByCongress(
233 congress,
234 LawParams::default()
235 .format(FormatType::Json)
236 .limit(limit as u32)
237 .offset(offset as u32),
238 )
239 },
240 |response: &LawsResponse| response.bills.clone(),
241 results_max,
242 limit,
243 )?;
244 display_laws(&LawsResponse {
245 bills: all_laws,
246 unknown: None,
247 });
248 }
249 "list_amendments" => {
250 let limit = 250;
251 let all_amendments = fetch_all(
252 &client,
253 |offset, limit| {
254 Endpoints::AmendmentList(
255 AmendmentListParams::default()
256 .format(FormatType::Json)
257 .limit(limit as u32)
258 .offset(offset as u32),
259 )
260 },
261 |response: &AmendmentsResponse| response.amendments.clone(),
262 results_max,
263 limit,
264 )?;
265 display_amendments(&AmendmentsResponse {
266 amendments: all_amendments,
267 unknown: None,
268 });
269 }
270 _ => {
271 println!("Unknown command: {}", command);
272 print_usage();
273 return Err("Invalid command.".into());
274 }
275 }
276
277 Ok(())
278}Trait Implementations§
impl Copy for BillType
Source§impl<'de> Deserialize<'de> for BillType
impl<'de> Deserialize<'de> for BillType
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Forget for BillType
impl Freeze for BillType
impl RefUnwindSafe for BillType
impl Send for BillType
impl Sync for BillType
impl Unpin for BillType
impl UnsafeUnpin for BillType
impl UnwindSafe for BillType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more