R/get_top20_candidate_of_FinancialCategory.R

Defines functions get_top20_candidate_of_FinancialCategory

Documented in get_top20_candidate_of_FinancialCategory

#' Get Top 20 Candidates in Specific Financial Category
#' 
#' https://www.propublica.org/datastore/apis
#' HTTP Request: GET https://api.propublica.org/campaign-finance/v1/{cycle}/candidates/leaders/{category}
#'
#' @param category One of the values from the following categories:'candidate-loan', 'contribution-total', 'debts-owed', 'disbursements-total', 'end-cash', 'individual-total', 'pac-total', 'receipts-total' and 'refund-total'.
#' @param cycle The election cycle
#' @inheritParams get_new_members
#'
#' @return List of returned JSON from endpoint that retrieves a specific FEC candidate for a given campaign cycle.
#' @export
#'
#' @examples
#' \dontrun{
#' get_top20_candidate_of_FinancialCategory('pac-total', 2016)
#' }
get_top20_candidate_of_FinancialCategory <- function(category, cycle=2018, page = 1, myAPI_Key){
  API = 'campaign-finance'
  if(!validate_cycle(cycle))
    stop("Incorrect cycle")
  if(is.character(category) & category %in% c('candidate-loan', 'contribution-total', 'debts-owed', 'disbursements-total'
                                              , 'end-cash', 'individual-total', 'pac-total', 'receipts-total',
                                              'refund-total')){
    query <- sprintf("%s/candidates/leaders/%s.json", cycle,category)
    pp_query(query, API,  page = page, myAPI_Key = myAPI_Key)
  } else stop("Incorrect Category")
    
}

Try the ProPublicaR package in your browser

Any scripts or data that you put into this service are public.

ProPublicaR documentation built on Sept. 8, 2023, 5:53 p.m.