Skip to content

Commit

Permalink
masterlist status check & getsession default change
Browse files Browse the repository at this point in the history
  • Loading branch information
Abraham Ruiz committed Nov 13, 2024
1 parent c608c8f commit 819ee70
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified R/.DS_Store
Binary file not shown.
44 changes: 31 additions & 13 deletions R/getMasterlist.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,36 @@ getMasterList <- function(session = NULL, state = NULL, legiKey = NULL){
}
}

req <- httr2::request(
"https://api.legiscan.com"
) |>
httr2::req_url_query(
key = legiKey,
op = op,
state = state,
id = session,
.multi = "explode"
tryCatch({
req <- httr2::request(
"https://api.legiscan.com"
) |>
httr2::req_perform() |>
httr2::resp_body_json()
print(req$masterlist$session$session_name)
return(dplyr::bind_rows(req$masterlist[-1]))
httr2::req_url_query(
key = legiKey,
op = op,
state = state,
id = session,
.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$masterlist$session$session_name)
return(dplyr::bind_rows(response$masterlist[-1]))

}, error = function(e) {
stop(sprintf("Error in API request: %s", e$message))
})
}
2 changes: 1 addition & 1 deletion R/getSessions.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' getSessions(state = "MA")
#'
#' @export
getSessions <- function(state = "TX", legiKey = NULL){
getSessions <- function(state = NULL, legiKey = NULL){
op <- "getSessionlist"

if (is.null(legiKey)){
Expand Down

0 comments on commit 819ee70

Please sign in to comment.