Skip to content

Commit 819ee70

Browse files
author
Abraham Ruiz
committed
masterlist status check & getsession default change
1 parent c608c8f commit 819ee70

4 files changed

Lines changed: 32 additions & 14 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

R/.DS_Store

0 Bytes
Binary file not shown.

R/getMasterlist.R

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,36 @@ getMasterList <- function(session = NULL, state = NULL, legiKey = NULL){
3434
}
3535
}
3636

37-
req <- httr2::request(
38-
"https://api.legiscan.com"
39-
) |>
40-
httr2::req_url_query(
41-
key = legiKey,
42-
op = op,
43-
state = state,
44-
id = session,
45-
.multi = "explode"
37+
tryCatch({
38+
req <- httr2::request(
39+
"https://api.legiscan.com"
4640
) |>
47-
httr2::req_perform() |>
48-
httr2::resp_body_json()
49-
print(req$masterlist$session$session_name)
50-
return(dplyr::bind_rows(req$masterlist[-1]))
41+
httr2::req_url_query(
42+
key = legiKey,
43+
op = op,
44+
state = state,
45+
id = session,
46+
.multi = "explode"
47+
) |>
48+
httr2::req_perform()
49+
50+
status <- httr2::resp_status(req)
51+
if (status != 200) {
52+
stop(sprintf("API request failed with status code: %d", status))
53+
}
54+
55+
response <- httr2::resp_body_json(req)
56+
57+
if (!is.null(response$status)) {
58+
if (response$status != "OK") {
59+
stop(sprintf("API returned error: %s", response$alert))
60+
}
61+
}
62+
63+
print(response$masterlist$session$session_name)
64+
return(dplyr::bind_rows(response$masterlist[-1]))
65+
66+
}, error = function(e) {
67+
stop(sprintf("Error in API request: %s", e$message))
68+
})
5169
}

R/getSessions.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#' getSessions(state = "MA")
1414
#'
1515
#' @export
16-
getSessions <- function(state = "TX", legiKey = NULL){
16+
getSessions <- function(state = NULL, legiKey = NULL){
1717
op <- "getSessionlist"
1818

1919
if (is.null(legiKey)){

0 commit comments

Comments
 (0)