Browse Source

ran CRAN checks and cleaned the code up a bit

master
boB Rudis 7 years ago
parent
commit
950c555c98
  1. 1
      .Rbuildignore
  2. 7
      DESCRIPTION
  3. 5
      NAMESPACE
  4. 9
      R/aaa.r
  5. 1
      R/docker-splash.r
  6. 2
      R/execute.r
  7. 16
      R/helpers.r
  8. 4
      R/render-har.r
  9. 6
      R/render-png.r
  10. 3
      R/render_file.R
  11. 4
      R/splashr-package.R
  12. 2
      man/as_har.Rd
  13. 4
      man/execute_lua.Rd
  14. 4
      man/get_content_type.Rd
  15. 4
      man/render_file.Rd
  16. 2
      man/render_har.Rd
  17. 4
      man/render_png.Rd
  18. 2
      man/stop_splash.Rd

1
.Rbuildignore

@ -7,3 +7,4 @@
^NOTES\.*html$
^img$
^CONDUCT\.md$
^README_files$

7
DESCRIPTION

@ -34,6 +34,11 @@ Imports:
HARtools,
openssl,
lubridate,
scales
formatR,
scales,
harbor,
stats,
utils,
curl
RoxygenNote: 6.0.0
Remotes: wch/harbor

5
NAMESPACE

@ -79,12 +79,17 @@ importFrom(HARtools,HARviewerOutput)
importFrom(HARtools,renderHARviewer)
importFrom(HARtools,writeHAR)
importFrom(clipr,read_clip)
importFrom(curl,curl_unescape)
importFrom(formatR,tidy_source)
importFrom(jsonlite,fromJSON)
importFrom(lubridate,ymd_hms)
importFrom(openssl,base64_decode)
importFrom(scales,comma)
importFrom(stats,setNames)
importFrom(stringi,stri_detect_regex)
importFrom(stringi,stri_split_fixed)
importFrom(stringi,stri_split_regex)
importFrom(utils,capture.output)
importFrom(utils,str)
importFrom(xml2,read_html)
importFrom(xml2,url_parse)

9
R/aaa.r

@ -6,3 +6,12 @@ trunc_string <- function (x, maxlen = 20, justify = "left") {
for (i in 1:length(x)) if (toolong[i]) chopx[i] <- paste(chopx[i], "...", sep = "")
return(formatC(chopx, width = maxlen, flag = ifelse(justify == "left", "-", " ")))
}
parse_query <- function(query) {
params <- vapply(stri_split_regex(query, "&", omit_empty=TRUE)[[1]],
stri_split_fixed, "=", 2, simplify=TRUE,
FUN.VALUE=character(2))
purrr::set_names(as.list(curl::curl_unescape(params[2,])),
curl::curl_unescape(params[1,]))
}

1
R/docker-splash.r

