R/SunlightAPI.R

Defines functions SunlightAPI

Documented in SunlightAPI

#' R interface for Sunlight API
#'
#' See \url{(https://sunlightlabs.github.io/congress/)}
#'
#' @import jsonlite
#' @export
#' @param method method to call
#' @param key API key
#' @param debug Enable debugging mode
#' @keywords API
#' @seealso \code{\link{GoogleAPI}}, \code{\link{PopongAPI}}
#'

SunlightAPI <- function(method, key=getOption("SunlightAPIKey"), debug=FALSE) {
    # TODO: auto navigate pages
    apiSource   <- "sunlight"
    apiAttrs    <- eval(parse(text=sprintf("apiInfo$%s", apiSource)))

    MethodInAPI(apiSource, method)

    paths <- c(apiAttrs$url, method)
    query <- list("apikey"=key)
    url   <- FormatURL(paths, query)
    jsontext <- RCurl::getURL(url)
    response <- jsonlite::fromJSON(jsontext)
    if(debug) { print(url) }

    return(response$results)
}

Try the polidata package in your browser

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

polidata documentation built on May 2, 2019, 6:54 a.m.