-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add getRollCall & getDatasetList year correction
- Loading branch information
Showing
4 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.