@ -55,7 +55,6 @@ start_splash <- function(host = harbor::localhost, add_tempdir=FALSE) {
#' Stop a running a Splash server Docker container
#'
#' @param splash_container saved Splash container id from [start_splash]
#' @param splash_container Docker `container` object created by [start_splash]
#' @note you need Docker running on your system and have pulled the container with
#' [install_spash] and started the Splash container with [start_splash] for this

2
R/execute.r

@ -2,7 +2,7 @@
#'
#' @md
#' @param splash_obj Object created by a call to [splash]
#' @param lua_sourc Browser automation script. See [Splash Script](http://splash.readthedocs.io/en/stable/scripting-tutorial.html#scripting-tutorial) Tutorial for more info.
#' @param lua_source Browser automation script. See [Splash Script](http://splash.readthedocs.io/en/stable/scripting-tutorial.html#scripting-tutorial) Tutorial for more info.
#' @param timeout A timeout (in seconds) for the render (defaults to 30).
#' @param allowed_domains Comma-separated list of allowed domain names. If present, Splash won’t load anything neither from domains not in this list nor from subdomains of domains not in this list.
#' @param proxy Proxy profile name or proxy URL.

16
R/helpers.r

@ -12,7 +12,6 @@ get_response_body <- function(har_resp_obj) {
#' Retrieve or test content type of a HAR request object
#'
#' @param har_resp_obj HAR response object
#' @export
get_content_type <- function(har_resp_obj) {
ctype <- har_resp_obj$response$content$mimeType
@ -30,6 +29,7 @@ is_content_type <- function(har_resp_obj, type="application/json") {
}
#' @rdname get_content_type
#' @param har_resp_obj a reponse object from [render_har]() or [execute_lua]()
#' @export
is_json <- function(har_resp_obj) { is_content_type(har_resp_obj) }
@ -78,13 +78,13 @@ is_gif <- function(har_resp_obj) { is_content_type(har_resp_obj, type="image/gif
#' @rdname get_content_type
#' @export
is_xhr <- function(x) {
is_xhr <- function(har_resp_obj) {
if (is.null(x$request$headers)) return(NA)
if (length(x$request$headers)==0) return(NA)
if (is.null(har_resp_obj$request$headers)) return(NA)
if (length(har_resp_obj$request$headers)==0) return(NA)
y <- map(x$request$headers, "value")
names(y) <- tolower(map_chr(x$request$headers, "name"))
y <- map(har_resp_obj$request$headers, "value")
names(y) <- tolower(map_chr(har_resp_obj$request$headers, "name"))
if ("x-requested-with" %in% names(y)) {
return(tolower("xmlhttprequest") == tolower(y[["x-requested-with"]]))
@ -116,8 +116,8 @@ get_request_type <- function(har_resp_obj) {
#' @rdname get_request_type
#' @export
is_get <- function(har_resp_obj) { get_requet_type(har_resp_obj) == "GET" }
is_get <- function(har_resp_obj) { get_request_type(har_resp_obj) == "GET" }
#' @rdname get_request_type
#' @export
is_post <- function(har_resp_obj) { get_requet_type(har_resp_obj) == "POST" }
is_post <- function(har_resp_obj) { get_request_type(har_resp_obj) == "POST" }

4
R/render-har.r

@ -6,7 +6,7 @@
#' @md
#' @param response_body When `TRUE`, response content is included in the HAR records
#' @inheritParams render_html
#' @return a [HARtools::har] object
#' @return a `HARtools` `har` object
#' @references [Splash docs](http://splash.readthedocs.io/en/stable/index.html)
#' @export
render_har <- function(splash_obj = splash_local, url, base_url, response_body=FALSE, timeout=30, resource_timeout, wait=0,
@ -47,7 +47,7 @@ render_har <- function(splash_obj = splash_local, url, base_url, response_body=F
#' Turn a generic Splash HAR response into a HAR object
#'
#' @param as_har splash response object as returned by `splash:har()` lua script
#' @param splash_resp splash response object as returned by `splash::har()` lua script
#' @export
as_har <- function(splash_resp) {

6
R/render-png.r

@ -8,7 +8,7 @@
#' @inheritParams render_html
#' @export
render_png <- function(
splash_obj = splash_local, url, base_url=NULL, quality=75, width=1024, height=768,
splash_obj = splash_local, url, base_url=NULL, width=1024, height=768,
timeout=30, resource_timeout, wait=0, render_all=FALSE,
proxy, js, js_src, filters, allowed_domains, allowed_content_types,
forbidden_content_types, viewport="1024x768", images, headers, body,
@ -16,8 +16,8 @@ render_png <- function(
params <- list(url=url, timeout=timeout,
wait=if (render_all & wait == 0) 0.5 else wait,
viewport=viewport,
quality=quality, width=width, height=height, render_all=as.numeric(render_all))
viewport=viewport, width=width, height=height,
render_all=as.numeric(render_all))
if (!missing(base_url)) params$base_url <- base_url
if (!missing(resource_timeout)) params$resource_timeout <- resource_timeout

3
R/render_file.R

@ -8,12 +8,13 @@
#' @md
#' @param splash_obj Object created by a call to [splash]()
#' @param file_path Absolute path to a filename on the local host. **This only works with a locally running Splash instance started with [start_splash]().**
#' @param wait seconds to wait
#' @param output either `html` or `png` to get the page content or an image capture
#' @param viewport View width and height (in pixels) of the browser viewport to render the web page. Format is "`<width>x<height>`". e.g. 800x600. Default value is 1024x768.
#' @param ... other params to [render_html]() or [render_png]()
#' @return An XML document or `magick` object
#' @export
render_file <- function(splash_obj = slpash_local, file_path, output=c("html", "png"), wait=0, viewport="1024x768", ...) {
render_file <- function(splash_obj = splash_local, file_path, output=c("html", "png"), wait=0, viewport="1024x768", ...) {
output <- match.arg(output, c("html", "png"))

4
R/splashr-package.R

@ -23,6 +23,10 @@
#' @importFrom clipr read_clip
#' @importFrom lubridate ymd_hms
#' @importFrom scales comma
#' @importFrom stats setNames
#' @importFrom formatR tidy_source
#' @importFrom utils capture.output str
#' @importFrom curl curl_unescape
NULL

2
man/as_har.Rd

@ -7,7 +7,7 @@
as_har(splash_resp)
}
\arguments{
\item{as_har}{splash response object as returned by `splash:har()` lua script}
\item{splash_resp}{splash response object as returned by `splash::har()` lua script}
}
\description{
Turn a generic Splash HAR response into a HAR object

4
man/execute_lua.Rd

@ -10,6 +10,8 @@ execute_lua(splash_obj, lua_source, timeout = 30, allowed_domains, proxy,
\arguments{
\item{splash_obj}{Object created by a call to \link{splash}}
\item{lua_source}{Browser automation script. See \href{http://splash.readthedocs.io/en/stable/scripting-tutorial.html#scripting-tutorial}{Splash Script} Tutorial for more info.}
\item{timeout}{A timeout (in seconds) for the render (defaults to 30).}
\item{allowed_domains}{Comma-separated list of allowed domain names. If present, Splash won’t load anything neither from domains not in this list nor from subdomains of domains not in this list.}
@ -21,8 +23,6 @@ execute_lua(splash_obj, lua_source, timeout = 30, allowed_domains, proxy,
\item{save_args}{A list of argument names to put in cache.}
\item{load_args}{Parameter values to load from cache}
\item{lua_sourc}{Browser automation script. See \href{http://splash.readthedocs.io/en/stable/scripting-tutorial.html#scripting-tutorial}{Splash Script} Tutorial for more info.}
}
\value{
\code{raw} content from the \code{httr} call. Given the vast diversity of possible return values, it's up to the caller to handle the return value.

4
man/get_content_type.Rd

@ -43,10 +43,10 @@ is_svg(har_resp_obj)
is_gif(har_resp_obj)
is_xhr(x)
is_xhr(har_resp_obj)
}
\arguments{
\item{har_resp_obj}{HAR response object}
\item{har_resp_obj}{a reponse object from [render_har]() or [execute_lua]()}
\item{type}{content type to compare to (default: "\code{application/json}")}
}

4
man/render_file.Rd

@ -4,7 +4,7 @@
\alias{render_file}
\title{Return the HTML or image (png) of the javascript-rendered page in a local file}
\usage{
render_file(splash_obj = slpash_local, file_path, output = c("html", "png"),
render_file(splash_obj = splash_local, file_path, output = c("html", "png"),
wait = 0, viewport = "1024x768", ...)
}
\arguments{
@ -14,6 +14,8 @@ render_file(splash_obj = slpash_local, file_path, output = c("html", "png"),
\item{output}{either \code{html} or \code{png} to get the page content or an image capture}
\item{wait}{seconds to wait}
\item{viewport}{View width and height (in pixels) of the browser viewport to render the web page. Format is "\code{<width>x<height>}". e.g. 800x600. Default value is 1024x768.}
\item{...}{other params to \url{render_html} or \url{render_png}}

2
man/render_har.Rd

@ -54,7 +54,7 @@ render_har(splash_obj = splash_local, url, base_url, response_body = FALSE,
\item{load_args}{Parameter values to load from cache}
}
\value{
a \link[HARtools:har]{HARtools::har} object
a \code{HARtools} \code{har} object
}
\description{
It includes information about requests made, responses received, timings, headers, etc and

4
man/render_png.Rd

@ -4,8 +4,8 @@
\alias{render_png}
\title{Return a image (in PNG format) of the javascript-rendered page.}
\usage{
render_png(splash_obj = splash_local, url, base_url = NULL, quality = 75,
width = 1024, height = 768, timeout = 30, resource_timeout, wait = 0,
render_png(splash_obj = splash_local, url, base_url = NULL, width = 1024,
height = 768, timeout = 30, resource_timeout, wait = 0,
render_all = FALSE, proxy, js, js_src, filters, allowed_domains,
allowed_content_types, forbidden_content_types, viewport = "1024x768",
images, headers, body, http_method, save_args, load_args)

2
man/stop_splash.Rd

@ -7,8 +7,6 @@
stop_splash(splash_container)
}
\arguments{
\item{splash_container}{saved Splash container id from [start_splash]}
\item{splash_container}{Docker `container` object created by [start_splash]}
}
\description{

Loading…
Cancel
Save