Skip to content

Commit 18cf1b0

Browse files
committed
add getRollCall & getDatasetList year correction
1 parent 8163b82 commit 18cf1b0

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export(getDatasetList)
55
export(getMasterList)
66
export(getMonitorList)
77
export(getPerson)
8+
export(getRollCall)
89
export(getSessionPeople)
910
export(getSessions)
1011
export(getSponsoredList)

R/getDatasetList.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ getDatasetList <- function(state = NULL, year = NULL, legiKey = NULL){
3535
key = legiKey,
3636
op = op,
3737
state = state,
38-
state = year,
38+
year = year,
3939
.multi = "explode"
4040
) |>
4141
httr2::req_perform()

R/getRollCall.R

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#' Voting information for provided Roll Call
2+
#'
3+
#' @description
4+
#' Return vote detail summary for provided Roll Call and a nested list of individual votes
5+
#'
6+
#' @param RollCall Roll Call ID integer
7+
#'
8+
#' @param legiKey 32 character string provided by legiscan
9+
#'
10+
#' @returns Summary of Vote and nested list of individual votes by people id
11+
#'
12+
#' @examples
13+
#' getRollCall(RollCall = 1361957)
14+
#'
15+
#' @export
16+
getRollCall <- function(RollCall = NULL, legiKey = NULL){
17+
op <- "getRollcall"
18+
19+
if (is.null(legiKey)){
20+
legiKey <- getlegiKey()
21+
}
22+
if (nchar(legiKey)!=32){
23+
warning(paste0("Invalid API Key: ",legiKey,"\nRegister <https://legiscan.com/user/register>\nStore with `setlegiKey`"))
24+
return(paste0("Invalid API Key: ",legiKey,"\nRegister <https://legiscan.com/user/register>\nStore with `setlegiKey`"))
25+
}
26+
27+
tryCatch({
28+
req <- httr2::request("https://api.legiscan.com") |>
29+
httr2::req_url_query(
30+
key = legiKey,
31+
op = op,
32+
id = RollCall,
33+
.multi = "explode"
34+
) |>
35+
httr2::req_perform()
36+
37+
status <- httr2::resp_status(req)
38+
if (status != 200) {
39+
stop(sprintf("API request failed with status code: %d", status))
40+
}
41+
42+
response <- httr2::resp_body_json(req)
43+
44+
if (!is.null(response$status)) {
45+
if (response$status != "OK") {
46+
stop(sprintf("API returned error: %s", response$alert))
47+
}
48+
}
49+
50+
print(response$roll_call$desc)
51+
return(response)
52+
}, error = function(e) {
53+
stop(sprintf("Error in API request: %s", e$message))
54+
})
55+
}

man/getRollCall.Rd

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)