Browse Source

ran CRAN checks and cleaned the code up a bit

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

+ 1
- 0
.Rbuildignore View File

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

+ 6
- 1
DESCRIPTION View File

@@ -34,6 +34,11 @@ Imports:
34 34
     HARtools,
35 35
     openssl,
36 36
     lubridate,
37
-    scales
37
+    formatR,
38
+    scales,
39
+    harbor,
40
+    stats,
41
+    utils,
42
+    curl
38 43
 RoxygenNote: 6.0.0
39 44
 Remotes: wch/harbor

+ 5
- 0
NAMESPACE View File

@@ -79,12 +79,17 @@ importFrom(HARtools,HARviewerOutput)
79 79
 importFrom(HARtools,renderHARviewer)
80 80
 importFrom(HARtools,writeHAR)
81 81
 importFrom(clipr,read_clip)
82
+importFrom(curl,curl_unescape)
83
+importFrom(formatR,tidy_source)
82 84
 importFrom(jsonlite,fromJSON)
83 85
 importFrom(lubridate,ymd_hms)
84 86
 importFrom(openssl,base64_decode)
85 87
 importFrom(scales,comma)
88
+importFrom(stats,setNames)
86 89
 importFrom(stringi,stri_detect_regex)
87 90
 importFrom(stringi,stri_split_fixed)
88 91
 importFrom(stringi,stri_split_regex)
92
+importFrom(utils,capture.output)
93
+importFrom(utils,str)
89 94
 importFrom(xml2,read_html)
90 95
 importFrom(xml2,url_parse)

+ 9
- 0
R/aaa.r View File

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

+ 0
- 1
R/docker-splash.r View File

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

+ 1
- 1
R/execute.r View File

@@ -2,7 +2,7 @@
2 2
 #'
3 3
 #' @md
4 4
 #' @param splash_obj Object created by a call to [splash]
5
-#' @param lua_sourc Browser automation script. See [Splash Script](http://splash.readthedocs.io/en/stable/scripting-tutorial.html#scripting-tutorial) Tutorial for more info.
5
+#' @param lua_source Browser automation script. See [Splash Script](http://splash.readthedocs.io/en/stable/scripting-tutorial.html#scripting-tutorial) Tutorial for more info.
6 6
 #' @param timeout A timeout (in seconds) for the render (defaults to 30).
7 7
 #' @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.
8 8
 #' @param proxy Proxy profile name or proxy URL.

+ 8
- 8
R/helpers.r View File

