Skip to content

Commit

Permalink
add getRollCall & getDatasetList year correction
Browse files Browse the repository at this point in the history
  • Loading branch information
aberuiz committed Nov 16, 2024
1 parent 8163b82 commit 18cf1b0
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(getDatasetList)
export(getMasterList)
export(getMonitorList)
export(getPerson)
export(getRollCall)
export(getSessionPeople)
export(getSessions)
export(getSponsoredList)
Expand Down
2 changes: 1 addition & 1 deletion R/getDatasetList.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ getDatasetList <- function(state = NULL, year = NULL, legiKey = NULL){
key = legiKey,
op = op,
state = state,
state = year,
year = year,
.multi = "explode"
) |>
httr2::req_perform()
Expand Down
55 changes: 55 additions & 0 deletions R/getRollCall.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#' Voting information for provided Roll Call
#'
#' @description
#' Return vote detail summary for provided Roll Call and a nested list of individual votes
#'
#' @param RollCall Roll Call ID integer
#'
#' @param legiKey 32 character string provided by legiscan
#'
#' @returns Summary of Vote and nested list of individual votes by people id
#'
#' @examples
#' getRollCall(RollCall = 1361957)
#'
#' @export
getRollCall <- function(RollCall = NULL, legiKey = NULL){
op <- "getRollcall"

if (is.null(legiKey)){
legiKey <- getlegiKey()
}
if (nchar(legiKey)!=32){
warning(paste0("Invalid API Key: ",legiKey,"\nRegister <https://legiscan.com/user/register>\nStore with `setlegiKey`"))
return(paste0("Invalid API Key: ",legiKey,"\nRegister <https://legiscan.com/user/register>\nStore with `setlegiKey`"))
}

tryCatch({
req <- httr2::request("https://api.legiscan.com") |>
httr2::req_url_query(
key = legiKey,
op = op,
id = RollCall,
.multi = "explode"
) |>
httr2::req_perform()

status <- httr2::resp_status(req)
if (status != 200) {
stop(sprintf("API request failed with status code: %d", status))
}

response <- httr2::resp_body_json(req)

if (!is.null(response$status)) {
if (response$status != "OK") {
stop(sprintf("API returned error: %s", response$alert))
}
}

print(response$roll_call$desc)
return(response)
}, error = function(e) {
stop(sprintf("Error in API request: %s", e$message))
})
}
23 changes: 23 additions & 0 deletions man/getRollCall.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 18cf1b0

Please sign in to comment.