Browse Source

added function to turn HAR objects into data frames

master
boB Rudis 2 years ago
parent
commit
bd5da8bd38
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
6 changed files with 113 additions and 1 deletions
  1. +2
    -1
      DESCRIPTION
  2. +8
    -0
      NAMESPACE
  3. +1
    -0
      NEWS.md
  4. +65
    -0
      R/as-data-frame-har.R
  5. +1
    -0
      R/splashr-package.R
  6. +36
    -0
      man/as_data_frame.harentry.Rd

+ 2
- 1
DESCRIPTION View File

@@ -33,6 +33,7 @@ Imports:
xml2,
curl,
httr,
dplyr,
purrr,
stats,
utils,
@@ -42,8 +43,8 @@ Imports:
formatR,
openssl,
stringi,
jsonlite,
HARtools,
jsonlite,
lubridate
RoxygenNote: 6.0.1.9000
VignetteBuilder: knitr

+ 8
- 0
NAMESPACE View File

@@ -1,5 +1,11 @@
# Generated by roxygen2: do not edit by hand

S3method(as.data.frame,har)
S3method(as.data.frame,harentries)
S3method(as.data.frame,harentry)
S3method(as_data_frame,har)
S3method(as_data_frame,harentries)
S3method(as_data_frame,harentry)
S3method(print,splash_debug)
S3method(print,splash_json)
export("%>%")
@@ -93,6 +99,8 @@ importFrom(HARtools,HARviewerOutput)
importFrom(HARtools,renderHARviewer)
importFrom(HARtools,writeHAR)
importFrom(curl,curl_unescape)
importFrom(dplyr,as_data_frame)
importFrom(dplyr,data_frame)
importFrom(formatR,tidy_source)
importFrom(jsonlite,fromJSON)
importFrom(jsonlite,stream_in)


+ 1
- 0
NEWS.md View File

@@ -1,6 +1,7 @@
0.5.0

* support Splash API basic auth
* `as_data_frame`/`as.data.frame` methods for HAR objects

0.4.1



+ 65
- 0
R/as-data-frame-har.R View File

@@ -0,0 +1,65 @@
#' Turns a "HAR"-like object into a data frame(tibble)
#'
#' @md
#' @param harentry_obj A `harentry` object
#' @return data frame (tibble)
#' @export
as_data_frame.harentry <- function(harentry_obj) {

req <- harentry_obj$request
resp <- harentry_obj$response

data_frame(
request_url = req$url,
request_method = req$method,
request_http_version = req$httpVersion,
request_query_string = list(req$queryString),
request_header_size = req$headersSize,
requestheaders = list(if (length(req$headers) > 0) flatten_df(req$headers) else data_frame()),
requestcookies = list(if (length(req$cookies) > 0) flatten_df(req$cookies) else data_frame()),
response_url = resp$url,
response_http_version = resp$httpVersion,
status_text = resp$statusText,
status = resp$status,
ok = resp$ok,
redirect_url = resp$redirectURL,
response_headers_size = resp$headersSize,
response_headers = list(if (length(resp$headers) > 0) flatten_df(resp$headers) else data_frame()),
response_cookies = list(if (length(resp$cookies) > 0) flatten_df(resp$cookies) else data_frame()),
response_body_size = resp$bodySize,
content_type = resp$content$mimeType,
content_encoding = resp$content$encoding %||% NA_character_,
content_size = resp$content$size,
content = resp$content$text %||% NA_character_
)

}

#' @md
#' @param harentries_obj A `harentry` object
#' @rdname as_data_frame.harentry
#' @export
as_data_frame.harentries <- function(harentries_obj) {
map_df(harentries_obj, as_data_frame)
}

#' @md
#' @param har_obj A `har` object
#' @rdname as_data_frame.harentry
#' @export
as_data_frame.har <- function(har_obj) {
as_data_frame(har_obj$log$entries)
}

#' @export
#' @rdname as_data_frame.harentry
as.data.frame.har <- as_data_frame.har

#' @export
#' @rdname as_data_frame.harentry
as.data.frame.harentries <- as_data_frame.harentries

#' @export
#' @rdname as_data_frame.harentry
as.data.frame.harentry <- as_data_frame.harentry


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

@@ -26,6 +26,7 @@
#' @importFrom formatR tidy_source
#' @importFrom utils capture.output str
#' @importFrom curl curl_unescape
#' @importFrom dplyr data_frame as_data_frame
NULL

#' splashr exported operators


+ 36
- 0
man/as_data_frame.harentry.Rd View File

@@ -0,0 +1,36 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/as-data-frame-har.R
\name{as_data_frame.harentry}
\alias{as_data_frame.harentry}
\alias{as_data_frame.harentries}
\alias{as_data_frame.har}
\alias{as.data.frame.har}
\alias{as.data.frame.harentries}
\alias{as.data.frame.harentry}
\title{Turns a "HAR"-like object into a data frame(tibble)}
\usage{
\method{as_data_frame}{harentry}(harentry_obj)

\method{as_data_frame}{harentries}(harentries_obj)

\method{as_data_frame}{har}(har_obj)

\method{as.data.frame}{har}(har_obj)

\method{as.data.frame}{harentries}(harentries_obj)

\method{as.data.frame}{harentry}(harentry_obj)
}
\arguments{
\item{harentry_obj}{A \code{harentry} object}

\item{harentries_obj}{A \code{harentry} object}

\item{har_obj}{A \code{har} object}
}
\value{
data frame (tibble)
}
\description{
Turns a "HAR"-like object into a data frame(tibble)
}

Loading…
Cancel
Save