@@ -12,7 +12,6 @@ get_response_body <- function(har_resp_obj) {
12 12
 
13 13
 #' Retrieve or test content type of a HAR request object
14 14
 #'
15
-#' @param har_resp_obj HAR response object
16 15
 #' @export
17 16
 get_content_type <- function(har_resp_obj) {
18 17
   ctype <- har_resp_obj$response$content$mimeType
@@ -30,6 +29,7 @@ is_content_type <- function(har_resp_obj, type="application/json") {
30 29
 }
31 30
 
32 31
 #' @rdname get_content_type
32
+#' @param har_resp_obj a reponse object from [render_har]() or [execute_lua]()
33 33
 #' @export
34 34
 is_json <- function(har_resp_obj) { is_content_type(har_resp_obj) }
35 35
 
@@ -78,13 +78,13 @@ is_gif <- function(har_resp_obj) { is_content_type(har_resp_obj, type="image/gif
78 78
 
79 79
 #' @rdname get_content_type
80 80
 #' @export
81
-is_xhr <- function(x) {
81
+is_xhr <- function(har_resp_obj) {
82 82
 
83
-  if (is.null(x$request$headers)) return(NA)
84
-  if (length(x$request$headers)==0) return(NA)
83
+  if (is.null(har_resp_obj$request$headers)) return(NA)
84
+  if (length(har_resp_obj$request$headers)==0) return(NA)
85 85
 
86
-  y <- map(x$request$headers, "value")
87
-  names(y) <- tolower(map_chr(x$request$headers, "name"))
86
+  y <- map(har_resp_obj$request$headers, "value")
87
+  names(y) <- tolower(map_chr(har_resp_obj$request$headers, "name"))
88 88
 
89 89
   if ("x-requested-with" %in% names(y)) {
90 90
     return(tolower("xmlhttprequest") == tolower(y[["x-requested-with"]]))
@@ -116,8 +116,8 @@ get_request_type <- function(har_resp_obj) {
116 116
 
117 117
 #' @rdname get_request_type
118 118
 #' @export
119
-is_get <- function(har_resp_obj) { get_requet_type(har_resp_obj) == "GET" }
119
+is_get <- function(har_resp_obj) { get_request_type(har_resp_obj) == "GET" }
120 120
 
121 121
 #' @rdname get_request_type
122 122
 #' @export
123
-is_post <- function(har_resp_obj) { get_requet_type(har_resp_obj) == "POST" }
123
+is_post <- function(har_resp_obj) { get_request_type(har_resp_obj) == "POST" }

+ 2
- 2
R/render-har.r View File

@@ -6,7 +6,7 @@
6 6
 #' @md
7 7
 #' @param response_body When `TRUE`, response content is included in the HAR records
8 8
 #' @inheritParams render_html
9
-#' @return a [HARtools::har] object
9
+#' @return a `HARtools` `har` object
10 10
 #' @references [Splash docs](http://splash.readthedocs.io/en/stable/index.html)
11 11
 #' @export
12 12
 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
47 47
 
48 48
 #' Turn a generic Splash HAR response into a HAR object
49 49
 #'
50
-#' @param as_har splash response object as returned by `splash:har()` lua script
50
+#' @param splash_resp splash response object as returned by `splash::har()` lua script
51 51
 #' @export
52 52
 as_har <- function(splash_resp) {
53 53
 

+ 3
- 3
R/render-png.r View File

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

+ 2
- 1
R/render_file.R View File

@@ -8,12 +8,13 @@
8 8
 #' @md
9 9
 #' @param splash_obj Object created by a call to [splash]()
10 10
 #' @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]().**
11
+#' @param wait seconds to wait
11 12
 #' @param output either `html` or `png` to get the page content or an image capture
12 13
 #' @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.
13 14
 #' @param ... other params to [render_html]() or [render_png]()
14 15
 #' @return An XML document or `magick` object
15 16
 #' @export
16
-render_file <- function(splash_obj = slpash_local, file_path, output=c("html", "png"), wait=0, viewport="1024x768", ...) {
17
+render_file <- function(splash_obj = splash_local, file_path, output=c("html", "png"), wait=0, viewport="1024x768", ...) {
17 18
 
18 19
   output <- match.arg(output, c("html", "png"))
19 20
 

+ 4
- 0
R/splashr-package.R View File

@@ -23,6 +23,10 @@
23 23
 #' @importFrom clipr read_clip
24 24
 #' @importFrom lubridate ymd_hms
25 25
 #' @importFrom scales comma
26
+#' @importFrom stats setNames
27
+#' @importFrom formatR tidy_source
28
+#' @importFrom utils capture.output str
29
+#' @importFrom curl curl_unescape
26 30
 
27 31
 NULL
28 32
 

+ 1
- 1
man/as_har.Rd View File

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

+ 2
- 2
man/execute_lua.Rd View File

@@ -10,6 +10,8 @@ execute_lua(splash_obj, lua_source, timeout = 30, allowed_domains, proxy,
10 10
 \arguments{
11 11
 \item{splash_obj}{Object created by a call to \link{splash}}
12 12
 
13
+\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.}
14
+
13 15
 \item{timeout}{A timeout (in seconds) for the render (defaults to 30).}
14 16
 
15 17
 \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,
21 23
 \item{save_args}{A list of argument names to put in cache.}
22 24
 
23 25
 \item{load_args}{Parameter values to load from cache}
24
-
25
-\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.}
26 26
 }
27 27
 \value{
28 28
 \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.

+ 2
- 2
man/get_content_type.Rd View File

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

+ 3
- 1
man/render_file.Rd View File

@@ -4,7 +4,7 @@
4 4
 \alias{render_file}
5 5
 \title{Return the HTML or image (png) of the javascript-rendered page in a local file}
6 6
 \usage{
7
-render_file(splash_obj = slpash_local, file_path, output = c("html", "png"),
7
+render_file(splash_obj = splash_local, file_path, output = c("html", "png"),
8 8
   wait = 0, viewport = "1024x768", ...)
9 9
 }
10 10
 \arguments{
@@ -14,6 +14,8 @@ render_file(splash_obj = slpash_local, file_path, output = c("html", "png"),
14 14
 
15 15
 \item{output}{either \code{html} or \code{png} to get the page content or an image capture}
16 16
 
17
+\item{wait}{seconds to wait}
18
+
17 19
 \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.}
18 20
 
19 21
 \item{...}{other params to \url{render_html} or \url{render_png}}

+ 1
- 1
man/render_har.Rd View File

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

+ 2
- 2
man/render_png.Rd View File

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

+ 0
- 2
man/stop_splash.Rd View File

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

Loading…
Cancel
Save