|
| 1 | +#' Add or remove bills from the monitor list |
| 2 | +#' |
| 3 | +#' @description |
| 4 | +#' Interact with GAITS to add or remove bills from the monitor list of the |
| 5 | +#' account associated with the legiKey provided, or set a stance on monitored bills |
| 6 | +#' |
| 7 | +#' @param billIDs One or more bill_id integer values to operate on |
| 8 | +#' |
| 9 | +#' @param action Action to take on the bill list: "monitor", "remove", or "set" |
| 10 | +#' |
| 11 | +#' @param stance Position on the bill: "watch", "support", or "oppose" |
| 12 | +#' |
| 13 | +#' @param legiKey 32 character API key from legiscan |
| 14 | +#' |
| 15 | +#' @returns Status of each bill_id and the action taken in dataframe format |
| 16 | +#' |
| 17 | +#' @examples |
| 18 | +#' \dontrun{ |
| 19 | +#' setMonitor(billIDs = c(150334, 141690), action = "monitor") |
| 20 | +#' setMonitor(billIDs = 1533377, action = "set", stance = "support") |
| 21 | +#' } |
| 22 | +#' |
| 23 | +#' @export |
| 24 | +setMonitor <- function(billIDs = NULL, action = NULL, stance = "watch", legiKey = NULL){ |
| 25 | + |
| 26 | + if (is.null(billIDs)){ |
| 27 | + stop("Specify one or more billIDs to operate on") |
| 28 | + } |
| 29 | + if (is.null(action) || !action %in% c("monitor", "remove", "set")){ |
| 30 | + stop("action must be one of 'monitor', 'remove', or 'set'") |
| 31 | + } |
| 32 | + if (!stance %in% c("watch", "support", "oppose")){ |
| 33 | + stop("stance must be one of 'watch', 'support', or 'oppose'") |
| 34 | + } |
| 35 | + |
| 36 | + response <- legiRequest( |
| 37 | + op = "setMonitor", |
| 38 | + list = paste(billIDs, collapse = ","), |
| 39 | + action = action, |
| 40 | + stance = stance, |
| 41 | + legiKey = legiKey |
| 42 | + ) |
| 43 | + |
| 44 | + return( |
| 45 | + data.frame( |
| 46 | + bill_id = names(response$`return`), |
| 47 | + result = unlist(response$`return`), |
| 48 | + row.names = NULL |
| 49 | + ) |
| 50 | + ) |
| 51 | +} |
0 commit comments