diff --git a/NAMESPACE b/NAMESPACE index 9599f85..152c9d2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(getDatasetList) export(getMasterList) export(getMonitorList) export(getPerson) +export(getRollCall) export(getSessionPeople) export(getSessions) export(getSponsoredList) diff --git a/R/getDatasetList.R b/R/getDatasetList.R index c704d63..f28d2ab 100644 --- a/R/getDatasetList.R +++ b/R/getDatasetList.R @@ -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() diff --git a/R/getRollCall.R b/R/getRollCall.R new file mode 100644 index 0000000..4e9e9e2 --- /dev/null +++ b/R/getRollCall.R @@ -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 \nStore with `setlegiKey`")) + return(paste0("Invalid API Key: ",legiKey,"\nRegister \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)) + }) +} diff --git a/man/getRollCall.Rd b/man/getRollCall.Rd new file mode 100644 index 0000000..8517991 --- /dev/null +++ b/man/getRollCall.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getRollCall.R +\name{getRollCall} +\alias{getRollCall} +\title{Voting information for provided Roll Call} +\usage{ +getRollCall(RollCall = NULL, legiKey = NULL) +} +\arguments{ +\item{RollCall}{Roll Call ID integer} + +\item{legiKey}{32 character string provided by legiscan} +} +\value{ +Summary of Vote and nested list of individual votes by people id +} +\description{ +Return vote detail summary for provided Roll Call and a nested list of individual votes +} +\examples{ +getRollCall(RollCall = 1361957) + +}