diff --git a/NAMESPACE b/NAMESPACE index 8250b94..795bd2d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,11 +1,11 @@ # Generated by roxygen2: do not edit by hand +S3method(html_element,"rvest::rvest_session") S3method(html_element,LiveHTML) S3method(html_element,default) -S3method(html_element,rvest_session) +S3method(html_elements,"rvest::rvest_session") S3method(html_elements,LiveHTML) S3method(html_elements,default) -S3method(html_elements,rvest_session) S3method(html_table,"rvest::rvest_session") S3method(html_table,LiveHTML) S3method(html_table,xml_document) @@ -38,9 +38,6 @@ export(html_session) export(html_table) export(html_text) export(html_text2) -export(httr_cookies) -export(httr_headers) -export(httr_status_code) export(is.session) export(jump_to) export(minimal_html) @@ -57,7 +54,6 @@ export(session_submit) export(set_values) export(submit_form) export(url_absolute) -export(xml2_read_html) export(xml_node) export(xml_nodes) export(xml_tag) diff --git a/R/form.R b/R/form.R index 9bf8ab7..c08f122 100644 --- a/R/form.R +++ b/R/form.R @@ -37,12 +37,10 @@ html_form <- new_generic("html_form", "x", function(x, base_url = NULL) { S7_dispatch() }) -#' @export method(html_form, new_S3_class("xml_document")) <- function(x, base_url = NULL) { html_form(xml2::xml_find_all(x, ".//form"), base_url = base_url) } -#' @export method(html_form, new_S3_class("xml_nodeset")) <- function(x, base_url = NULL) { lapply(x, html_form, base_url = base_url) } @@ -59,7 +57,6 @@ rvest_form <- new_class( ) ) -#' @export method(html_form, new_S3_class("xml_node")) <- function(x, base_url = NULL) { if (xml2::xml_name(x) != "form") { cli::cli_abort("{.arg x} must be a
element.") @@ -91,8 +88,8 @@ method(html_form, new_S3_class("xml_node")) <- function(x, base_url = NULL) { ) } -baseprint <- new_external_generic("base", "print", "x") -method(baseprint, rvest_form) <- function(x, ...) { +print <- new_external_generic("base", "print", "x") +method(print, rvest_form) <- function(x, ...) { cat(" '", x@name, "' (", x@method, " ", x@action, ")\n", sep = "") cat(format_list(x@fields, indent = 1), "\n", sep = "") } @@ -237,19 +234,11 @@ rvest_field <- new_class( value = class_character | NULL, attr = class_list, options = NULL | class_character - ), - constructor = function(type, name, value, attr, options = NULL) { - force(type) - force(name) - force(value) - force(attr) - new_object(S7_object(), type = type, name = name, value = value, attr = attr, options = options) - } + ) ) -baseformat <- new_external_generic("base", "format", "x") -#' @export -method(baseformat, rvest_field) <- function(x, ...) { +format <- new_external_generic("base", "format", "x") +method(format, rvest_field) <- function(x, ...) { if (x@type == "password") { value <- paste0(rep("*", nchar(x@value %||% "")), collapse = "") } else { @@ -260,8 +249,7 @@ method(baseformat, rvest_field) <- function(x, ...) { paste0(" (", x@type, ") ", x@name, ": ", value) } -#' @export -method(baseprint, rvest_field) <- function(x, ...) { +method(print, rvest_field) <- function(x, ...) { cat(format(x, ...), "\n", sep = "") invisible(x) } diff --git a/R/session.R b/R/session.R index 8b730a8..7a2cc67 100644 --- a/R/session.R +++ b/R/session.R @@ -61,8 +61,7 @@ rvest_session <- new_class( #' @rdname session is.session <- function(x) S7_inherits(x, rvest_session) -#' @export -method(baseprint, rvest_session) <- function(x, ...) { +method(print, rvest_session) <- function(x, ...) { cat(" ", x@url, "\n", sep = "") cat(" Status: ", httr::status_code(x), "\n", sep = "") cat(" Type: ", httr::headers(x)$`Content-Type`, "\n", sep = "") @@ -208,7 +207,6 @@ session_submit <- function(x, form, submit = NULL, ...) { # xml2 methods ------------------------------------------------------------ #' @importFrom xml2 read_html -#' @export xml2_read_html <- new_external_generic("xml2", "read_html", "x") method(xml2_read_html, rvest_session) <- function(x, ...) { if (!is_html(x@response)) { @@ -230,7 +228,6 @@ is_html <- function(x) { # rvest methods ----------------------------------------------------------------- -#' @export method(html_form, rvest_session) <- function(x, base_url = NULL) { html_form(read_html(x), base_url = base_url) } @@ -267,21 +264,18 @@ method(html_form, rvest_session) <- function(x, base_url = NULL) { # httr methods ----------------------------------------------------------------- #' @importFrom httr status_code -#' @export httr_status_code <- new_external_generic("httr", "status_code", "x") method(httr_status_code, rvest_session) <- function(x) { status_code(x@response) } #' @importFrom httr headers -#' @export httr_headers <- new_external_generic("httr", "headers", "x") method(httr_headers, rvest_session) <- function(x) { headers(x@response) } #' @importFrom httr cookies -#' @export httr_cookies <- new_external_generic("httr", "cookies", "x") method(httr_cookies, rvest_session) <- function(x) { cookies(x@response)